Generate a PDF from a web page

Easily convert a web page into a PDF with MPDF, this library makes it possible to take a webpage and turn it into a PDF viewable on the site or offer it as a download.

A handy place for to learn about MPDF is through the manual at http://mpdf1.com/manual

Download a copy of MPDF at http://www.mpdf1.com/mpdf/download

What is MPDF?

This tutorial will show you how easy it can be to use.

Create a file say generatepdf.php

Include the library then create a new object, set the payout type and dimensions.
Next set the base path this is needed for the paths to images etc
Optionally include a stylesheet for the page and pass that to the page using writeHTML()
Next include the web page to be read from, parameters can be passed to the page using GETs.
Finally to show the pdf call the output method.

That’s those few lines you can generate the PDF by calling the file in this case generatepdf.php in the browser.

If instead of display the PDF you wanted to download it you specify that in the output method set the filename to be used and then a D flag which tells the page to download the PDF rather then display it.

There’s much more to MPDF then this but that’s all you need to get started.