[pmwiki-users] Simple PDF Generation

Jason Green jgreen at kpm-net.com
Tue Apr 26 13:09:38 CDT 2005


I'm brand new to this list and PmWiki, but I've spent a few days hacking
up the code and added on a very simple PDF generator.  This is no where
near as complex as what Affinity is trying to do with pdf2you:
http://www.pdf2you.com/, but it works for us.

Using htmldoc (GPL'd program available on all major platforms -
http://www.htmldoc.org/software.php), I added a few functions to have
htmldoc view a page using the ?action=print view and create a PDF from
it to store on your webserver.  I'm positive that this isn't the best
solution, but it works, and someone else here might be able to use it.
Below is everything you need to get this working.  My configuration is
as follows:

Windows 2000 SP4 running IIS and PHP 4.3.11.
PmWiki 2.0 beta 30 (using the 'dropdown' skin)
htmldoc 1.8.23

Steps to setup:


1) Create folder: /pmwiki/output

2) Install htmldoc 1.8.23 or greater to webserver. 
All you have to do on Windows is unzip the binary program to c:\program
files\htmldoc, and it works out of the box. 

3) Changes to PmWiki code:
 a) In /pmwiki/public/skins/dropdown/dropdown.tmpl: 
 - Add <a id='pdf' href="$PageUrl?action=pdf">$[Generate PDF]</a> 
   at end of <!--PageHeaderFmt?-->
 b) In /pmwiki/local/config.php: 
 - Add:
  function HandlePDF?($pagename) {
    $filename_to_write = '/inetpub/wwwroot/pmwiki/output/' . $pagename .
'.pdf';
    $url = '/pmwiki/output/' . $pagename . '.pdf';
    $output = shell_exec('/progra~1/htmldoc/htmldoc.exe -f ' .
$filename_to_write . '
    --webpage http://localhost/pmwiki/pmwiki.php?n=' . $pagename .
'?action=print');
    header("Refresh: 0; URL=" . $url);
  }
  $HandleActions = array(
    'browse' => 'HandleBrowse?',
    'edit' => 'HandleEdit?', 'source' => 'HandleSource?', 
    'attr'=>'HandleAttr?', 'postattr' => 'HandlePostAttr?',
    'pdf' => 'HandlePDF?');


Note: You'll have to modify your skin in a similar fashion if you use a
different skin than dropdown.  Also, change the file locations for
$filename_to_write and $url if you don't want to use the /pmwiki/output
folder.

Limitations: As far as I know, htmldoc cannot handle authentication, so
if your pages are not available to anonymous web users, this method will
not work for you.  Also, the next time you upgrade your PmWiki skins,
you'll have to recreate your changes to the template file.


I hope this helps someone!

Jason Green




More information about the pmwiki-users mailing list