I can see there are a few options for doing this. My question is does any one know of a way that I can simply pass a php web page into a pdf creator and it outputs exactly the same as if it was viewed via a browser? Taking into consideration CSS, images and php functions etc.
Thanks
Think wkhtmltopdf is the answer you are looking for as it uses WebKit to render the webpage just like it would look in a browser and then converts it to a PDF. This saves you writing a load of PHP code to organise the layout of your PDF.
Details from their site:
Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.
Searching the web, I have found several command line tools that allow you to convert a HTML-document to a PDF-document, however they all seem to use their own, and rather incomplete rendering engine, resulting in poor quality. Recently QT 4.4 was released with a WebKit widget (WebKit is the engine of Apples Safari, which is a fork of the KDE KHtml), and making a good tool became very easy.
- Convert web pages into PDF documents using webkit
- Adding headers and footers (static version only)
- TOC generation (static version only)
- Batch mode conversions
- (Linux) No longer requires an XServer to be running (however the X11 client libs must be installed)
For code and more information on wkhtmltopdf integration with PHP see https://github.com/aur1mas/Wkhtmltopdf
This is a two-part question really.
Making a screen shot of a web site into an image has many good answers on SO
To generate a PDF, use e.g. the fpdf library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With