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