Table of Contents
⇐ 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 theprint.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']