*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
/**
* Render xhtml suitable as input for mpdf library
*/
class renderer_plugin_dw2pdf extends Doku_Renderer_xhtml {
private $lastheadlevel = -1;
private $current_bookmark_level = 0;
/**
* Stores action instance
*
* @var action_plugin_dw2pdf
*/
private $actioninstance = null;
/**
* load action plugin instance
*/
public function __construct() {
$this->actioninstance = plugin_load('action', 'dw2pdf');
}
public function document_start() {
global $ID;
parent::document_start();
//ancher for rewritten links to included pages
$check = false;
$pid = sectionID($ID, $check);
$this->doc .= "";
$this->doc .= "";
}
/**
* Make available as XHTML replacement renderer
*
* @param $format
* @return bool
*/
public function canRender($format){
if($format == 'xhtml') return true;
return false;
}
/**
* Simplified header printing with PDF bookmarks
*
* @param string $text
* @param int $level
* @param int $pos
*/
public function header($text, $level, $pos) {
if(!$text) return; //skip empty headlines
global $ID;
$hid = $this->_headerToLink($text, true);
//only add items within global configured levels (doesn't check the pdf toc settings)
$this->toc_additem($hid, $text, $level);
$check = false;
$pid = sectionID($ID, $check);
$hid = $pid . '__' . $hid;
// add PDF bookmark
$bookmark = '';
$bmlevel = $this->actioninstance->getExportConfig('maxbookmarks');
if($bmlevel && $bmlevel >= $level) {
// PDF readers choke on invalid nested levels
if($this->lastheadlevel == -1) {
$this->lastheadlevel = $level;
}
$step = $level - $this->lastheadlevel;
if($step > 0) {
$this->current_bookmark_level += 1;
} elseif($step < 0) {
$this->current_bookmark_level -= 1;
if($this->current_bookmark_level < 0) {
$this->current_bookmark_level = 0;
}
}
$this->lastheadlevel = $level;
$bookmark = '