====== Export DokuWiki Pages to PDFs ====== Several methods exist to convert your wiki pages to PDFs. See also the full list of [[https://www.dokuwiki.org/plugins?plugintag=pdf#extension__table|plugins tagged 'PDF']]. Plugins that export directly to PDF: * [[plugin:dw2pdf]] * [[plugin:xslfo|XSL-FO]] * [[plugin:pdfex]] (old) * [[plugin:html2pdf]] (broken) Other ways to generate PDFs: * HTML to PDF converter: [[tips:pdfexport:HTMLDOC]]; or * Generate ODT documents from your wiki using the [[plugin:odt|ODT plugin]], as LibreOffice, OpenOffice, etc. provide means to export to PDF (with working hyperlinks, tables, images and more). ===== Common changes ===== In order to export your pages to PDF you'll need to add a button to your wiki. Regardless which PDF converter you use, you need to implement the following changes: \\ * Add an //Export to PDF// button by editing ''lib/tpl/default/main.php'' like so:
'export_pdf')) ?>
(If you want the button to appear in the bottom bar use ''id="bar_bottom"'') * Add a new string to ''inc/lang/en/lang.php'' (or whatever language you use): $lang['btn_exportpdf'] = 'Export to PDF'; * 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 .= ' and replace with this. //This allows the insertion of an icon in the menu bar if ($name=="exportpdf"){ $ret .= ' ==== 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''

    ', ''); tpl_action('revert', 1, 'li', 0, '', ''); tpl_action('revisions', 1, 'li', 0, '', ''); tpl_action('backlink', 1, 'li', 0, '', ''); tpl_action('subscribe', 1, 'li', 0, '', ''); tpl_action('top', 1, 'li', 0, '', ''); tpl_action('export_pdf',1, 'li', 0, '', ''); ?>
* Edit the ''function tpl_get_action($type)'' in file ''inc/template.php'' and add the following condition: case 'media': $params['ns'] = getNS($ID); break; case 'export_pdf': break; default: return '[unknown %s type]'; break; } return compact('accesskey', 'type', 'id', 'method', 'params'); } * Create two new ''export_pdf'' css-actions for the image in ''lib/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 [[tips:pdfexport: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 [[http://www.tufat.com/script19.htm|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'', in ''inc/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 [[http://www.tufat.com/resources.php?dl=274|get the patch for html2ps]]. ==== Issues ==== This appears to only work with pages that allow anonymous read access. GIF images are not embedded into the generated PDF, instead only the first frame is shown. ---- ---- ---- *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.