DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:html2pdf

This is an old revision of the document!


html2pdf plugin

Compatible with DokuWiki

No compatibility info given!

plugin Exports HTML to PDF.

Last updated on
2009-02-16
Provides
Action

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to dw2pdf, pdfdownload, pdfex

Tagged with export, pdf

Download and Installation

Download and install the plugin using the Plugin Manager using the following URL. Refer to Plugins on how to install plugins manually.

Warning! This is a large file (52MB) and the plugin manager would not handle it for me (not sure where that's a DokuWiki setting or an Apache setting at this point in time). To install it manually, just download and install into the doku/lib/plugins directory.

Overview

The goal of this plugin was to provide a simple, ready to go PDF converter that almost faithfully replicates the screen view of your wiki pages (i.e. doesn't convert them to a print-document format like the latex plugin). It also bundles the necessary fonts and libraries (hence the 52M size) so that you should not need to do any configuration to get it up and running as quickly as possible. I haven't thoroughly tested this point on many platforms yet, so any feedback is welcome.

Features
  • Uses the html2ps PHP library which is itself a wrapper around one of several backends. In this plugin, it uses, by default, the fpdf backend.
  • Handles different languages (it bundles the large, but relatively complete arialuni.ttf font).
  • Outputs graphics of reasonable quality.

Demo

Not available yet.

To use the script, you simply need to call the page passing it a “do=export_pdf” php argument. The easiest way to implement this is to add a button or similar somewhere in your template design.

Dokubook

I use an extended dokubook for this, and have the following code inserted into the top__nav unordered list in main.php:

  $pdf_plugin = &plugin_load('action','html2pdf');
  if ( $pdf_plugin ) {
    if ( !plugin_isdisabled($pdf_plugin->getPluginName() ) ) {
      print '<li>'.DOKU_LF;
      print '  <a href="';
        echo exportlink($ID, 'pdf');
        print '" class="action tab_pdf" rel="nofollow">Export Pdf</a>'.DOKU_LF;
      print '</li>'.DOKU_LF;
    }
  }

The appropriate bit of CSS is added for tab_pdf in dokubook_design.css.

Monobook

When using the template “monobook for DokuWiki”, and using the “default toolbox”, you simply have to add two lines in context.php (line 355) of the template:

  $monobook['defaulttoolbox']['pdf']['href'] = exportlink($ID, 'pdf');
  $monobook['defaulttoolbox']['pdf']['text'] = 'Export PDF';

That's all – at least for me ;-)Werner Flamme 2009-02-16 10:00 CET

TroubleShooting

  • Errata - some random jots about the html2ps package for myself that may help (your mileage may vary).

Another thing to do is to do a few self checks on the html2ps engine yourself. Try the links below (replacing localhost/doku with the server/installation location of your own wiki):

Faithfully rendering HTML+CSS job is a massive job (even browsers have trouble with it) and so you're bound to find a few things the html2ps library can't do well. When I first started with it, it had a few problems with regular DokuWiki pages, but by reducing the problem to a simple example and positing it to the forum (link below), I found the author very responsive and he addressed the issues very quickly. You may wish to consider a similar approach - and if you get an update let me know and I'll update the html2ps in this plugin.

  • Forum - official html2ps (the converter library) forum, pretty good support and the author is very responsive.

Known Issues

PHP

The html2ps script is pretty greedy and you might not have enough memory reserved for the PHP script. When this happens, it will return with an error stating so. To increase the memory:

  • Edit your php.ini file, set the memory_limit variable to 128K or more.
  • Restart Apache.
CSS

The html2pdf script doesn't know how to handle the !important CSS property so internal links do not get styled. If you want them to show up as they appear on the web page, go into your template and edit /lib/tpl/_template/design.css, looking for the a.wikilink# (where # is 1 or 2) pattern and edit out the !important pieces.

Requests

I'm using the fckg plugin with DokuWiki, which is far more rich in features than the regular wiki, and suits our needs (since we have to convert some word-like documents to DokuWiki).
So, would it be possible to somehow convert such a document (which includes, for example tables with colored cells, etc.) to PDF with html2pdf?

(since FCKG format is more similar to HTML than the DokuWiki syntax)

Thnx! - 2009/11/04

This package uses a library maintained by someone else which is just focusing on converting html to pdf.

Problems

Some Rending Errors
I just installed the html2pdf Plugin. It's great an I like its performance. But I stumbled upon two Problems: First I wanted to export a gcalender produced by the gcalender Plugin, but it did not render the Pictures the PDF just showed the Text Second I was using an .htaccess to secure the Wiki. I got a lot of 401 errors as long I had this activated. Wen I deactivated it the Plugin just worked fine. My question is whether there are any workarounds to get rid of the two mentioned problems.

I haven't tried everything with the plugin, just the most common things. The guy who is writing the library has a monumental job - to faithfully render HTML+CSS is really difficult, even the browsers get it wrong. Still he's done a great job and is very active. I found a couple of problems when first starting to use the converter with just regular DokuWiki pages. However, if you simply scale the problem down to a simple example and hit the html2ps forum he's very quick on addressing them. He fixed the most glaring DokuWiki problems for me very quickly. That may be an approach you can take if you want the gcalender output rendered better.

The second problem, I'm a bit curious as to your setup. I'm using 2008 DokuWiki with Apache which has an AllowOverRide all setting for the DokuWiki directory. Other than that, I leave DokuWiki to handle the access (I think it uses one .htaccess file in the root folder - but I might be wrong about that, haven't checked in detail) and have no problems. Is the plugin directory owned by the web server?

Page not Showing up
I recently installed this addon, but my PDF is showing a blank page. I have done everything this site and the other linked from this page has suggested but to no > prevail. Any suggestions?
  • Plugin DOES show up in the admin section of DokuWiki
  • Tried with ALL access and restricted
  • http.conf makes _export/wherever/whatever show up as doku.php?do=whatever&ID=wherever or something similar to that (rewrite rules from DokuWiki site)
Thanks
Jason - 2009.06.24
  • Check that the html is being made in _doku_dir_/lib/plugins/html2pdf/tmp/export_pdf.html.
  • Check that the html2pdf is working with the systemcheck link in the troubleshooting section above.
    • Especially check curl and ghostscript - you need php with curl use flag and ghostscript package installed.
  • Make sure your entire directory is read/writeable by your web server user (usually apache:apache).

Another problem

After installing html2pdf, i tried and generated pdf file 15.2Mb size from 2 pages of simple text. Is this a normal behavior or i did something wrong?

Aye, thats normal. The holy grail of easily convertable documents isn't really here yet (though I've seen a project aiming to get there), but this is the best I've seen for faithfully rendering what you see in a dokuwiki page to pdf, even if it is pretty heavy getting there. I wouldn't use it for anything more than one or two page documents - but wiki pages should ideally never get longer than that if you're using the wiki as it should be used.

Configuration

I have installed the plugin html2pdf and when I tried it, the PDF-file that has been generated was good but not as far as those which are generated on the demo website.
I have maybe a file to modify, to configure the PDF export, but were is it? What can I put into it to have a good result as on the demo website?
Thanks!
Yohann – 2009-06-23

plugin/html2pdf.1261848939.txt.gz · Last modified: 2009-12-26 18:35 by 125.131.236.242

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki