/lib/tpl/default/main.php
, there are two divs that contain some buttons: <div class="bar" id="bar__top">
and <div class="bar" id="bar__bottom">
. Just insert the HTML code inside one of the two divs (left or right) This is an old revision of the document!
Compatible with DokuWiki
Weatherwax, Binky, Ponder Stibbons, Hrun,Detritus
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 bookcreator, ebookexport, html2pdf, pdfex, xslfo
Needed for bookcreator, pdftools
Previous developer: Luigi Micco
Download and install the plugin using the Plugin Manager using the URL given above. Refer to Plugins on how to install plugins manually.
The plugin can't be installed through the plugin manager on pre-Angua releases, because it's too big and the plugin manager will fail while downloading. Please install it manually and make sure the installed directory is named dw2pdf
.
To export images with an alpha channel (used for transparency), you need to install the GD library for PHP. For example on Debian systems:
sudo apt-get install php5-gd
Also see the PHP with gd tips page.
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 48MB size) so that you should not need to do any configuration to get it up and running as quickly as possible.
Since 11 June 2015 version 6.0 of the mPDF library is included. This should significantly improve the styling possibilities. However there could also be regressions. As fallback an old release is available:
To use the plugin, you simply need to call the page passing it a βdo=export_pdfβ PHP argument for a single page. Some templates let the plugin extend the pagetools automatically. For other templates you need to implement this yourself to add a button or similar somewhere in your template design.
See the syntax section on how to export an entire namespace as one PDF.
Since 2013-12-08 Binky release this plugin automatically adds the export button to the page tools. When required, you can disable it via the Configuration Manager.
Use the following to add another button in the upper or bottom button row of the default template1)
<form class="button" method="get" action="<?php wl($ID)?>"> <div class="no"> <input type="submit" value="Export to PDF" class="button" /> <input type="hidden" name="do" value="export_pdf" /> <input type="hidden" name="rev" value="<?php global $REV; echo $REV?>" /> <input type="hidden" name="id" value="<?php echo $ID?>" /> </div> </form>
Or use this for a simple 16×16 icon somewhere in your template:
<a href="<?php global $REV,$ID; echo exportlink($ID, 'pdf', "rev=$REV")?>"> <img src="<?php echo DOKU_BASE?>lib/images/fileicons/pdf.png" alt="PDF Export" /> </a>
You can mix the 2 previous methods, and get a button with an image inside, with this code:
<form class="button" method="get" action="<?php wl($ID)?>"> <div class="no"> <button type="submit" class="button"> <img src="<?php echo DOKU_BASE?>lib/images/fileicons/pdf.png" alt="PDF Export" /> Export to PDF </button> <input type="hidden" name="do" value="export_pdf" /> <input type="hidden" name="rev" value="<?php global $REV; echo $REV?>" /> <input type="hidden" name="id" value="<?php echo $ID?>" /> </div> </form>
When using the template βmonobook for DokuWikiβ, to have an Export PDF tab, in /user/tabs.php
, use this code
//PDF plugin: export tab if (file_exists(DOKU_PLUGIN."dw2pdf/action.php") && !plugin_isdisabled("dw2pdf")){ $_monobook_tabs["tab-export-pdf"]["text"] = $lang["monobook_tab_exportpdf"]; $_monobook_tabs["tab-export-pdf"]["href"] = wl(getID(), array("do" => "export_pdf"), false, "&"); }
Add translation to file /lib/tpl/monobook/lang/en/lang.php
$lang["monobook_tab_exportpdf"] = "Export as PDF";
When using the typo template, add this code in lib/tpl/typo/tpl_functions.php
just before print ' </ul>' . DOKU_LF;
print '<li>'.tpl_link(wl($ID,'do=export_pdf'), 'Export PDF', 'class="action export_pdf" rel="nofollow"',1).'</li>'.DOKU_LF
When your template has implemented the trigger for the TEMPLATE_PAGETOOLS_DISPLAY event the dw2pdf plugin can extend your templates pagetools.
In the addbutton()
method of action.php a case should be added for the template, with the html of your button. Depending on the layout of your template, you might like to improve the style.css
and the button images as well.
To create a link in any wiki page to export any namespace, you can use the following syntax:
~~PDFNS>namespace|pdftitle~~
namespace
is the namespace you want to exportpdftitle
is the title of the generated output PDF&book_order=pagename
) by simply appending them to the pdftitle.
Handling of startpages: If the page <namespace>:start
doesn't exist, it checks if the page with the name <namespace>
exists and will add to the pdf as well.
The plugin provides a few configuration settings that can be configured in the Configuration Manager. Some can be overridden via url-parameters.
do=export_pdf
β Export current wiki page
book_title=<urlencode%20title>
do=export_pdfns
β Export the requested namespace
book_ns=<namespace>
Exported namespace book_title=<urlencode%20title>
book_nsdepth=<number>
(optional) β Down to which level the pages are collected for inclusion (default: all levels included)book_order=<order>
(optional) β Sort included pages by natural
(default), date
or pagename
Cookie list-pagelist
is set with a page list β Export pdf book via Bookcreator Plugin
book_title=<urlencode%20title>
If a url-parameter is provided, that value is used, otherwise the plugin config setting from the Configuration Manager is used.
pagesize=A4|letter|etc
A page format as supported by mPDF. Usually A4
or letter
. See the docs for other allowed values for the format
parameter of mpdf(). mpdf.github.io
orientation=portrait|landscape
Page orientation of the whole document, you can select Portrait
or Landscape
.
Also you can change the orientation of only some pages. Adding the syntax will change the orientation, until you change it with the other orientation syntax.
~~PDF:LANDSCAPE~~ ~~PDF:PORTRAIT~~
doublesided=0|1
By default a double-sided PDF document is outputted. The first page is an odd page (left hand-side page) and further even-odd page pairs are added. Disabling this will output a single-sided document with only odd pages. The single-sided document doesn't add additional blank pages if a Table of Contents or cover page is included (and you can still send it to the printer as double-sided, but it won't have odd-even formatting).
toc=0|1
toclevels=<top>-<max>
An auto-generated Table of Contents can be included by enabling the setting 'toc' (values: 0 or 1). By default, the same headings are added to the PDF Table of Contents as in the TOC for a wiki article (as set with toptoclevel and maxtoclevel). The range of headings can be overridden by setting 'toclevels' e.g. 1-3
. Where the values correspond to <toptoclevel>-<maxtoclevel>
.
maxbookmarks=0|1|2|3|4|5
By default the plugin generates PDF bookmarks for each headline in the source page. You can lower the number here to include only higher level headlines in the bookmarks. Set it 0
to disable bookmarks all together.
tpl=<foldername>
Choose which PDF template (see below) should be used by default. The template can be overridden with the tpl
request variable e.g. add &tpl=yourtemplate
to the export url.
The output
option controls if PDF should be opened within the Browser (when a PDF plugin is installed) or should always be downloaded.
By default, generated PDFs are cached. This includes embedded images. This means the ACLs for embedded images will not be rechecked when a user requests a cached PDF. If this is a problem, you should disable caching.
The plugin automatically uses print.css
and pdf.css
files of installed 3rd party plugins to style plugin content. Often plugins do not provide such styles or you may actually prefer their screen styles. In that case list the names of these plugins here.
Via a placeholder a QR code can be added in the pdf-templates, which is generated with the size given in the configuration. The plugin uses an online generator. Setting the size to zero will disable this feature.
Lets you show or hide the toolbar button in the pagetools.
To work with other plugins you have to add dw2pdf
to its action_plugin_include
supportedModes
member variable
var $supportedModes = array('xhtml', 'metadata','dw2pdf');
Otherwise you may have problems with caching.
Templates define the design of the created PDF files and are a good way to easily customize them to your Corporate Identity.
To create a new template, just create a new folder within the plugin's tpl
folder and put your header, footers, cover page, and style definitions in it. See lib/plugins/dw2pdf/tpl/default
for an example. Don't modify the template default
, these template can be overwritten on updates, so you will lose your changes.
The following files can be created and will be used to set headers and footers on odd or even pages. Special headers/footers can be used on the first page of a document. If a file does not exist the next more generic one will be tried. Eg. if you don't differ between even and odd pages, just the header.html is used.
header.html
β Header for all pagesheader_odd.html
β Header for odd pagesheader_even.html
β Header for even pagesheader_first.html
β Header for the first pagefooter.html
β Footer for all pagesfooter_odd.html
β Footer for odd pagesfooter_even.html
β Footer for even pagesfooter_first.html
β Footer for the first pagecitation.html
β Citationbox to be printed after each articlecover.html
β Added once before first pageback.html
β Added once after last pageYou can use all HTML that is understood by mpdf (See http://mpdf1.com/manual/index.php?tid=256)
If you reference image files from your pdf-template file, be sure to prefix them with the @TPLBASE@ parameter (See Replacements below).
The following replacement patterns can be used within the header and footer files.
@PAGE@
β current page number in the PDF@PAGES@
β number of all pages in the PDF (excluded a ToC)@TITLE@
β the article's title@WIKI@
β the wiki's title@WIKIURL@
β URL to the wiki@DATE@
β time when the PDF was created (might be in the past if cached)@BASE@
β the wiki base directory@TPLBASE@
β the PDF-template base directory (use to reference images) (e.g. [wikibase]/lib/plugins/dw2pdf/tpl/<yourtplfolder>/
)@DATE(<date>[, <format>])@
β formats the given date with dformat or with the given format e.g. %Y-%m-%e
eg: this would give just the current year @DATE(@DATE@,%Y)@
Remark about Bookcreator:
The page dependent replacements are only for citation.html
updated for every page.
In the headers and footers the ID of the bookmanager page of the Bookcreator is applied.
@ID@
β The article's pageID@PAGEURL@
β URL to the article@UPDATE@
β Time of the last update of the article@QRCODE@
β QR code image pointing to the original page url (requires an online generator, see config setting)Custom stylings can be provided in the following file of your pdf-template folder:
You can use all the CSS that is understood by mpdf (See http://mpdf1.com/manual/index.php?tid=34)
If you're a plugin developer and want to make your syntax plugin compatible with the PDF export, here are a few tips:
print.css
and PDF export will probably work out of the boxpdf.css
If you want to provide custom HTML for the PDF export you should check if the renderer is a renderer_plugin_dw2pdf
when rendering xhtml
.
function render($mode, &$renderer, $data){ if($mode == 'xhtml') { if(is_a($renderer,'renderer_plugin_dw2pdf')){ // this is the PDF export, render simple HTML here }else{ // this is normal XHTML for Browsers, be fancy here } return true; } return false; }
By default, dw2pdf
will fetch embedded images via HTTP. If you want to embed local image files without going through HTTP, you can give their location by writing an img
tag using the dw2pdf
pseudo protocol:
$R->doc .= '<img src="dw2pdf:///full/path/to/some/image.png">';
Please report issues and requests in the issue tracker: https://github.com/splitbrain/dokuwiki-plugin-dw2pdf/issues/
If you are using the dw2pdf plugin and you don't get the wanted output, than you might investigate the data during its workflow. The dw2pdf plugin uses the HTML code of the print version of an wiki article and converts this code with the mPDF-library to a pdf-file.
Some options to investigate with the intermediate results are:
How-to output plain html (just before it is inputted in the mPDF library):
&debughtml=text
displays html as plain text in the browser&debughtml=html
displays html rendered by the browserSee for the debugging options of the mPDF library related to images: http://mpdf1.com/manual/index.php?tid=245
Feel free to add yours here:
Not all image format variations are successfully embedded in the PDF, even if they are properly displayed in DokuWiki. If you get missing images in your output, try stripping the Alpha channel of your (e.g. PNG) images.
If using full http links, make sure the permissions are set up for retrieving the image directly (test in a browser). DokuWiki may prevent outside access to images in the data/media directory.
To set fixed password for generated documents, edit:
dokuwiki/lib/plugins/dw2pdf/mpdf/config.php
and add following lines:
$this->setUserRights(); $this->SetProtection(array('print','copy', 'modify'),'password','password');
where password
is your password :)
(filips)
When using with an iPhone/iPad disable the setting: Seiten mit gzip komprimiert ausliefern otherwise this plugin will not generate PDF-Files on iPhone/iPad.
Is it possible to somehow add a tutorial for how to get external embedded images into the pdf? i'd really appreciate that.
An example for the footer HTML placeholder / variable to show just the Year so that you can add a dated copyright notice : © Your Company Name @DATE(@DATE@,%Y)@?
Is there a way to disable all hyperlinks in the pdf export? The pdf contains internal wiki links that the client can't access (as the wiki is for internal use only).
Feature request : Can we have a footer_last.html and header_last.html for the back cover page or front cover page?
/lib/tpl/default/main.php
, there are two divs that contain some buttons: <div class="bar" id="bar__top">
and <div class="bar" id="bar__bottom">
. Just insert the HTML code inside one of the two divs (left or right)