1<?php 2/** 3 * Wrapper around the mpdf library class 4 * 5 * This class overrides some functions to make mpdf make use of DokuWiki' 6 * standard tools instead of its own. 7 * 8 * @author Andreas Gohr <andi@splitbrain.org> 9 */ 10 11use dokuwiki\plugin\dw2pdf\DokuImageProcessorDecorator; 12 13require_once __DIR__ . '/vendor/autoload.php'; 14 15/** 16 * Class DokuPDF 17 * Some DokuWiki specific extentions 18 */ 19class DokuPDF extends \Mpdf\Mpdf 20{ 21 22 /** 23 * DokuPDF constructor. 24 * 25 * @param string $pagesize 26 * @param string $orientation 27 * @param int $fontsize 28 */ 29 function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11) 30 { 31 global $conf; 32 33 if (!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . rand(1, 1000) . '/'); 34 io_mkdir_p(_MPDF_TEMP_PATH); 35 36 $format = $pagesize; 37 if ($orientation == 'landscape') { 38 $format .= '-L'; 39 } 40 41 switch ($conf['lang']) { 42 case 'zh': 43 case 'zh-tw': 44 case 'ja': 45 case 'ko': 46 $mode = '+aCJK'; 47 break; 48 default: 49 $mode = 'UTF-8-s'; 50 51 } 52 53 // we're always UTF-8 54 parent::__construct( 55 array( 56 'mode' => $mode, 57 'format' => $format, 58 'fontsize' => $fontsize, 59 'ImageProcessorClass' => DokuImageProcessorDecorator::class, 60 'tempDir' => _MPDF_TEMP_PATH //$conf['tmpdir'] . '/tmp/dwpdf' 61 ) 62 ); 63 64 $this->autoScriptToLang = true; 65 $this->baseScript = 1; 66 $this->autoVietnamese = true; 67 $this->autoArabic = true; 68 $this->autoLangToFont = true; 69 70 $this->ignore_invalid_utf8 = true; 71 $this->tabSpaces = 4; 72 } 73 74 /** 75 * Cleanup temp dir 76 */ 77 function __destruct() 78 { 79 io_rmdir(_MPDF_TEMP_PATH, true); 80 } 81 82 /** 83 * Decode all paths, since DokuWiki uses XHTML compliant URLs 84 * 85 * @param string $path 86 * @param string $basepath 87 */ 88 function GetFullPath(&$path, $basepath = '') 89 { 90 $path = htmlspecialchars_decode($path); 91 parent::GetFullPath($path, $basepath); 92 } 93} 94