Home Convert HTML + CSS to PDF with PHP?

# Convert HTML + CSS to PDF with PHP?

user12659
1#
user12659 Published in September 19, 2018, 6:43 pm

I have an HTML (not XHTML) document that renders fine in Firefox 3 and IE 7. It uses fairly basic CSS to style it and renders fine in HTML.

I'm now after a way of converting it to PDF. I have tried:

• DOMPDF: it had huge problems with tables. I factored out my large nested tables and it helped (before it was just consuming up to 128M of memory then dying--thats my limit on memory in php.ini) but it makes a complete mess of tables and doesn't seem to get images. The tables were just basic stuff with some border styles to add some lines at various points;
• HTML2PDF and HTML2PS: I actually had better luck with this. It rendered some of the images (all the images are Google Chart URLs) and the table formatting was much better but it seemed to have some complexity problem I haven't figured out yet and kept dying with unknown node_type() errors. Not sure where to go from here; and
• Htmldoc: this seems to work fine on basic HTML but has almost no support for CSS whatsoever so you have to do everything in HTML (I didn't realize it was still 2001 in Htmldoc-land...) so it's useless to me.

I tried a Windows app called Html2Pdf Pilot that actually did a pretty decent job but I need something that at a minimum runs on Linux and ideally runs on-demand via PHP on the Webserver.

What am I missing, or how can I resolve this issue?

## closed as off-topic by meagar♦Oct 19 '16 at 18:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – meagar
If this question can be reworded to fit the rules in the help center, please edit the question.

• Html2Pdf actually uses an embedded instance of IE to render the page, then converts that to PDF - probably through IE's print mechanism. – Joel Mueller Dec 24 '08 at 19:31
• since it's a 2008 question, dompdf is much more mature now. ;-) – Hendra Uzia Jul 15 '11 at 9:03
• dompdf now supports CSS 2.1 and can deal with @import, @media and @screen rules, and will load external stylesheets. It also comes bundled with everything required for it to work, although there are things you can install to get better performance than the default libs. code.google.com/p/dompdf – totallyNotLizards Oct 4 '12 at 9:39
• 2015 Update: After researching a lot of options we decided to go with wkhtmltopdf its a nice utility we struggle with CSS because we have external CSS file but then we applied the trick of putting a dummy link of CSS on our HTML element which we want to convert and setting the right path it works like MAGIC !!! – Anshul Nigam Jan 20 '15 at 9:49
• I believe soon everyone finds Chrome/Chromium headless chrome --headless --print-to-pdf="path/to/pdf" https://your_url  as richest, fastest and easiest html to pdf generation tool crbug.com/603559 as it supports most of html features developers rely on web development and doesn't suck on complex scripts like most of the other libraries and tools do. – Ebrahim Byagowi May 22 '17 at 8:41