V
V
vism2018-08-16 21:10:03
PHP
vism, 2018-08-16 21:10:03

What is the most convenient way to generate complex PDF documents in PHP(laravel)?

In the current legacy project, PDF is generated using layout via MPDF. This is complete bullshit. Long and not comfortable.
It is necessary to typeset tables of variable height, blocks with text, lists.
How is this done in modern development?
I looked at the libraries and many accept HTML as input and convert to PDF.
Is it true wei now? Do not go styles / fonts? Won't pop out the content width?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Novikov, 2018-08-17
@vism

In general, generating HTML and rendering to pdf is just the most common way, and it is quite ok. Fonts will go, styles too, all through pain and checks :) Someone has more jambs and only primitive tags, someone +/- can do everything.
If the PDF files are large, there are some tricky CSS - then it makes sense to look at wkhtmltopdf .
There was just a legacy project, PDF generation with tables of 30-50 pages, and also pages with text and images + transformations, initially used some kind of PHP library.
The day of report generation was a test for the entire server, documents were generated painfully long, with errors (2-3 minutes for a large report). When I migrated, I checked 4-5 implementations, 4 on PHP libs of varying degrees of antiquity, and a variant with wkhtmltopdf (C console tool). With wkhtmltopdf, I got the exact rendering version + 20x speed gain and some memory gain (I don’t remember how much)
In general, if you generate small documents, or without cunning css, then you can search for php libraries without inflating the stack, the same fpdf.
But in case of something big - I would recommend wkhtmltopdf + generated html as input and calling its console part via exec

M
mShpakov, 2018-08-17
@mShpakov

fpdf.org

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question