U
U
ushim2014-05-21 16:16:15
PHP
ushim, 2014-05-21 16:16:15

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

7 answer(s)
T
Twist, 2014-05-21
@bboytiwst

habrahabr.ru/post/111979
PS what is meant by "floating elements"?

S
Sergey, 2014-05-21
Protko @Fesor

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.

M
Mikhail Osher, 2014-05-21
@miraage

If there is access to exec() then weasyprint.org

A
Andrey Kulikovsky, 2014-05-21
@by25

See this utility - https://code.google.com/p/wkhtmltopdf/
https://github.com/KnpLabs/KnpSnappyBundle - as an implementation example (Symfony2 bundle).

V
Vitaly Zheltyakov, 2014-05-21
@VitaZheltyakov

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).

W
whats, 2014-05-21
@whats

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.

C
cmx, 2014-05-27
@cmx

A variant with the TCPDF library is also possible: www.tcpdf.org

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question