mPDF Manual – Getting Started

HTML or PHP?

Most of the functions of mPDF can be achieved two ways: using PHP commands, or using custom HTML tags. Use whichever suits your purpose better, and you can always combine a mxture of the two.

If you are new to mPDF, I would recommend using HTML/CSS for everything - you can test most things out in a browser this way as you are writing it.

Example:

Example #1

<?php

$mpdf = new mPDF();

$mpdf->Bookmark('Start of the document');

$mpdf->WriteHTML('<div>Section 1 text</div>');

$mpdf->Output();

?>

Example #2

<?php

$html = '<bookmark content="Start of the Document" /><div>Section 1 text</div>';

$mpdf = new mPDF();

$mpdf->WriteHTML($html);

$mpdf->Output();

?>

Invalid HTML?

If you want to hide mPDF custom tags from a browser, enclose any mPDF code within:

<!--mpdf  ..  anything you want to write ...  mpdf-->

mPDF will strip away the $<!–mpdf tag and any following spaces, and the $mpdf–> tag and any preceeding spaces, and process all enclosed code e.g.

<!--mpdf  <htmlheader id="header1"><h2>Section 2</h2></htmlheader>  mpdf-->

See Also

Capturing HTML