Answer the question
In order to leave comments, you need to log in
How to convert HTML to PDF in PHP server?
Good day.
I have such a need to generate a PDF file and send it to the user for download using PHP. I already have a page layout in HTML, now I would like to present all this with the help of some framework in PDF format. The requirements are approximately the following: support for css files, support for tables, custom fonts and floating elements. Custom fonts and floating elements are hugely important, so far none of the frameworks I have tried have been able to show the result I need.
Answer the question
In order to leave comments, you need to log in
wkhtmltopdf or phantom.js. Do a console command, or add to the queue, or just do an exec in the script and voila. This is the most civilized option, which works relatively stably.
See this utility - https://code.google.com/p/wkhtmltopdf/
https://github.com/KnpLabs/KnpSnappyBundle - as an implementation example (Symfony2 bundle).
It is not possible to convert HTML to PDF using PHP (!). Therefore, you need to use third-party solutions.
Also:
- PDF can be generated based on templates;
- You can install doPDF on the client and give an html page (FF prepares documents without bugs this way).
I did with these classes.
www.digitaljunkies.ca/dompdf/index.php
Problems with floats are solved by normal layout. 3 css is the minimum supported. But for all the basic tasks this is enough.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question