Creating your first file
The following PHP will produce the most basic example with mPDF ≥ 7.0.
<?php
// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';
// Create an instance of the class:
$mpdf = new \Mpdf\Mpdf();
// Write some HTML code:
$mpdf->WriteHTML('Hello World');
// Output a PDF file directly to the browser
$mpdf->Output();
Note: For mPDF < 7.0 use $mpdf = new \mPDF();
Notes
For details and options for the Output()
method, see
Output().
Note: _MPDF_PATH
was required to be defined explicitly prior to mPDF 4.0 e.g. define('_MPDF_PATH','../')
.
Since mPDF 4.0 the value should be automatically defined by the script itself when including the mpdf.php file.
Since mPDF 7.0 this constant is deprecated and removed.