We help IT Professionals succeed at work.

Programmatically creating PDFs

dogsareit asked
I am seeking advice and suggestions concerning creating PDF documents. I researched many sites but thought I would ask you folks about it.
I will be extracting data from MS SQL Server - 2014 database from many tables to create/populate the PDF document which will be on our web server.
Basically, the user will click a button and code will generate the PDF file.
I can find my way around Java but client doesn't not want to use C or Net.
I use localhost - Win 10 - and mainly PHP - v5.6.25 (client version - no plans to upgrade - their web server is Linux) with Wampserver and Apache 2.4.23.
I have looked at Apache PDFBox - got confused about it. I also took a long peek at iText. I did request a quote but they have never responded to me.
The creation of the PDF document must be created programmatically.
Any thoughts - suggestions - advice would be appreciated.
thank you.
Watch Question

Most Valuable Expert 2018
Distinguished Expert 2019


Probably the easiest way is to use one of the PHP PDF Libraries. The general idea is that you generate a layout using HTML (populated with your DB data / maybe using HTML Tables etc) and then you export / save that HTML content directly to PDF. This is way easier than manually trying to place items on a PDF canvas using co-ordinates.

A couple spring to mind - DomPDF, TcPdf
Distinguished Expert 2019

Have you looked at the ssrs option if these are reports that are regularly generated?
Agree with Chris, php and Java include libtaries to create PDFs.
Are you pulling data usin jdbc or odbc from php?
Developer & EE Moderator
Fellow 2018
Most Valuable Expert 2013

HTML to PDF libraries are going to be the easiest if there are a lot of design elements involved. 

Otherwise,   http://www.fpdf.org/ is a php library  and pdftk   https://www.pdflabs.com/tools/pdftk-server/  is a tool you can use via the command line that can easily be called by php.

I think the easiest is to generate your page, then use javascript libraries like   https://github.com/eKoopmans/html2pdf.js and even   https://parall.ax/products/jspdf.  

Another is   https://wkhtmltopdf.org/

It really depends on what your work flow is and what the document is (pretty layout vs report style)


Wow !! Great resources to review and suggestions. I thank all of you folks. I am going to research the suggestions for the next two days and report back then with results. And then close out my question. Once again, thank you folks.
Stay tune for part 2 !!


Thank you all for responding - very helpful. I have settled on using FPDF - which seems to be very good.