mpdf/mpdf
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
mpdf/psr-http-message-shim | v2.0.1 | 9.53 kB | MIT | prod | |
mpdf/psr-log-aware-trait | v3.0.0 | - | MIT | prod | |
myclabs/deep-copy | 1.11.1 | 22.96 kB | MIT | prod | |
paragonie/random_compat | v9.99.100 | 5.93 kB | MIT | prod | |
psr/log | 3.0.0 | 6.77 kB | MIT | prod | |
setasign/fpdi | v2.6.0 | - | MIT | prod |
mPDF is a renowned PHP library that facilitates the generation of PDF files from HTML content encoded in UTF-8. It leverages the functionality of FPDF and HTML2FPDF, with numerous enhancements to provide a flexible and feature-rich platform for generating PDF files. mPDF is written by Ian Back and is open-source, available under the GNU GPL v2 licence. Its popularity is evident from numerous downloads on Packagist and it enjoys a wide base of users due to its versatility and compatibility with multiple PHP versions, from PHP 5.6 to PHP 8.2.
Getting started with mPDF is straightforward, especially if you have Composer installed on your system. Install mPDF by executing the command $ composer require mpdf/mpdf
in your terminal. This will add mPDF to your PHP project.
To use mPDF in your PHP code, first require the Composer autoloader through require_once __DIR__ . '/vendor/autoload.php';
. Following this, create an instance of mPDF through new \Mpdf\Mpdf();
. You can then write HTML content to the PDF with the WriteHTML
function, and finally output the PDF either inline to the browser with the Output
function.
Below is a simple usage example:
<?php
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello world!</h1>');
$mpdf->Output();
Take note of the versatility of mPDF configuration. All configuration directives can be established by the $config
parameter of the mPDF constructor. For example, you can define a custom temporary directory by setting the tempDir
configuration variable:
<?php
$mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/tmp']);
Comprehensive documentation for mPDF is easily accessible via https://mpdf.github.io/. The mPDF online manual covers everything from getting started, to setup & configuration, and even explains more advanced topics. It's a valuable resource for understanding mPDF usage and ensuring seamless integration of mPDF in your PHP projects. For troubleshooting, the manual provides a section on common issues and provides practical solutions. Developers can also engage with other mPDF users and contributors on GitHub Discussions or the Stack Overflow 'mpdf' tagged questions for interactive problem-solving.