Question

Our company allows its clients to view reports via our website. The pages are php based and the data is collected from MySQL. These reports were written a long time ago and include inline css. The pages themselves look fine, but the print version is lacking. I want to take the reports and create visually appealing "printable" pages that contain our branding.

I have found three solutions so far.

  1. @Media Print Stylesheets

    This is the easiest method, but does not give me complete layout control. I want landscape mode and need to control where the page breaks occur so this method has been eliminated from my list of possible solutions. The reports are built by looping through PHP data, so while I can always put a page break after a or for example, I can't stop the page from breaking before it gets to the next set of data.

  2. TCPDF/FPDF

    From what I have seen these classes will give me all of the control I need to customer a PDF. The challenge is that this appears to be a little more advanced than my programming skills require, and all of the inline CSS contained within the HTML tables may throw off formatting.

  3. FDF

    I am leaning towards this method if I understand it correctly. First I would create a PDF form and define all of the fields to be populated by the MySQL data. Then I would create a FDF file that would populate the form template with the data from the database. It seems easier to me to create a visually pleasing form via PDF and then populate that form using this method, rather than create the entire pdf from scratch using method 2.

Does it sound like I am on the right track? Are any of these methods "easier" than the other?

Any help is greatly appreciated.

Was it helpful?

Solution

TCPDF has the most control of each page which is what I am looking for. It is extremely sensitive when writing HTML, but that is the only downside I have found so far.

OTHER TIPS

There's this excellent answer on SO already.

If you're looking for easy, my money is on mPDF. I found it to be the easiest, and essentially an out-of-the-box solution (often zero server configuration to do).

I think you should try out wkhtmltopdf.

https://code.google.com/p/wkhtmltopdf/

As for the TCPDF/FPDF pagination issue, you can see this other question for the solution provided and use the flow in it to sort yours out.

TCPDF / FPDF - Page break issue

Just found this other solution as well and think you'll need it

Convert HTML + CSS to PDF with PHP?

For me personally, FPDF works great to fetch data from my database, insert into the FPDF class and dynamically create PDF's for customers.

I see some people want to write HTML/CSS to create PDF's but you will always have differences as the browser parses the HTML/CSS differently than when using it in PDF's.

When using FPDF's built-in method's, I have been able to get exactly what I wanted and haven't seen any issues (yet).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top