问题
I'm looking at generating PDFs to output various types of document sizes, A3, A4, A5 using PHP.
Currently I have a div that has various divs within this area that are positioned absolutely.
What I'm looking to do though is to have this div a fixed height a width, but when I save the contents, it can be used for A4, A3 and A5 print sizes.
What's the best way of achieving this?
Thanks
EDIT:
I am also trying to add a full width background image for each type?
Also, does the div need to be a specific height/width in order to create each document?
I'd like to have an 'area' where I can view the HTML of document. So, if I select A3, it will then save the PDF as A3, with the background image full width and all the positioned divs in the correct places.
回答1:
use MPDF
mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF, with a number of enhancements.
I wrote mPDF to output PDF files 'on-the-fly' from my website, handling different languages. It is slower than the original scripts e.g. HTML2FPDF and produces larger files when using Unicode fonts, but support for CSS styles etc. has been much enhanced - see the features.
Please see the examples, and feel free to download it. There is quite an extensive online documentation manual for mPDF.
Here is the list of arguments you can pass to default constructor.
$mpdf = new mPDF('', // mode - default ''
'', // format - A4, for example, default ''
0, // font size - default 0
'', // default font family
15, // margin_left
15, // margin right
16, // margin top
16, // margin bottom
9, // margin header
9, // margin footer
'L'); // L - landscape, P - portrait
回答2:
A good way to do it is the class FPDF, and its extension TFPDF that bring UTF8 support.
Fpdf Homepage
Tfpdf Script
I have used it sometimes and it works fine.
回答3:
You can use an API like the ones from htm2pdf.co.uk
回答4:
Try to use wkhtmltopdf is from google i think, it works with WebKit so it has a huge html compatiblity, and also has a option to specific the page-size output including A4,A3,etc or specific a custom size, the problem is that is a executable application , that's means you need to run it on Linux/Windows, and in some cases for archive that you need to ask to the hosting provider to give you run permission for that application
other option is http://pdfcrowd.com/html-to-pdf-api/ , is an API , that lets you create pdf and it has a huge compatibility with HTML aswell, is a Pay service , i think they have some free account but you have very limited amount of pdf you can generate
i strongly recomend wkhtmltopdf , the html convertion is almost perfect and free
来源:https://stackoverflow.com/questions/14397158/php-pdf-creation-a3-a4-and-a5