mPDF Manual – mPDF functions


mPDF Functions by Category

Main controls

\Mpdf\Mpdf::__construct() — Main class constructor mPDFI - [deprecated] - see SetImportUse() WriteHTML() — Write HTML code to the document Output() — Finalise the document and send it to specified destination


SetImportUse() — Enables use of templates and imported PDF files (was mPDFI) StartProgressBarOutput() — Show progress bars whilst generating PDF file SetAnchor2Bookmark() — Specifies how PDF Book marks are created from HTML anchors SetBasePath() — Specifies a base URL for mPDF to interpret relative URLs SetCompression() — Specifies that mPDF should compress the data for the PDF file SetDefaultBodyCSS() — Change default CSS properties at runtime SetDefaultFont() — [deprecated] SetDefaultFontSize() — [deprecated] SetDirectionality() — Set the document RTL state SetDisplayMode() — Specify the initial Display Mode when the PDF file is opened SetAutoFont() — [deprecated] RestrictUnicodeFonts() — Set (Unicode) fonts to restrict to

Document Metadata

SetTitle() — Set the document title SetAuthor() — Set the document author SetCreator() — Set the document creator SetSubject() — Set the document subject SetKeywords() — Set the document keywords

Encryption & Passwords

SetProtection() — Encrypts and sets the PDF document permissions SetUserRights() - [deprecated]

Watermarks (page backgrounds)

SetWatermarkImage() — Set an image to use as a Watermark SetWatermarkText() — Set the text to use as a Watermark

Page Numbering

AliasNbPages() — Defines the placeholder used to insert total number of pages into the document AliasNbPageGroups() — Defines the placeholder used to insert total page number into the document


AddSpotColor() — Define a Spot Colour to be referenced in the document


The following methods have HTML equivalents e.g. <pagebreak /> and AddPage():

AddPage() — Add a new page AddPageByArray() — Add a new page using array of parameters

Bookmarks (Outlines)

Bookmark() — Add a Bookmark to the document


Annotation() — Add an Annotation to the document


IndexEntry() — Insert an Index entry for the document IndexEntrySee() — Insert a cross-reference entry for the document Index InsertIndex() — Generate an Index for the document (mPDF ≥ v6.0) CreateReference() — [Deprecated] replace by InsertIndex() (mPDF < v2.4) CreateIndex() — [Deprecated] replaced by InsertIndex() (mPDF < v6.0)


SetColumns() — Control the use of multiple columns on the page AddColumn() — Start a new Column

Page Headers & Footers

DefFooterByName() — Define a page footer by name DefHeaderByName() — Define a page header by name DefHTMLFooterByName() — Define an HTML page footer by name DefHTMLHeaderByName() — Define an HTML page header by name SetFooter() — Set a page footer SetFooterByName() — Set a page footer by name SetHeader() — Set a page header SetHeaderByName() — Set a page header by name SetHTMLFooter() — Set an HTML page footer SetHTMLFooterByName() — Set an HTML page footer by name SetHTMLHeader() — Set an HTML page header SetHTMLHeaderByName() — Set an HTML page header by name

Table of Contents

TOCpagebreak() — Insert a table of contents in the document TOCpagebreakByArray() — Insert a table of contents in the document using an array of parameters TOC_Entry() — Insert an entry for the Table of Contents

Other Miscellaneous methods:

Replacing text in existing PDF files

OverWrite() — Replace specified text strings in an existing PDF file

Control Visibility

SetVisibility() — Control the visibility of subsequent objects

Import PDF files & Templates

mPDFI() — [deprecated] — see SetImportUse()

Thumbnail() — Print thumbnails of an external PDF file SetSourceFile() — Specify the source PDF file used to import pages into the document ImportPage() — Import a page from an external PDF file UseTemplate() — Insert an imported page from an external PDF file SetPageTemplate() — Specify a page from an external PDF file to use as a template SetDocTemplate() — Specify an external PDF file to use as a template


WriteBarcode() — Write an EAN-13 (ISBN-13) barcode

Write directly to page without HTML

AutosizeText() — Writes a single line of text, font size automatically reduced to fit width RoundedRect() — Draws a rectangle with rounded corners WriteCell() — print a cell MultiCell() — print text with line breaks WriteText() — print a string Shaded_box() — Writes line of text surrounded by layouted box CircularText() — Draw a circle using specified text

Original FPDF functions to write directly to page

FPDF functions to write directly to page without HTML:

  • Image() — output an image
  • Line() — draw a line
  • Rect() — draw a rectangle
  • SetDrawColor() — set drawing color
  • SetFillColor() — set filling color
  • SetFont() — set font
  • SetFontSize() — set font size
  • SetLineWidth() — set line width
  • SetTextColor() — set text color
  • SetX() — set current x position
  • SetXY() — set current x and y positions
  • SetY() — set current y position
Fork me on GitHub