Hey there, I'll keep it short. At our company we tried different approaches for PDF generation (server side, specifically in PHP) over the years but none made us happy. HTML to PDF using print stylesheets in the front (nowadays seems like a low tech puppetteer), domPDF for HTML to PDF in the back, or FPDF/TCPDF to manually place the elements on every page on the back.
For simple invoice-like PDFs we can use anything but currently I'm facing the task of generating a document with a complex design and dynamically generated data. For this I'm using FPDI + TCPDF loading a pregenerated PDF and then filling the gaps using coordinates mostly which is really boring and cumbersome.
Any thoughts?
Thanks!
Top comments (17)
I use github.com/mpdf/mpdf with a custom stylesheet, it works very well and is maintained.
Hi, thanks! I've heard of mpdf from one of our team members but we have the same pain point. Have you ever generated a complex design with mildly complex dynamic data?
Definitely having a very active repository makes it very appealing. I guess we'll have to prototype something and evaluate the developer experience while working and the results.
Well, here is the kind of pdf I generate. Is it complicated enough for you ? :p
get.elabftw.net/a.pdf
Oh that is kind of inspiring :) PDFs are such a pain for almost every colleague I talked to about this issue '
Hey, sorry for replying to this old thread, but could you go into more detail on how you use mpdf for complex layouts?
I guess the best is just to link you to this: github.com/elabftw/elabftw/blob/ma...
and the CSS: github.com/elabftw/elabftw/blob/ma...
and the kind of output you can have: demo.elabftw.net/make.php?what=pdf...
I would suggest you to try Aspose.PDF Cloud SDK for PHP.
Have a look on a feature list:
docs.aspose.cloud/display/pdfcloud...
You can create the templates and generate PDFs based on them. It is possible to implement the logic of any complexity: create, modify, convert, encrypt files, separate pages or elements with this library.
The greatest benefits you will feel while working with complicated PDFs with different shapes, tables, annotations, stamps, bookmarks, links, etc.
Note: I am working as Developer Evangelist at Aspose.
Hey, $99/month is a bit expensive for our use case, thanks for the info anyway.
Hey guys just wanted to drop a line thanking everyone who contributed. For the current task we kept FPDI/TCPDF with sort of a declarative api we developed on top to place items in given positions. In the same project we used the same stack but instead we went with auto page breaks and rendering html both gave us decent results but it proved to be a cumbersome stack to work with.
Still we got our hands on some of the technologies you guys pointed out so we can use them in real world context for upcoming projects.
cheers!
I had the same problem a few das Ago, and I found this: pdfshift.io
I needed an easy way to generate PDF versions of an article, and this SaaS Tool is really good for that. You can build your layout with HTML / CSS and use this to generate the PDF.
Thanks! Will check the docs with the team and see if it fits =)
Great suggestion. Looking into it lead me to pyoo which seems to be the best way to go for my use case.
pyoo link:
pypi.org/project/pyoo/
Related article:
blog.pyspoken.com/2016/07/27/creat...
Another similar library that might be useful:
relatorio.readthedocs.io/en/latest...
wkhtmltopdf.org/
Easy enough to use and also comes with wkhtmltoimage, to generate images based on html.
ReportingCloud is a Web API that can be used to create PDF documents from MS Word compatible templates. Cheaper than Aspose.
reporting.cloud/
Note: I work for Text Control, makers of ReportingCloud.
Browsershot by Spatie
packagist.org/packages/spatie/brow...
Well that approach looks interesting too. We'll look into it, thanks :)