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