DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:dw2pdf:exportsupport

dw2pdf plugin

For plugin developers, who want to export to PDF

If you're a plugin developer and want to make your syntax plugin compatible with the PDF export, here are a few tips:

  • provide a useful print.css/print.less and PDF export will probably work out of the box
  • if you want to use special stylings for PDF export provide a pdf.css/pdf.less (it will replace the print.css/print.less)
  • your HTML and CSS should be simple enough to be understood by mPDF (see mpdf.github.io documentation)

Custom HTML for PDF export

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;
}

Fetch images without HTTP request

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">';

Examples:

Use custom placeholders in HTML templates

Dw2pdf provides an event called PLUGIN_DW2PDF_REPLACE, which gives other plugins access to replacement patterns and all processed template parts, including cover and citation.

Example usage in the action component of your plugin:

  • Register two hooks for the PLUGIN_DW2PDF_REPLACE event, one called before and the other after the event.
  • In the first hook, add your replacement patterns (or modify existing ones) to $event->data['replace']
  • In the second hook, clean up your remaining replacements in $event->data['content']
plugin/dw2pdf/exportsupport.txt · Last modified: 2023-08-04 19:39 by Klap-in

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