Extension:Pdf Export

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);

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:

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

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.

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

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

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