DEV Community

Christian Córdoba
Christian Córdoba

Posted on

What tools do you use for server side PDF generation?

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)

Collapse
 
elabftw profile image
eLabFTW

I use github.com/mpdf/mpdf with a custom stylesheet, it works very well and is maintained.

Collapse
 
christianca profile image
Christian Córdoba

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.

Collapse
 
elabftw profile image
eLabFTW

Well, here is the kind of pdf I generate. Is it complicated enough for you ? :p

get.elabftw.net/a.pdf

Thread Thread
 
christianca profile image
Christian Córdoba

Oh that is kind of inspiring :) PDFs are such a pain for almost every colleague I talked to about this issue '

Collapse
 
dakira profile image
Matthias Niess

Hey, sorry for replying to this old thread, but could you go into more detail on how you use mpdf for complex layouts?

Collapse
 
elabftw profile image
eLabFTW

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

Collapse
 
grazhevskaja profile image
Alexandra Grazhevskaja • Edited

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.

Collapse
 
christianca profile image
Christian Córdoba

Hey, $99/month is a bit expensive for our use case, thanks for the info anyway.

Collapse
 
christianca profile image
Christian Córdoba

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!

Collapse
 
diegoliv profile image
Diego Toda de Oliveira

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.

Collapse
 
christianca profile image
Christian Córdoba

Thanks! Will check the docs with the team and see if it fits =)

Collapse
 
justinemailone profile image
justinemailone

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

Collapse
 
steffex profile image
Stefan Jansen

wkhtmltopdf.org/

Easy enough to use and also comes with wkhtmltoimage, to generate images based on html.

Collapse
 
bjoerntx profile image
bjoerntx

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.

Collapse
 
treggats profile image
Tonko Mulder
Collapse
 
christianca profile image
Christian Córdoba

Well that approach looks interesting too. We'll look into it, thanks :)