Summary: Generate PDF versions of pages (?action=pdf)
Prerequisites: PmWiki >=2.1.0, htmldoc >=1.8.27
Questions answered by this recipe
- Can I generate a PDF file on the fly from a wiki page?
The htmldoc package combined with the generatepdf.phpΔ script adds an ?action=pdf option that will generate PDF copies of a wiki page.
First, download and install htmldoc onto your system, and download and install the generatepdf.phpΔ script into your cookbook directory.
Next, tell the GeneratePDF script where to find the htmldoc executable on your system:
$HtmlToPdfCmd = '/path/to/htmldoc -t pdf --quiet --webpage';
NOTE: In Windows you'll want to download the HTMLDoc binaries, and perform an install. If you get the binaries from EasySW you'll need to purchase a license. Alternately do a Google search and find a free source for the binaries, or compile your own from the source. Your path line will then look something like this (note the double quotes since we have a space in the path):
$HtmlToPdfCmd = '"C:\Program Files\HTMLDOC\htmldoc.exe" -t pdf --quiet --webpage';
That's it! Using ?action=pdf on your pages should result in PDF versions of the file. For example, you can try it on this page with Cookbook.GeneratePDF?action=pdf.
By default, GeneratePDF uses PmWiki's 'print' skin to format the page; this can be changed by setting
$ActionSkin['pdf'] = 'myskin';
- Note that there are specific requirements to have an equivalent rendering. For example that HTMLDoc supports hexadecimal color but not color names like PmWiki does. Consequently when one renders a page only colors with hex values like
bgcolor=#C0C0C0 will work whereas
bgcolor=silver will only display a white background. Also HTML symbols will require their proper code, for example
€ will not work whereas
€ will. For more details see HTMLDoc documentation and release notes. Utopiah March 14, 2011, at 08:20 AM
- Watch the "--quiet" option with older versions of HTMLDOC. I use 1.8.7, where this option is implicit; requiring you to call "--verbose" instead. The wrong option leads to the system sending its help message, which does not create a PDF. BenWilson May 02, 2007, at 09:44 AM
- I obtain the PDF file, but with php extension! This way users have to rename manually files after saving. I obtatin always pmwiki.php .
MassimilianoVessi 24 Sept 2007
You could add this after line 46 in generatepdf.php :
header("Content-Disposition: attachment; filename=$pagename.pdf"); Nicolas Poulain
26 April 2008
- I have downloaded the software (htmldoc) in 2 different versions (both complete and exe files). Unfortunately, neither one is recognized (the install wasn't because I had to purchase a license and the complete package didn't respond to any queries). Is there something in the works that will convert our PMWiki files into pdf? -Chris (August 25, 2008)
- Refer to instructions above regarding installation under Windows.
Hi - Great recipe.
Only one tiny issue.
When you have wiki markup '===='
it doesn't produce a thick solid line but 4 = signs.
Also is it possible for it to honour markup. Ie open resultant pdf in a new window.
Test with an image
Test with a table
|cell 1||cell 2||cell 3|
- Jason Green -> mailto:jgreen_at_mykmg [period] net
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.