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 */ 10global $conf; 11if(!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'] . '/dwpdf/' . rand(1, 1000) . '/'); 12 13require_once __DIR__ . '/vendor/autoload.php'; 14require __DIR__ . '/DokuImageProcessorDecorator.class.php'; 15 16/** 17 * Class DokuPDF 18 * Some DokuWiki specific extentions 19 */ 20class DokuPDF extends \Mpdf\Mpdf { 21 22 function __construct($pagesize = 'A4', $orientation = 'portrait', $fontsize = 11) { 23 global $conf; 24 25 io_mkdir_p(_MPDF_TEMP_PATH); 26 27 $format = $pagesize; 28 if($orientation == 'landscape') { 29 $format .= '-L'; 30 } 31 32 switch($conf['lang']) { 33 case 'zh': 34 case 'zh-tw': 35 case 'ja': 36 case 'ko': 37 $mode = '+aCJK'; 38 break; 39 default: 40 $mode = 'UTF-8-s'; 41 42 } 43 44 // we're always UTF-8 45 parent::__construct( 46 array( 47 'mode' => $mode, 48 'format' => $format, 49 'fontsize' => $fontsize, 50 'ImageProcessorClass' => DokuImageProcessorDecorator::class, 51 'tempDir' => _MPDF_TEMP_PATH //$conf['tmpdir'] . '/tmp/dwpdf' 52 ) 53 ); 54 55 $this->autoScriptToLang = true; 56 $this->baseScript = 1; 57 $this->autoVietnamese = true; 58 $this->autoArabic = true; 59 $this->autoLangToFont = true; 60 61 $this->ignore_invalid_utf8 = true; 62 $this->tabSpaces = 4; 63 } 64 65 /** 66 * Cleanup temp dir 67 */ 68 function __destruct() { 69 io_rmdir(_MPDF_TEMP_PATH, true); 70 } 71 72 /** 73 * Decode all paths, since DokuWiki uses XHTML compliant URLs 74 */ 75 function GetFullPath(&$path, $basepath = '') { 76 $path = htmlspecialchars_decode($path); 77 parent::GetFullPath($path, $basepath); 78 } 79} 80