Extension:Pdf Export

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Pdf Export

Release status: beta

Implementation Special page, Data extraction
Description Converts current page to PDF and sends to browser
Author(s) Thomas Hempel (ThempelTalk)
Last version 2.4.2 (2011-02-23)
License No license specified
Download see here
Example Syncleus Wiki Example

Check usage (experimental)

Contents

[edit] Overview

This extension lets you view wiki pages as PDF. It has two modes:

  1. For any given page, it acts like the SpecialCite.php extension and provides a link in the toolbox to view that page as Pdf.
  2. If you invoke the Pdf Export special page directly, it lets you select a group of wiki pages and output them as a single pdf document. In that view you can also choose orientation (landscape vs portrait) and paper size.

The extension works with the open source htmldoc package. It works by rendering the current page without all the navigation stuff and writing it to a temp file. The temp file is passed through htmldoc which sends the PDF back to the browser.

The current version works with recent versions of MediaWiki, with a few tweaks it works with 1.6.7 and newer as well.

You'll need to make sure the paths are right (put htmldoc in Path environment variable). If you're having trouble with the images rendering, you may have to fiddle with how the pathnames get generated for them. In general the easy way to debug this extension is to comment out the line that removes the temp file. That way you can both check and hand-code the temp file, as well as manually run it through htmldoc to see what happens. Try commenting out $bhtml = str_replace ('/w/',$wgServer . '/w/', $bhtml);

[edit] Installation

The only prerequisite is installing Htmldoc (on Debian based systems such as Ubuntu or Mepis use: apt-get install htmldoc). Windows Binary can be found here (v1.8.27).

Get and save the Source Code, making sure there are no trailing spaces (or you will get a header error). Then add the following to your LocalSettings.php:

require_once("extensions/PdfExport/PdfExport.php");

You may also define a background image which will be printed to every page of the resulting PDF by setting the corresponding constant:

$wgPdfExportBackground = "path/to/the/background-image/image.jpg";

[edit] Version history

version history

Note that the current version is non-operational and requires a couple of fixes to make it work - see the code talk page.

[edit] See also

  • Extension:Collection - allows to build collections from a number of pages. Collections can be edited, persisted and retrieved as PDF
  • Extension:Pdf Book - composes categories of articles into a book in PDF format, also uses HTMLDOC
  • Extension:Pdf Export Dompdf - a modified version of Pdf Export, using dompdf, it will run on shared hosting servers too

[edit] List of possible Improvements

  • Images should be scaled down to the pagesize, so they do not get cut off.
  • Currently, only one link level is ever included. Please include nested links as well. (TOCLevel doesn't change anything)
  • Would be nice that the exported pdf kept the original colors in the wiki page and not only black and white

[edit] Making the TOC work

The clickable toc of the generated pdf may not work for some versions of mediawiki. To make it work you modify the file includes/Linker.php

--- a/includes/Linker.php
+++ b/includes/Linker.php
@@ -1417,7 +1417,7 @@ class Linker {
        public function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
                $ret = "<h$level$attribs"
                        . $link
-                       . " <span class=\"mw-headline\" id=\"$anchor\">$text</span>"
+                       . " <span class=\"mw-headline\" id=\"$anchor\"><a style=\"text-decoration:none;color:black\" name=\"$anchor\">$text</a></span>"
                        . "</h$level>";
                if ( $legacyAnchor !== false ) {
                        $ret = "<a id=\"$legacyAnchor\"></a>$ret";

You need to purge the wiki page cache for the changes to take effect. One way to do this is to make an edit.

NOTE that this was found to cause the section edit link, which is normally placed on the right-hand side of the page on a heading line, to be placed on the left side of the page next to the header, but only when viewed by a Firefox version 4 browser. -Jim - Apr 22, 2011
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox