html to PDF

Jake232

New member
Sep 4, 2010
712
4
0
I figured one of you guys had probably come across this before.

I need a way to convert a HTML page to PDF (via PHP). I have found various little plugins and such, but none of them work correctly. They don't take the CSS into account, or generally just fuck up the layout. It isn't super complicated, it's just a invoice. eg: few floats and a table.

Wondering if anyone had any bright ideas?
 


If your using linux you can install wkhtmltopdf then execute it in php like this:
shell_exec('wkhtmltopdf pageyouscraped.html result.pdf');
 
floats make your world a nightmare when converting to pdf. Simplify the layout by only using tables (old school html) and use this to convert it:

dompdf - HTML to PDF converter (PHP5) - Google Project Hosting

That's what I tried before, I used the codeigniter plugin for it. The problem was not only did it not do the floats, but the whole page was messed up. eg: didn't even get any of the styling or anything. It was just all plain text.
 
If your using linux you can install wkhtmltopdf then execute it in php like this:

Do you know if this works with floats?

I could rewrite in tables,but due to the nature of the project and what I'm converting to PDF, I'd like to avoid if at all possible.
 
That's what I tried before, I used the codeigniter plugin for it. The problem was not only did it not do the floats, but the whole page was messed up. eg: didn't even get any of the styling or anything. It was just all plain text.

most of the time, when outputting to pdf, you supply an alternate stylesheet and (in codeigniter world) a whole alternate view.

web != paper