This is an old revision of the document!
Table of Contents
- In order to display a small PDF icon instead of the above “Export to PDF”, do the following in inc/html.php
Search for this line
$ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
and replace with this.
//This allows the insertion of an icon in the menu bar if ($name=="exportpdf"){ $ret .= '<input type="image" src="../lib/images/fileicons/pdf.png" value="'.htmlspecialchars($label).'" '; }else{ $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" '; }
Dokuwiki-template: Export Link in Pagetools
In order to have an export-link below the “Back to top”-link do the following:
- Add a new string (different from above) to
inc/lang/de/lang.php
(or whatever language you use):$lang['btn_export_pdf'] = 'Als PDF exportieren';
- Add the following line in
lib/tpl/dokuwiki/main.php
<!-- PAGE ACTIONS --> <div id="dokuwiki__pagetools"> <h3 class="a11y"><?php echo $lang['page_tools']; ?></h3> <div class="tools"> <ul> <?php tpl_action('edit', 1, 'li', 0, '<span>', '</span>'); tpl_action('revert', 1, 'li', 0, '<span>', '</span>'); tpl_action('revisions', 1, 'li', 0, '<span>', '</span>'); tpl_action('backlink', 1, 'li', 0, '<span>', '</span>'); tpl_action('subscribe', 1, 'li', 0, '<span>', '</span>'); tpl_action('top', 1, 'li', 0, '<span>', '</span>'); tpl_action('export_pdf',1, 'li', 0, '<span>', '</span>'); <!-- inserted line --> ?> </ul> </div> </div>
- Edit the
function tpl_get_action($type)
in fileinc/template.php
and add the following condition:case 'media': $params['ns'] = getNS($ID); break; case 'export_pdf': <!-- inserted line --> break; <!-- inserted line --> default: return '[unknown %s type]'; break; } return compact('accesskey', 'type', 'id', 'method', 'params'); }
- Create two new
export_pdf
css-actions for the image inlib/tpl/dokuwiki/css/pagetools.css
and add them at the end of the file#dokuwiki__pagetools ul li a.export_pdf { background-position: right -270px; } #dokuwiki__pagetools ul li a.export_pdf:before { margin-top: -270px; } #dokuwiki__pagetools ul li a.export_pdf:hover, #dokuwiki__pagetools ul li a.export_pdf:active, #dokuwiki__pagetools ul li a.export_pdf:focus { background-position: right -315px; }
Issues & Questions
Q: Where I will find required file /lib/plugins/pdf/renderer.php (and rest of files from /lib/plugins/pdf/) ?
A: If you follow the guide htmldoc then it wont complain about these missing files, as the system will not try to start a “pdf” plugin
html2ps PHP Script
Using the html2ps PHP script requires only little changes and additions to the DokuWiki source code.
- Install html2ps. (To run the php script you'll need ghostscript or libpdf - install them first!)
- Add the Export to PDF button as described above.
- In the function
act_export
, ininc/actions.php
, add this:if ($act == 'export_pdf') { header("Location: " . DOKU_BASE.'html2ps/html2ps.php?URL='.urlencode(wl($ID, '', true)).'&pixels=1024&media=A4&ps2pdf=2&output=0&cssmedia=screen&renderimages=1&scalepoints=1&leftmargin=10&rightmargin=10&topmargin=10&bottommargin=10'); exit; }
Variations
If you want to remove the wiki structures and send the raw html page to the pdf exporter, edit the above so that
urlencode(wl($ID, '', true))
⇒
urlencode(wl($ID, '', true).'&do=export_html')
You may also wish to vary other options for the html2ps command, these can be found in the documentation on the html2ps site. I add renderlinks=1 and method=fastps (for building using ghostscript) to mine.
html2ps discussion
If your Wiki uses HTTPS, then get the patch for html2ps.
Issues
This appears to only work with pages that allow anonymous read access.
*Is-someone knows where I can found the html2ps.php file ?. It's not provided with the package. Thanks. The file is in the Demo directory. Use the index file and the single URL convert to test your website before. My Website is Strict XHTML but looks horrible in PDF. Best regards from Germany.