1<?php 2/** 3 * Site Export Plugin - mPDF Extension 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author i-net software <tools@inetsoftware.de> 7 * @author Gerry Weissbach <gweissbach@inetsoftware.de> 8 */ 9 10// must be run within Dokuwiki 11if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13 14if ( file_exists(DOKU_PLUGIN . 'dw2pdf/mpdf/mpdf.php') ) { 15 16 global $conf; 17 if(!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'].'/dwpdf/'.rand(1,1000).'/'); 18 19 require_once(DOKU_PLUGIN . 'dw2pdf/mpdf/mpdf.php'); 20 21 class siteexportPDF extends mPDF { 22 23 var $debugObj = true; 24 25 function siteexportPDF($encoding, $debug=false) { 26 parent::mPDF($encoding); 27 $this->debugObj = $debug; 28 $this->debug = true; 29 $this->shrink_tables_to_fit = 1; // Does not shrink tables by default, only in emergency 30 $this->use_kwt = true; // avoids page-breaking in H1-H6 if a table follows directly 31 } 32 33 function message($msg, $vars=null, $lvl=1) 34 { 35 if ( $this->debugObj !== false ) { 36 // $this->debugObj->message($msg, $vars, $lvl); 37 } 38 } 39 40 function Error($msg) 41 { 42 if ( $this->debug !== false && $lvl == null && method_exists($this->debug, 'runtimeException') ) { 43 $this->debug->runtimeException($msg); 44 } else { 45 parent::Error($msg); 46 } 47 } 48 49 function OpenTag($tag, $attr) { 50 switch($tag) { 51 case 'BOOKMARK': 52 case 'TOCENTRY': 53 if ( $attr['CONTENT'] ) { 54 // resolve double encoding 55 $attr['CONTENT'] = htmlspecialchars_decode($attr['CONTENT'], ENT_QUOTES); 56 } 57 break; 58 } 59 return parent::OpenTag($tag, $attr); 60 } 61 62/* 63 function _putannots($n) { 64 $nb=$this->page; 65 for($n=1;$n<=$nb;$n++) 66 { 67 $annotobjs = array(); 68 if(isset($this->PageLinks[$n]) || isset($this->PageAnnots[$n])) { 69 $wPt=$this->pageDim[$n]['w']*$this->k; 70 $hPt=$this->pageDim[$n]['h']*$this->k; 71 72 //Links 73 if(isset($this->PageLinks[$n])) { 74 foreach($this->PageLinks[$n] as $key => $pl) { 75 $this->_newobj(); 76 $annot=''; 77 $rect=sprintf('%.3f %.3f %.3f %.3f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); 78 $annot .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.']'; 79 $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl[4]); 80 $annot .= ' /NM ('.sprintf('%04u-%04u', $n, $key).')'; 81 $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis')); 82 $annot .= ' /Border [0 0 0]'; 83 // mPDF 4.2.018 84 if ($this->PDFA) { $annot .= ' /F 28'; } 85 if (strpos($pl[4],'@')===0) { 86 $p=substr($pl[4],1); 87 // $h=isset($this->OrientationChanges[$p]) ? $wPt : $hPt; 88 $htarg=$this->pageDim[$p]['h']*$this->k; 89 $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3f null]>>',1+2*$p,$htarg); 90 } 91 else if(is_string($pl[4])) { 92 93 if ( preg_match( "#^(https?:/|file:)/#", $pl[4] )) { 94 $annot .= ' /A <</Type/Action/S/URI/URI'.$this->_textstring($pl[4]).'>> >>'; 95 } else { 96 $annot .= ' /A <</Type/Action/S/GoToR/F'.$this->_textstring($pl[4]).'>> >>'; 97 } 98 } 99 else { 100 $l=$this->links[$pl[4]]; 101 // mPDF 3.0 102 // may not be set if #link points to non-existent target 103 if (isset($this->pageDim[$l[0]]['h'])) { $htarg=$this->pageDim[$l[0]]['h']*$this->k; } 104 else { $htarg=$this->h*$this->k; } // doesn't really matter 105 $annot.=sprintf(' /Dest [%d 0 R /XYZ 0 %.3f null]>>',1+2*$l[0],$htarg-$l[1]*$this->k); 106 } 107 $this->_out($annot); 108 $this->_out('endobj'); 109 } 110 } 111*/ 112 113 /*-- ANNOTATIONS --*/ 114/* if(isset($this->PageAnnots[$n])) { 115 foreach ($this->PageAnnots[$n] as $key => $pl) { 116 $this->_newobj(); 117 $annot=''; 118 $pl['opt'] = array_change_key_case($pl['opt'], CASE_LOWER); 119 $x = $pl['x']; 120 if ($this->annotMargin <> 0 || $x==0 || $x<0) { // Odd page 121 $x = ($wPt/$this->k) - $this->annotMargin; 122 } 123 $w = $h = ($this->annotSize * $this->k); 124 $a = $x * $this->k; 125 // mPDF 3.0 126 $b = $hPt - ($pl['y'] * $this->k); 127 $rect = sprintf('%.3f %.3f %.3f %.3f', $a, $b-$h, $a+$w, $b); 128 $annot .= '<</Type /Annot /Subtype /Text /Rect ['.$rect.']'; 129 $annot .= ' /Contents '.$this->_UTF16BEtextstring($pl['txt']); 130 $annot .= ' /NM ('.sprintf('%04u-%04u', $n, (2000 + $key)).')'; 131 $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis')); 132 $annot .= ' /CreationDate '.$this->_textstring('D:'.date('YmdHis')); 133 $annot .= ' /Border [0 0 0]'; 134 // mPDF 4.2.018 135 if ($this->PDFA) { 136 $annot .= ' /F 28'; 137 $annot .= ' /CA 1'; 138 } 139 else if ($pl['opt']['ca']>0) { $annot .= ' /CA '.$pl['opt']['ca']; } 140 141 $annot .= ' /C ['; 142 if (isset($pl['opt']['c']) AND (is_array($pl['opt']['c']))) { 143 foreach ($pl['opt']['c'] as $col) { 144 $col = intval($col); 145 $color = $col <= 0 ? 0 : ($col >= 255 ? 1 : $col / 255); 146 $annot .= sprintf(" %.4f", $color); 147 } 148 } 149 else { $annot .= '1 1 0'; } // mPDF 4.2.026 150 $annot .= ']'; 151 // Usually Author 152 if (isset($pl['opt']['t']) AND is_string($pl['opt']['t'])) { 153 $annot .= ' /T '.$this->_UTF16BEtextstring($pl['opt']['t']); 154 } 155 if (isset($pl['opt']['subj'])) { 156 $annot .= ' /Subj '.$this->_UTF16BEtextstring($pl['opt']['subj']); 157 } 158 $iconsapp = array('Comment', 'Help', 'Insert', 'Key', 'NewParagraph', 'Note', 'Paragraph'); 159 if (isset($pl['opt']['icon']) AND in_array($pl['opt']['icon'], $iconsapp)) { 160 $annot .= ' /Name /'.$pl['opt']['icon']; 161 } 162 else { $annot .= ' /Name /Note'; } 163 // mPDF 4.2.027 164 if (!empty($pl['opt']['popup'])) { 165 $annot .= ' /Open true'; 166 $annot .= ' /Popup '.($this->n+1).' 0 R'; // mPDF 4.2.027 167 } 168 else { $annot .= ' /Open false'; } // mPDF 4.2.027 169 $annot .= ' /P 3 0 R'; // mPDF 4.2.027 170 $annot .= '>>'; 171 $this->_out($annot); 172 $this->_out('endobj'); 173 174 // mPDF 4.2.027 175 if (!empty($pl['opt']['popup'])) { 176 $this->_newobj(); 177 $annot=''; 178 if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][0])) { $x = $pl['opt']['popup'][0] * $this->k; } 179 else { $x = $pl['x'] * $this->k; } 180 if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][1])) { $y = $hPt - ($pl['opt']['popup'][1] * $this->k); } 181 else { $y = $hPt - ($pl['y'] * $this->k); } 182 if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][2])) { $w = $pl['opt']['popup'][2] * $this->k; } 183 else { $w = 180; } 184 if (is_array($pl['opt']['popup']) && isset($pl['opt']['popup'][3])) { $h = $pl['opt']['popup'][3] * $this->k; } 185 else { $h = 120; } 186 $rect = sprintf('%.3f %.3f %.3f %.3f', $x, $y-$h, $x+$w, $y); 187 $annot .= '<</Type /Annot /Subtype /Popup /Rect ['.$rect.']'; 188 $annot .= ' /M '.$this->_textstring('D:'.date('YmdHis')); 189 if ($this->PDFA) { $annot .= ' /F 28'; } 190 $annot .= ' /P 3 0 R'; 191 $annot .= ' /Parent '.($this->n-1).' 0 R'; 192 $annot .= '>>'; 193 $this->_out($annot); 194 $this->_out('endobj'); 195 } 196 } 197 } 198*/ /*-- END ANNOTATIONS --*/ 199/* } 200 } 201 } 202*/ 203 } 204}