Extension:Mpdf

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
Mpdf

Release status:Extension status beta

ImplementationTemplate:Extension#type Data extraction
DescriptionTemplate:Extension#description Converts current page to PDF and sends it to the browser
Author(s)Template:Extension#username Pavel Astakhov (pastakhovtalk)
Latest versionTemplate:Extension#version 0.6.0 (2015-10-14)
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GPL v2+
Download
ExampleTemplate:Extension#example [1]
ParametersTemplate:Extension#parameters

$wgMpdfTab

Hooks usedTemplate:Extension#hook
MediaWikiPerformActionManual:Hooks/MediaWikiPerformAction
SkinTemplateTabsManual:Hooks/SkinTemplateTabs
SkinTemplateNavigationManual:Hooks/SkinTemplateNavigation
LanguageGetMagicManual:Hooks/LanguageGetMagic

Translate the Mpdf extension if it is available at translatewiki.net

Check usage and version matrix.

The Mpdf extension lets you export printable version of wiki page as PDF file.

What can this extension do?[edit]

This extension lets you export printable version of wiki page as PDF file. For conversion uses mPDF PHP class (modified version 5.7.2).

Advantage
  • no need to install additional components
  • for generate PDF using same CSS styles as for render printable wiki page.
  • small size of the pdf file
  • supports utf-8

Use the following Pdf imposes a number of limitations.

About mPDF[edit]

mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF, with a number of enhancements.

Usage[edit]

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:

http://www.foo.bar/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.

[{{fullurl:{{FULLPAGENAMEE}}|action=mpdf}} 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.

Customization[edit]

Use magic word {{#mpdftags: ... }} to add tags specified in documentation of mpdf class.

Sample:

{{#mpdftags: pageheader name="MyHeader1" content-left="" content-center="" content-right="My document" header-style="font-family: serif; font-size: 10pt; font-weight: bold; color: #000000;" line="on" | pagefooter name="MyFooter1" content-left="{DATE j-m-Y}" content-center="{PAGENO}/{nbpg}" content-right="My document" footer-style="font-family: serif; font-size: 8pt; font-weight: bold; font-style: italic; color: #000000;" }} {{#mpdftags: setpageheader name="MyHeader1" value="on" show-this-page="1" | setpagefooter name="MyFooter1" value="on" }}

Raw HTML output[edit]

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

http://www.foo.bar/wiki/index.php?title=Main_Page&action=mpdf&format=html

Installation[edit]

  • Download and place the file(s) in a directory called Mpdf in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/Mpdf/Mpdf.php";
    
  • Make sure that you set the following required php modules:
    • gd
    • mbstring
    • zlib
  • Ensure that you have write permissions set for the following folders in $IP/extensions/Mpdf/mpdf:
    • /ttfontdata/
    • /tmp/
    • /graph_cache/
  • Configure as required
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration[edit]

Here are some global variables which affect the operation of the extension. These should be set in your LocalSettings.php file after the include of the Mpdf.php script.

Variable Default value Meaning
$wgMpdfTab false Whether or not an action tab is wanted for export to PDF

See also[edit]

  • Extension:Collection - allows to build collections from a number of pages. Collections can be edited, persisted and retrieved as PDF
  • Extension:PdfBook - composes a book from articles in a category and exports as a PDF file
  • Extension:Pdf Export - use this extension for exporting single articles as PDF's