Extension:Mpdf

The Mpdf extension lets you export the printable version of a page as a PDF file. To do so it uses the mPDF PHP library (version 6.1), which does HTML-to-PDF conversion.

Advantages of this extension:
 * no need to install additional components
 * the generated PDF uses the same CSS styles as for rendering the printable version of the page
 * small size of the PDF file
 * supports UTF-8

Requirements
In order to run this extension, your PHP installation must include the following modules:
 * gd
 * mbstring
 * zlib

Standard
First, download the main Mpdf code from here, extract it, and place it as a directory called  in your /extensions directory.

Then, download the mPDF code from here, extract it, and place it as a directory called  in your   folder.

Using Git and Composer
Within the /extensions directory, call a command like the following:

Then, you have two options:


 * (Preferred option) Add the line  to the "composer.local.json" file in the root directory of your wiki like e.g.:


 * Within the newly-created /Mpdf directory, run  - or, when updating,

Installation
Once you have downloaded all the code, you will have an /mpdf directory (containing the mPDF library) within either  or , depending on how it was downloaded. In either case, make sure that the following subfolders of that directory have write permission for the web server:

Then, add the following line to LocalSettings.php:

Configuration
The following variables can be set in LocalSettings.php after the inclusion of the extension:


 * If set to, makes the PDF output simpler by including only the contents of the page, and not anything from the skin itself (defaults to  )
 * If set to, makes the PDF output simpler by including only the contents of the page, and not anything from the skin itself (defaults to  )


 * If set to, adds an action/tab to each page, linking to "action=mpdf" (defaults to  )
 * If set to, adds an action/tab to each page, linking to "action=mpdf" (defaults to  )


 * If set to, adds a link to "action=mpdf" to the toolbox, usually found in the sidebar (defaults to  )
 * If set to, adds a link to "action=mpdf" to the toolbox, usually found in the sidebar (defaults to  )

Usage
The PDF creation is initialised by the mpdf action, so a page can be downloaded as a PDF file directly from a link such as: https://www.example.org/wiki/index.php?title=Main_Page&action=mpdf

A more generic way of creating the link is to use the "fullurl" parser function and the FULLPAGENAMEE built in variable as in the following example. [ download this page as a PDF file] This link can then be added to a template which can be transcluded into any page for downloading as a PDF file.

If you use other skins than Vector and run into problems (e. g. empty PDF documents being created), try to force the Vector skin: https://www.example.org/wiki/index.php?title=Main_Page&useskin=vector&action=mpdf

Customization
Use parser function  to add tags specified in documentation of mpdf class.


 * Examples

Raw HTML output
You can download the file as a single HTML document by setting format=html in the query-string.

https://www.example.org/wiki/index.php?title=Main_Page&action=mpdf&format=html
 * Example