Guides › mPDF
mPDF guides
mPDF is a free, open-source PHP library that turns HTML and CSS into PDF documents. It is widely used for invoices, reports, tickets and certificates, and many PHP frameworks and CMSs ship plugins for it. These guides explain how it works today, in version 8, with examples you can copy.
PDF1 is an independent site. mPDF itself is developed on GitHub, and its reference documentation is at mpdf.github.io. Why this domain has mPDF guides.
Getting started
- Install mPDF with ComposerRequirements, Composer install, the temp directory and your first PDF.
- Configuration optionsThe constructor config array: format, margins, fonts, temp directory.
- Output: show, download or saveThe four Output() destinations and when to use each.
Layout and content
- Supported HTMLWhich tags and attributes mPDF understands, and the table quirks.
- Supported CSSWhat the CSS engine handles, what it ignores, and the workarounds.
- Headers, footers and page numbersHTML headers and footers, {PAGENO}, {nbpg} and dates.
- Page breaks<pagebreak>, CSS break rules and keeping rows together.
- Fonts and languagesCustom TTF fonts, lang, right-to-left text and CJK.
- ImagesFormats, paths versus data URIs, SVG, and dpi sizing.
- Backgrounds and bordersColours, background images, rounded corners and page backgrounds.
- Barcodes and QR codesThe <barcode> tag, common symbologies and QR codes.
- Document metadataTitle, author, subject, keywords and language.
Recipes
- Password protectionSetProtection(): passwords, permissions and encryption strength.
- Invoice exampleA complete invoice template with header, line items and totals.
- Email a PDFGenerate in memory and attach it with PHPMailer or Symfony Mailer.
- Turn a form into a PDFTake user input safely and render it as a PDF.
Running it well
- Performance and memoryLarge documents, memory limits, big tables and speed.
- TroubleshootingThe errors people hit most, and how to fix each one.
Also useful
- Topic indexFind the guide for any function, setting or tag.
- Limitations and workaroundsWhat mPDF can’t do, and what to do instead.
- Getting mPDFComposer, releases and upgrading from very old versions.
- Examples galleryTemplates that render in mPDF and in the browser.