PluginProbe ʕ •ᴥ•ʔ
Event Tickets with Ticket Scanner / 2.8.4
Event Tickets with Ticket Scanner v2.8.4
3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.4 trunk 2.6.0 2.7.0 2.7.1 2.7.10 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3
event-tickets-with-ticket-scanner / sasoEventtickets_PDF.php
event-tickets-with-ticket-scanner Last commit date
3rd 5 months ago css 5 months ago img 5 months ago includes 5 months ago js 5 months ago languages 5 months ago ticket 5 months ago vendors 5 months ago .gitignore 5 months ago SASO_EVENTTICKETS.php 5 months ago backend.js 5 months ago changelog.txt 5 months ago db.php 5 months ago index.php 5 months ago init_file.php 5 months ago order_details.js 5 months ago readme.txt 5 months ago saso-eventtickets-validator.js 5 months ago sasoEventtickets_AdminSettings.php 5 months ago sasoEventtickets_Authtoken.php 5 months ago sasoEventtickets_Base.php 5 months ago sasoEventtickets_Core.php 5 months ago sasoEventtickets_Frontend.php 5 months ago sasoEventtickets_Messenger.php 5 months ago sasoEventtickets_Options.php 5 months ago sasoEventtickets_PDF.php 5 months ago sasoEventtickets_Seating.php 5 months ago sasoEventtickets_Ticket.php 5 months ago sasoEventtickets_TicketBadge.php 5 months ago sasoEventtickets_TicketDesigner.php 5 months ago sasoEventtickets_TicketQR.php 5 months ago ticket_events.js 5 months ago ticket_scanner.js 5 months ago validator.js 5 months ago wc_backend.js 5 months ago wc_frontend.js 5 months ago woocommerce-hooks.php 5 months ago
sasoEventtickets_PDF.php
535 lines
1 <?php
2 use setasign\Fpdi\Tcpdf\Fpdi;
3 include_once(plugin_dir_path(__FILE__)."init_file.php");
4 class sasoEventtickets_PDF {
5 private $parts = [];
6 private $filemode;
7 private $filepath;
8 private $filename;
9 private $orientation = "P";
10 private $page_format = 'A4';
11 private $isRTL = false;
12 private $languageArray = null;
13 private $background_image = null;
14 private $fontSize = 10;
15 private $fontFamily = "dejavusans";
16
17 private $is_own_page_format = false;
18 private $size_width = 210;
19 private $size_height = 297;
20 public $marginsZero = false;
21
22 private $attach_pdfs = [];
23
24 private $qr;
25 private $qr_values;
26
27 public function __construct($parts=[], $filemode="I", $filename="PDF.pdf") {
28 $this->qr_values = $this->getDefaultQRValues();
29 if (is_array($parts)) $this->setParts($parts);
30 $this->setFilemode($filemode);
31 $this->setFilename($filename);
32 $this->_loadLibs();
33 }
34
35 private function _loadLibs() {
36 // always load alternative config file for examples
37
38 //require_once('vendors/TCPDF/config/tcpdf_config_alt.php');
39 require_once('vendors/TCPDF/config/tcpdf_config.php');
40
41 // Include the main TCPDF library (search the library on the following directories).
42 if (!class_exists('TCPDF')) {
43 $tcpdf_include_dirs = array(
44 plugin_dir_path(__FILE__).'vendors/TCPDF/tcpdf.php',
45 realpath(dirname(__FILE__) . '/vendors/TCPDF/tcpdf.php'),// True source file
46 realpath('vendors/TCPDF/tcpdf.php'),// Relative from $PWD
47 '/usr/share/php/tcpdf/tcpdf.php',
48 '/usr/share/tcpdf/tcpdf.php',
49 '/usr/share/php-tcpdf/tcpdf.php',
50 '/var/www/tcpdf/tcpdf.php',
51 '/var/www/html/tcpdf/tcpdf.php',
52 '/usr/local/apache2/htdocs/tcpdf/tcpdf.php'
53 );
54 foreach ($tcpdf_include_dirs as $tcpdf_include_path) {
55 if (@file_exists($tcpdf_include_path)) {
56 require_once($tcpdf_include_path);
57 break;
58 }
59 }
60 }
61
62 if (!class_exists('Fpdi')) {
63 require_once('vendors/FPDI-2.3.7/src/autoload.php');
64 }
65 if (!class_exists('FPDF')) {
66 require_once("vendors/fpdf185/fpdf.php");
67 }
68 }
69
70 public function getFontInfos() {
71 // Returns an array with font names and their descriptions
72 // The array contains the font name as key and an array with "name", "lang_support" and "desc" as values
73 // "name" is the display name
74 // "lang_support" is a string with language codes that the font supports (e.g. "en, de, fr")
75 // "desc" is a description of the font
76 // The array is sorted by the font name
77 // The font names are the same as in the TCPDF library, so you can use them directly in the SetFont() method
78 // The font names are case-sensitive, so you must use the exact name as in the array
79 // the font names are in the folder vendors/TCPDF/fonts
80 // The array is used to populate a dropdown list in the settings page of the plugin
81 $infos = [
82 'aealarabiya'=>["name"=>'AE Al Arabiya', "lang_support"=>"ar", "desc"=>"AE Al Arabiya is a font family that supports Arabic characters."],
83 'aefurat'=>["name"=>'AE Furat', "lang_support"=>"ar", "desc"=>"AE Furat is a font family that supports Arabic characters."],
84 'cid0jp'=>["name"=>'CID0JP', "lang_support"=>"ja", "desc"=>"CID0JP is a font family that supports Japanese characters."],
85 'cid0kr'=>["name"=>'CID0KR', "lang_support"=>"ko", "desc"=>"CID0KR is a font family that supports Korean characters."],
86 'cid0cn'=>["name"=>'CID0CN', "lang_support"=>"zh", "desc"=>"CID0CN is a font family that supports Chinese characters."],
87 'cid0tw'=>["name"=>'CID0TW', "lang_support"=>"zh", "desc"=>"CID0TW is a font family that supports Traditional Chinese characters."],
88 'cid0vn'=>["name"=>'CID0VN', "lang_support"=>"vi", "desc"=>"CID0VN is a font family that supports Vietnamese characters."],
89 'cid0th'=>["name"=>'CID0TH', "lang_support"=>"th", "desc"=>"CID0TH is a font family that supports Thai characters."],
90 'cid0cs'=>["name"=>'CID0CS', "lang_support"=>"cn", "desc"=>"CID0CS is a font family that supports chinese simplified characters."],
91 'cid0ct'=>["name"=>'CID0CT', "lang_support"=>"cn", "desc"=>"CID0CT is a font family that supports chinese traditional characters."],
92 'cid0arabic'=>["name"=>'CID0Arabic', "lang_support"=>"ar", "desc"=>"CID0Arabic is a font family that supports Arabic characters."],
93 'cid0hebrew'=>["name"=>'CID0Hebrew', "lang_support"=>"he", "desc"=>"CID0Hebrew is a font family that supports Hebrew characters."],
94 'cid0cyrillic'=>["name"=>'CID0Cyrillic', "lang_support"=>"ru", "desc"=>"CID0Cyrillic is a font family that supports Cyrillic characters."],
95 'cid0greek'=>["name"=>'CID0Greek', "lang_support"=>"el", "desc"=>"CID0Greek is a font family that supports Greek characters."],
96 'cid0thai'=>["name"=>'CID0Thai', "lang_support"=>"th", "desc"=>"CID0Thai is a font family that supports Thai characters."],
97 'cid0vietnamese'=>["name"=>'CID0Vietnamese', "lang_support"=>"vi", "desc"=>"CID0Vietnamese is a font family that supports Vietnamese characters."],
98 'cid0latin'=>["name"=>'CID0Latin', "lang_support"=>"", "desc"=>"CID0Latin is a font family that supports Latin characters."],
99 'cid0latinext'=>["name"=>'CID0Latin Extended', "lang_support"=>"", "desc"=>"CID0Latin Extended is a font family that supports Latin characters with extended glyphs."],
100 'cid0cyrillicext'=>["name"=>'CID0Cyrillic Extended', "lang_support"=>"", "desc"=>"CID0Cyrillic Extended is a font family that supports Cyrillic characters with extended glyphs."],
101 'cid0greekext'=>["name"=>'CID0Greek Extended', "lang_support"=>"", "desc"=>"CID0Greek Extended is a font family that supports Greek characters with extended glyphs."],
102 'cid0arabicext'=>["name"=>'CID0Arabic Extended', "lang_support"=>"", "desc"=>"CID0Arabic Extended is a font family that supports Arabic characters with extended glyphs."],
103 'courier'=>["name"=>'Courier', "lang_support"=>"", "desc"=>"Courier is a monospaced font that is widely used for programming and technical documents."],
104 'courierb'=>["name"=>'Courier Bold', "lang_support"=>"", "desc"=>"Courier Bold is a bold version of the Courier font."],
105 'courieri'=>["name"=>'Courier Italic', "lang_support"=>"", "desc"=>"Courier Italic is an italic version of the Courier font."],
106 'courierbi'=>["name"=>'Courier Bold Italic', "lang_support"=>"", "desc"=>"Courier Bold Italic is a bold italic version of the Courier font."],
107 'dejavusans'=>["name"=>'DejaVu Sans', "lang_support"=>"", "desc"=>"DejaVu Sans is a font family based on the Bitstream Vera Fonts with a wider range of characters."],
108 'dejavusansb'=>["name"=>'DejaVu Sans Bold', "lang_support"=>"", "desc"=>"DejaVu Sans Bold is a bold version of the DejaVu Sans font."],
109 'dejavusansi'=>["name"=>'DejaVu Sans Italic', "lang_support"=>"", "desc"=>"DejaVu Sans Italic is an italic version of the DejaVu Sans font."],
110 'dejavusansbi'=>["name"=>'DejaVu Sans Bold Italic', "lang_support"=>"", "desc"=>"DejaVu Sans Bold Italic is a bold italic version of the DejaVu Sans font."],
111 'dejavusanscondensed'=>["name"=>'DejaVu Sans Condensed', "lang_support"=>"", "desc"=>"DejaVu Sans Condensed is a font family based on the Bitstream Vera Fonts with a wider range of characters."],
112 'dejavusanscondensedb'=>["name"=>'DejaVu Sans Condensed Bold', "lang_support"=>"", "desc"=>"DejaVu Sans Condensed Bold is a bold version of the DejaVu Sans Condensed font."],
113 'dejavusanscondensedi'=>["name"=>'DejaVu Sans Condensed Italic', "lang_support"=>"", "desc"=>"DejaVu Sans Condensed Italic is an italic version of the DejaVu Sans Condensed font."],
114 'dejavusanscondensedbi'=>["name"=>'DejaVu Sans Condensed Bold Italic', "lang_support"=>"", "desc"=>"DejaVu Sans Condensed Bold Italic is a bold italic version of the DejaVu Sans Condensed font."],
115 'dejavusansextralight'=>["name"=>'DejaVu Sans ExtraLight', "lang_support"=>"", "desc"=>"DejaVu Sans ExtraLight is a font family based on the Bitstream Vera Fonts with a wider range of characters."],
116 'dejavusansi'=>["name"=>'DejaVu Sans ExtraLight Italic', "lang_support"=>"", "desc"=>"DejaVu Sans ExtraLight Italic is an italic version of the DejaVu Sans ExtraLight font."],
117 'dejavusansmono'=>["name"=>'DejaVu Sans Mono', "lang_support"=>"", "desc"=>"DejaVu Sans Mono is a font family based on the Bitstream Vera Fonts with a wider range of characters."],
118 'dejavusansmonob'=>["name"=>'DejaVu Sans Mono Bold', "lang_support"=>"", "desc"=>"DejaVu Sans Mono Bold is a bold version of the DejaVu Sans Mono font."],
119 'dejavusansmonoi'=>["name"=>'DejaVu Sans Mono Italic', "lang_support"=>"", "desc"=>"DejaVu Sans Mono Italic is an italic version of the DejaVu Sans Mono font."],
120 'dejavusansmonobi'=>["name"=>'DejaVu Sans Mono Bold Italic', "lang_support"=>"", "desc"=>"DejaVu Sans Mono Bold Italic is a bold italic version of the DejaVu Sans Mono font."],
121 'dejavuserif'=>["name"=>'DejaVu Serif', "lang_support"=>"", "desc"=>"DejaVu Serif is a font family based on the Bitstream Vera Fonts with a wider range of characters."],
122 'dejavuserifcondensed'=>["name"=>'DejaVu Serif Condensed', "lang_support"=>"", "desc"=>"DejaVu Serif Condensed is a font family based on the Bitstream Vera Fonts with a wider range of characters."],
123 'dejavuserifmono'=>["name"=>'DejaVu Serif Mono', "lang_support"=>"", "desc"=>"DejaVu Serif Mono is a font family based on the Bitstream Vera Fonts with a wider range of characters."],
124 'freemono'=>["name"=>'FreeMono', "lang_support"=>"", "desc"=>"FreeMono is a monospaced font that is widely used for programming and technical documents."],
125 'freemonob'=>["name"=>'FreeMono Bold', "lang_support"=>"", "desc"=>"FreeMono Bold is a bold version of the FreeMono font."],
126 'freemonoi'=>["name"=>'FreeMono Italic', "lang_support"=>"", "desc"=>"FreeMono Italic is an italic version of the FreeMono font."],
127 'freemonobi'=>["name"=>'FreeMono Bold Italic', "lang_support"=>"", "desc"=>"FreeMono Bold Italic is a bold italic version of the FreeMono font."],
128 'freesans'=>["name"=>'FreeSans', "lang_support"=>"", "desc"=>"FreeSans is a sans-serif font that is widely used for general-purpose documents."],
129 'freesansb'=>["name"=>'FreeSans Bold', "lang_support"=>"", "desc"=>"FreeSans Bold is a bold version of the FreeSans font."],
130 'freesansi'=>["name"=>'FreeSans Italic', "lang_support"=>"", "desc"=>"FreeSans Italic is an italic version of the FreeSans font."],
131 'freesansbi'=>["name"=>'FreeSans Bold Italic', "lang_support"=>"", "desc"=>"FreeSans Bold Italic is a bold italic version of the FreeSans font."],
132 'freeserif'=>["name"=>'FreeSerif', "lang_support"=>"", "desc"=>"FreeSerif is a serif font that is widely used for general-purpose documents."],
133 'freeserifb'=>["name"=>'FreeSerif Bold', "lang_support"=>"", "desc"=>"FreeSerif Bold is a bold version of the FreeSerif font."],
134 'freeserifi'=>["name"=>'FreeSerif Italic', "lang_support"=>"", "desc"=>"FreeSerif Italic is an italic version of the FreeSerif font."],
135 'freeserifbi'=>["name"=>'FreeSerif Bold Italic', "lang_support"=>"", "desc"=>"FreeSerif Bold Italic is a bold italic version of the FreeSerif font."],
136 'helvetica'=>["name"=>'Helvetica', "lang_support"=>"", "desc"=>"Helvetica is a widely used sans-serif font that is known for its clean and modern appearance."],
137 'helveticab'=>["name"=>'Helvetica Bold', "lang_support"=>"", "desc"=>"Helvetica Bold is a bold version of the Helvetica font."],
138 'helveticai'=>["name"=>'Helvetica Italic', "lang_support"=>"", "desc"=>"Helvetica Italic is an italic version of the Helvetica font."],
139 'helveticabi'=>["name"=>'Helvetica Bold Italic', "lang_support"=>"", "desc"=>"Helvetica Bold Italic is a bold italic version of the Helvetica font."],
140 'hysmyeongjostdmedium'=>["name"=>'HYSMyeongJoStd-Medium', "lang_support"=>"ko", "desc"=>"HYSMyeongJoStd-Medium is a font family that supports Korean characters."],
141 'kozgopromedium'=>["name"=>'KoZGoPro-Medium', "lang_support"=>"ko", "desc"=>"KoZGoPro-Medium is a font family that supports Korean characters."],
142 'kozminproregular'=>["name"=>'KoZMinPro-Regular', "lang_support"=>"ja", "desc"=>"KoZMinPro-Regular is a font family that supports Japanese characters."],
143 'msungstdlight'=>["name"=>'MyeongJoStd-Light', "lang_support"=>"ko", "desc"=>"MyeongJoStd-Light is a font family that supports Korean characters."],
144 'pdfacourier'=>["name"=>'PDFa Courier', "lang_support"=>"", "desc"=>"PDFa Courier is a monospaced font that is widely used for programming and technical documents."],
145 'pdfacourierb'=>["name"=>'PDFa Courier Bold', "lang_support"=>"", "desc"=>"PDFa Courier Bold is a bold version of the PDFa Courier font."],
146 'pdfacourieri'=>["name"=>'PDFa Courier Italic', "lang_support"=>"", "desc"=>"PDFa Courier Italic is an italic version of the PDFa Courier font."],
147 'pdfacourierbi'=>["name"=>'PDFa Courier Bold Italic', "lang_support"=>"", "desc"=>"PDFa Courier Bold Italic is a bold italic version of the PDFa Courier font."],
148 'pdfahelvetica'=>["name"=>'PDFa Helvetica', "lang_support"=>"", "desc"=>"PDFa Helvetica is a widely used sans-serif font that is known for its clean and modern appearance."],
149 'pdfahelveticab'=>["name"=>'PDFa Helvetica Bold', "lang_support"=>"", "desc"=>"PDFa Helvetica Bold is a bold version of the PDFa Helvetica font."],
150 'pdfahelveticai'=>["name"=>'PDFa Helvetica Italic', "lang_support"=>"", "desc"=>"PDFa Helvetica Italic is an italic version of the PDFa Helvetica font."],
151 'pdfahelveticabi'=>["name"=>'PDFa Helvetica Bold Italic', "lang_support"=>"", "desc"=>"PDFa Helvetica Bold Italic is a bold italic version of the PDFa Helvetica font."],
152 'pdfasymbol'=>["name"=>'PDFa Symbol', "lang_support"=>"", "desc"=>"PDFa Symbol is a font family that supports mathematical symbols and special characters."],
153 'pdfatimes'=>["name"=>'PDFa Times', "lang_support"=>"", "desc"=>"PDFa Times is a serif font that is widely used for general-purpose documents."],
154 'pdfatimesb'=>["name"=>'PDFa Times Bold', "lang_support"=>"", "desc"=>"PDFa Times Bold is a bold version of the PDFa Times font."],
155 'pdfatimesi'=>["name"=>'PDFa Times Italic', "lang_support"=>"", "desc"=>"PDFa Times Italic is an italic version of the PDFa Times font."],
156 'pdfatimesbi'=>["name"=>'PDFa Times Bold Italic', "lang_support"=>"", "desc"=>"PDFa Times Bold Italic is a bold italic version of the PDFa Times font."],
157 'pdfazapfdingbats'=>["name"=>'PDFa ZapfDingbats', "lang_support"=>"", "desc"=>"PDFa ZapfDingbats is a font family that supports various symbols and icons."],
158 'roboto'=>["name"=>'Roboto', "lang_support"=>"", "desc"=>"Roboto is a sans-serif font that is widely used for general-purpose documents."],
159 'stsongstdlight'=>["name"=>'STSongStd-Light', "lang_support"=>"zh", "desc"=>"STSongStd-Light is a font family that supports Simplified Chinese characters."],
160 'symbol'=>["name"=>'Symbol', "lang_support"=>"", "desc"=>"Symbol is a font family that supports mathematical symbols and special characters."],
161 'times'=>["name"=>'Times', "lang_support"=>"", "desc"=>"Times is a serif font that is widely used for general-purpose documents."],
162 'timesb'=>["name"=>'Times Bold', "lang_support"=>"", "desc"=>"Times Bold is a bold version of the Times font."],
163 'timesi'=>["name"=>'Times Italic', "lang_support"=>"", "desc"=>"Times Italic is an italic version of the Times font."],
164 'timesbi'=>["name"=>'Times Bold Italic', "lang_support"=>"", "desc"=>"Times Bold Italic is a bold italic version of the Times font."],
165 'uni2cid_ac15'=>["name"=>'Uni2CID_AC15', "lang_support"=>"", "desc"=>"Uni2CID_AC15 is a font family that supports various characters and symbols."],
166 'uni2cid_ag15'=>["name"=>'Uni2CID_AG15', "lang_support"=>"", "desc"=>"Uni2CID_AG15 is a font family that supports various characters and symbols."],
167 'uni2cid_aj16'=>["name"=>'Uni2CID_AJ16', "lang_support"=>"", "desc"=>"Uni2CID_AJ16 is a font family that supports various characters and symbols."],
168 'uni2cid_ak12'=>["name"=>'Uni2CID_AK12', "lang_support"=>"", "desc"=>"Uni2CID_AK12 is a font family that supports various characters and symbols."],
169 'zapfdingbats'=>["name"=>'ZapfDingbats', "lang_support"=>"", "desc"=>"ZapfDingbats is a font family that supports various symbols and icons."],
170 ];
171 // sort by name
172 ksort($infos);
173 return $infos;
174 }
175 public function getPossibleFontFamiles() {
176 $ret = ["default"=>'dejavusans', "fonts"=>[]];
177 if ($handle = opendir(__DIR__.'/vendors/TCPDF/fonts')) {
178 while (false !== ($entry = readdir($handle))) {
179 if (pathinfo($entry, PATHINFO_EXTENSION) == "php") {
180 $ret["fonts"][] = substr($entry, 0, -4);
181 }
182 }
183 closedir($handle);
184 }
185 return $ret;
186 }
187
188 public function setAdditionalPDFsToAttachThem($pdfs) {
189 if (!is_array($pdfs)) {
190 $pdfs = [$pdfs];
191 }
192 $this->attach_pdfs = $pdfs;
193 }
194
195 public function setBackgroundImage($background_image=null) {
196 $this->background_image = $background_image;
197 }
198
199 public function setFontSize($number=10) {
200 $this->fontSize = intval($number);
201 }
202
203 public function convertPixelIntoMm($pixels, $dpi=96) {
204 if ($dpi < 1) $dpi = 96;
205 return $pixels * 25.4 / $dpi;
206 }
207
208 private function getDefaultQRValues() {
209 return [
210 'pos'=>['x'=>150, 'y'=>10],
211 'size'=>['width'=>50, 'height'=>50],
212 "type"=>"QRCODE,Q",
213 'style'=>[
214 'position'=>'R',
215 //'align'=>'C',
216 'border' => 0,
217 'vpadding' => 0,//'auto',
218 'hpadding' => 0,//'auto',
219 'fgcolor' => array(0,0,0),
220 //'bgcolor' => false, //array(255,255,255)
221 'bgcolor' => array(255,255,255),
222 'module_width' => 1, // width of a single module in points
223 'module_height' => 1 // height of a single module in points
224 ],
225 'align'=>'C'
226 ];
227 }
228
229 public function setQRParams($data) {
230 foreach ($data as $key => $value) {
231 if (is_array($value)) {
232 $this->qr_values[$key] = array_merge($this->qr_values[$key], $value);
233 } else {
234 $this->qr_values[$key] = $value;
235 }
236 }
237 }
238
239 public function setFontFamily($fontFamily="dejavusans") {
240 $this->fontFamily = trim($fontFamily);
241 }
242
243 public function initQR() {
244 $this->qr = array_merge(["text"=>""], $this->qr_values);
245 }
246
247 public function setSize($w, $h) {
248 $this->is_own_page_format = true;
249 $this->size_width = intval($w);
250 $this->size_height = intval($h);
251 }
252 public function setRTL($rtl=false) {
253 $this->isRTL = $rtl;
254 }
255 public function isRTL() {
256 return $this->isRTL;
257 }
258 public function setLanguageArray($a) {
259 $this->languageArray = $a;
260 }
261 public function setQRCodeContent($qr) {
262 if ($this->qr == null) {
263 $this->initQR();
264 }
265 foreach ($qr as $key => $value) {
266 if (is_array($this->qr[$key]) && is_array($value)) {
267 $this->qr[$key] = array_merge($this->qr[$key], $value);
268 } else {
269 $this->qr[$key] = $value;
270 }
271 }
272 }
273 public function setPageFormat($format) {
274 $this->page_format = trim($format);
275 }
276 public function setOrientation($value){
277 // L oder P
278 $this->orientation = addslashes(trim($value));
279 }
280 public function setFilemode($m) {
281 $this->filemode = strtoupper($m);
282 }
283
284 public function getFilemode() {
285 return $this->filemode;
286 }
287 public function setFilepath($path) {
288 $this->filepath = trim($path);
289 }
290 public function setFilename($p) {
291 $this->filename = trim($p);
292 }
293
294 public function getFullFilePath() {
295 return $this->filepath.$this->filename;
296 }
297 public function setParts($parts=[]) {
298 $this->parts = [];
299 foreach($parts as $part) {
300 $this->addPart($part);
301 }
302 }
303 public function addPart($part) {
304 $teile = explode('{PAGEBREAK}', $part);
305 foreach($teile as $teil) {
306 $this->parts[] = $teil;
307 }
308 }
309
310 private function getParts() {
311 return $this->parts;
312 }
313
314 private function prepareOutputBuffer() {
315 if ($this->filemode != "F" && ob_get_length() !== false) ob_clean();
316 if ($this->filemode != "F") ob_start();
317 }
318 private function cleanOutputBuffer() {
319 if ($this->filemode != "F") {
320 $output_level = ob_get_level();
321 for ($a=0;$a<$output_level;$a++) {
322 ob_end_clean();
323 }
324 }
325 }
326 private function outputPDF($pdf) {
327 if ($this->filemode == "F") {
328 $pdf->Output($this->filepath.$this->filename, $this->filemode);
329 } else {
330 header_remove();
331 $pdf->Output($this->filename, $this->filemode);
332 }
333 }
334
335 private function getFormat() {
336 $format = $this->page_format;
337 if ($this->is_own_page_format) {
338 $format = [$this->size_width, $this->size_height];
339 }
340 return $format;
341 }
342
343 private function checkFilePath() {
344 if (empty($this->filepath)) $this->filepath = get_temp_dir();
345 }
346
347 private function attachPDFs($pdf, $pdf_filelocations=[]) {
348 if (count($pdf_filelocations) > 0) {
349 foreach($pdf_filelocations as $pdf_filelocation) {
350 // mergen und entsprechend dem filemode senden
351 $pagenumbers = $pdf->setSourceFile($pdf_filelocation);
352 for ($a=1;$a<=$pagenumbers;$a++) {
353 $tplIdx = $pdf->importPage($a);
354 $pdf->AddPage();
355 $pdf->useTemplate($tplIdx,0,0,null,null,true);
356 }
357 }
358 }
359 return $pdf;
360 }
361
362 public function mergeFiles($pdf_filelocations=[]) {
363 if (count($pdf_filelocations) == 0) throw new Exception("no files to merge");
364 $this->prepareOutputBuffer();
365 $this->checkFilePath();
366 $format = $this->getFormat();
367 $pdf = new Fpdi($this->orientation, PDF_UNIT, $format, true, 'UTF-8', false, false);
368 $pdf = $this->attachPDFs($pdf, $pdf_filelocations);
369
370 $this->cleanOutputBuffer();
371 $this->outputPDF($pdf);
372 }
373
374 public function render() {
375 $this->prepareOutputBuffer();
376 $this->checkFilePath();
377 $format = $this->getFormat();
378
379 if ($this->size_width > $this->size_height) {
380 $this->orientation = "L";
381 }
382
383 $pdf = new Fpdi($this->orientation, PDF_UNIT, $format, true, 'UTF-8', false, false);
384 //$pdf->error = function ($msg) {throw new Exception("PDF-Parser: ".$msg);};
385
386 $preferences = [
387 //'HideToolbar' => true,
388 //'HideMenubar' => true,
389 //'HideWindowUI' => true,
390 //'FitWindow' => true,
391 'CenterWindow' => true,
392 //'DisplayDocTitle' => true,
393 //'NonFullScreenPageMode' => 'UseNone', // UseNone, UseOutlines, UseThumbs, UseOC
394 //'ViewArea' => 'CropBox', // CropBox, BleedBox, TrimBox, ArtBox
395 //'ViewClip' => 'CropBox', // CropBox, BleedBox, TrimBox, ArtBox
396 'PrintArea' => 'CropBox', // CropBox, BleedBox, TrimBox, ArtBox
397 //'PrintClip' => 'CropBox', // CropBox, BleedBox, TrimBox, ArtBox
398 'PrintScaling' => 'None', // None, AppDefault
399 'Duplex' => 'DuplexFlipLongEdge', // Simplex, DuplexFlipShortEdge, DuplexFlipLongEdge
400 'PickTrayByPDFSize' => true,
401 //'PrintPageRange' => array(1,1,2,3),
402 //'NumCopies' => 2
403 ];
404 if ($this->orientation == "L") $preferences['Duplex'] = "DuplexFlipShortEdge";
405 $pdf->setViewerPreferences($preferences);
406 $pdf->SetAutoPageBreak(TRUE, 5);
407
408 // set image scale factor
409 $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
410 $pdf->setJPEGQuality(90);
411
412 //$pdf->addFormat("custom", $this->size_width, $this->size_height);
413
414 // set margins
415 if ($this->marginsZero) {
416 $pdf->SetMargins(0, 0, 0);
417 }
418 //$pdf->SetMargins(PDF_MARGIN_LEFT, 17, 10);
419 //$pdf->SetHeaderMargin(10);
420 //$pdf->SetFooterMargin(10);
421
422 $pdf->SetPrintHeader(false);
423 $pdf->SetPrintFooter(false);
424
425 if ($this->isRTL) {
426 $pdf->setRTL(true);
427 }
428
429 if ($this->languageArray != null) {
430 $pdf->setLanguageArray($this->languageArray);
431 }
432
433 //$pdf->SetFont('helvetica', '', "10pt");
434 //$pdf->SetFont('dejavusans', '', $this->fontSize."pt");
435 //$pdf->SetFont('cid0jp', '', $this->fontSize."pt"); // support for japanese
436 $pdf->SetFont($this->fontFamily, '', $this->fontSize."pt"); // support for japanese
437
438 $page_parts = $this->getParts();
439 // Print text using writeHTMLCell()
440 $pdf->AddPage();
441
442 // background image
443 if ($this->background_image != null) {
444 //$w_image = $this->orientation == "L" ? $this->size_height : $this->size_width;
445 //$h_image = $this->orientation == "L" ? $this->size_width : $this->size_height;
446 $w_image = $this->size_width;
447 $h_image = $this->size_height;
448 $pdf->SetAutoPageBreak(false, 0);
449 $bg_pos_x = 0;
450 $bg_pos_y = 0;
451 $bg_size_w = $w_image;
452 $bg_size_h = $h_image;
453 if (function_exists("getimagesize")){
454 $finfo = getimagesize($this->background_image);
455 //print_r($finfo);exit;
456 if (is_array($finfo) && count($finfo) > 1) {
457 $bg_size_w = $pdf->pixelsToUnits($finfo[0]);
458 $bg_size_h = $pdf->pixelsToUnits($finfo[1]);
459 }
460 $faktor = 1;
461 if ($bg_size_w > $w_image) {
462 $faktor = $bg_size_w / $w_image;
463 $bg_size_w = $w_image;
464 $bg_size_h /= $faktor;
465 }
466 if ($bg_size_h > $h_image) {
467 $faktor = $bg_size_h / $h_image;
468 $bg_size_h = $h_image;
469 $bg_size_w /= $faktor;
470 }
471 $bg_pos_x = ($w_image - $bg_size_w) / 2;
472 $bg_pos_y = ($h_image - $bg_size_h) / 2;
473 }
474 //$pdf->Image($this->background_image, $bg_pos_x, $bg_pos_y, $bg_size_w, $bg_size_h, '', '', '', false, 300, '', false, false, 1, 'CM');
475 $pdf->Image($this->background_image, $bg_pos_x, $bg_pos_y, $bg_size_w, $bg_size_h, '', '', '', false, 300, '', false, false, 0);
476 $pdf->SetAutoPageBreak(TRUE, 5);
477 $pdf->setPageMark();
478 }
479
480 // Build QR code inline - with fallback for FPDI versions that don't have serializeTCPDFtagParameters
481 // This can happen when another plugin loads setasign/fpdi via composer which overrides our bundled FPDI
482 $qr_code_inline = '';
483 $use_qrcode_fallback = false;
484 if (method_exists($pdf, 'serializeTCPDFtagParameters')) {
485 $qr_params = $pdf->serializeTCPDFtagParameters([$this->qr['text'], $this->qr['type'], '', '', $this->qr['size']['width'], $this->qr['size']['height'], $this->qr['style'], $this->qr['align']]);
486 $qr_code_inline = '<tcpdf method="write2DBarcode" params="'.$qr_params.'" />';
487 } else {
488 // Fallback: replace {QRCODE_INLINE} with marker, render QR code after HTML
489 $use_qrcode_fallback = true;
490 }
491 //$pdf->writeHTML(print_r($this->qr, true));
492
493 foreach($page_parts as $p) {
494
495 // Check if this part contains {QRCODE_INLINE} and we need fallback
496 $needs_qr_fallback = $use_qrcode_fallback && strpos($p, '{QRCODE_INLINE}') !== false;
497 $p = str_replace("{QRCODE_INLINE}", $qr_code_inline, $p);
498
499 try {
500 if ($p == "{PAGEBREAK}") {
501 $pdf->AddPage();
502 continue;
503 }
504 $teile = explode('{PAGEBREAK}', $p);
505 $counter = 0;
506 foreach($teile as $teil) {
507 $counter++;
508 if ($counter > 1) $pdf->AddPage();
509 if ($teil == "{QRCODE}") {
510 if (!empty($this->qr['text'])) {
511 $qr = $this->getDefaultQRValues();
512 $pdf->write2DBarcode($this->qr['text'], $this->qr['type'], $this->qr['pos']['x'], $this->qr['pos']['y'], $this->qr['size']['width'], $this->qr['size']['height'], $qr['style'], $qr['align']);
513 }
514 } else {
515 $pdf->writeHTML($teil, false, false, true, false, '');
516 // Fallback: render QR code after HTML if inline method not available
517 if ($needs_qr_fallback && !empty($this->qr['text'])) {
518 $qr = $this->getDefaultQRValues();
519 $pdf->write2DBarcode($this->qr['text'], $this->qr['type'], $this->qr['pos']['x'], $this->qr['pos']['y'], $this->qr['size']['width'], $this->qr['size']['height'], $qr['style'], $qr['align']);
520 $needs_qr_fallback = false; // Only render once
521 }
522 }
523 }
524 } catch(Exception $e) { }
525 }
526
527 $pdf->lastPage();
528 $pdf = $this->attachPDFs($pdf, $this->attach_pdfs);
529
530 $this->cleanOutputBuffer();
531 $this->outputPDF($pdf);
532 }
533
534 }
535 ?>