tcpdf_static.php 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639
  1. <?php
  2. //============================================================+
  3. // File name : tcpdf_static.php
  4. // Version : 1.1.4
  5. // Begin : 2002-08-03
  6. // Last Update : 2023-09-06
  7. // Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
  8. // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
  9. // -------------------------------------------------------------------
  10. // Copyright (C) 2002-2023 Nicola Asuni - Tecnick.com LTD
  11. //
  12. // This file is part of TCPDF software library.
  13. //
  14. // TCPDF is free software: you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as
  16. // published by the Free Software Foundation, either version 3 of the
  17. // License, or (at your option) any later version.
  18. //
  19. // TCPDF is distributed in the hope that it will be useful, but
  20. // WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. // See the GNU Lesser General Public License for more details.
  23. //
  24. // You should have received a copy of the License
  25. // along with TCPDF. If not, see
  26. // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
  27. //
  28. // See LICENSE.TXT file for more information.
  29. // -------------------------------------------------------------------
  30. //
  31. // Description :
  32. // Static methods used by the TCPDF class.
  33. //
  34. //============================================================+
  35. /**
  36. * @file
  37. * This is a PHP class that contains static methods for the TCPDF class.<br>
  38. * @package com.tecnick.tcpdf
  39. * @author Nicola Asuni
  40. * @version 1.1.2
  41. */
  42. /**
  43. * @class TCPDF_STATIC
  44. * Static methods used by the TCPDF class.
  45. * @package com.tecnick.tcpdf
  46. * @brief PHP class for generating PDF documents without requiring external extensions.
  47. * @version 1.1.1
  48. * @author Nicola Asuni - info@tecnick.com
  49. */
  50. class TCPDF_STATIC {
  51. /**
  52. * Current TCPDF version.
  53. * @private static
  54. */
  55. private static $tcpdf_version = '6.7.6';
  56. /**
  57. * String alias for total number of pages.
  58. * @public static
  59. */
  60. public static $alias_tot_pages = '{:ptp:}';
  61. /**
  62. * String alias for page number.
  63. * @public static
  64. */
  65. public static $alias_num_page = '{:pnp:}';
  66. /**
  67. * String alias for total number of pages in a single group.
  68. * @public static
  69. */
  70. public static $alias_group_tot_pages = '{:ptg:}';
  71. /**
  72. * String alias for group page number.
  73. * @public static
  74. */
  75. public static $alias_group_num_page = '{:png:}';
  76. /**
  77. * String alias for right shift compensation used to correctly align page numbers on the right.
  78. * @public static
  79. */
  80. public static $alias_right_shift = '{rsc:';
  81. /**
  82. * Encryption padding string.
  83. * @public static
  84. */
  85. public static $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
  86. /**
  87. * ByteRange placemark used during digital signature process.
  88. * @since 4.6.028 (2009-08-25)
  89. * @public static
  90. */
  91. public static $byterange_string = '/ByteRange[0 ********** ********** **********]';
  92. /**
  93. * Array page boxes names
  94. * @public static
  95. */
  96. public static $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox');
  97. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  98. /**
  99. * Return the current TCPDF version.
  100. * @return string TCPDF version string
  101. * @since 5.9.012 (2010-11-10)
  102. * @public static
  103. */
  104. public static function getTCPDFVersion() {
  105. return self::$tcpdf_version;
  106. }
  107. /**
  108. * Return the current TCPDF producer.
  109. * @return string TCPDF producer string
  110. * @since 6.0.000 (2013-03-16)
  111. * @public static
  112. */
  113. public static function getTCPDFProducer() {
  114. return "\x54\x43\x50\x44\x46\x20".self::getTCPDFVersion()."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
  115. }
  116. /**
  117. * Check if the URL exist.
  118. * @param string $url URL to check.
  119. * @return boolean true if the URl exist, false otherwise.
  120. * @since 5.9.204 (2013-01-28)
  121. * @public static
  122. */
  123. public static function isValidURL($url) {
  124. $headers = @get_headers($url);
  125. if ($headers === false) {
  126. return false;
  127. }
  128. return (strpos($headers[0], '200') !== false);
  129. }
  130. /**
  131. * Removes SHY characters from text.
  132. * Unicode Data:<ul>
  133. * <li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
  134. * <li>HTML Entity (decimal): "&amp;#173;"</li>
  135. * <li>HTML Entity (hex): "&amp;#xad;"</li>
  136. * <li>HTML Entity (named): "&amp;shy;"</li>
  137. * <li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
  138. * <li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
  139. * <li>UTF-8 character: chr(194).chr(173)</li>
  140. * </ul>
  141. * @param string $txt input string
  142. * @param boolean $unicode True if we are in unicode mode, false otherwise.
  143. * @return string without SHY characters.
  144. * @since (4.5.019) 2009-02-28
  145. * @public static
  146. */
  147. public static function removeSHY($txt='', $unicode=true) {
  148. $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt);
  149. if (!$unicode) {
  150. $txt = preg_replace('/([\\xad]{1})/', '', $txt);
  151. }
  152. return $txt;
  153. }
  154. /**
  155. * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)
  156. * @param string|array|int $brd Indicates if borders must be drawn around the cell block. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
  157. * @param string $position multicell position: 'start', 'middle', 'end'
  158. * @param boolean $opencell True when the cell is left open at the page bottom, false otherwise.
  159. * @return array border mode array
  160. * @since 4.4.002 (2008-12-09)
  161. * @public static
  162. */
  163. public static function getBorderMode($brd, $position='start', $opencell=true) {
  164. if ((!$opencell) OR empty($brd)) {
  165. return $brd;
  166. }
  167. if ($brd == 1) {
  168. $brd = 'LTRB';
  169. }
  170. if (is_string($brd)) {
  171. // convert string to array
  172. $slen = strlen($brd);
  173. $newbrd = array();
  174. for ($i = 0; $i < $slen; ++$i) {
  175. $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter');
  176. }
  177. $brd = $newbrd;
  178. }
  179. foreach ($brd as $border => $style) {
  180. switch ($position) {
  181. case 'start': {
  182. if (strpos($border, 'B') !== false) {
  183. // remove bottom line
  184. $newkey = str_replace('B', '', $border);
  185. if (strlen($newkey) > 0) {
  186. $brd[$newkey] = $style;
  187. }
  188. unset($brd[$border]);
  189. }
  190. break;
  191. }
  192. case 'middle': {
  193. if (strpos($border, 'B') !== false) {
  194. // remove bottom line
  195. $newkey = str_replace('B', '', $border);
  196. if (strlen($newkey) > 0) {
  197. $brd[$newkey] = $style;
  198. }
  199. unset($brd[$border]);
  200. $border = $newkey;
  201. }
  202. if (strpos($border, 'T') !== false) {
  203. // remove bottom line
  204. $newkey = str_replace('T', '', $border);
  205. if (strlen($newkey) > 0) {
  206. $brd[$newkey] = $style;
  207. }
  208. unset($brd[$border]);
  209. }
  210. break;
  211. }
  212. case 'end': {
  213. if (strpos($border, 'T') !== false) {
  214. // remove bottom line
  215. $newkey = str_replace('T', '', $border);
  216. if (strlen($newkey) > 0) {
  217. $brd[$newkey] = $style;
  218. }
  219. unset($brd[$border]);
  220. }
  221. break;
  222. }
  223. }
  224. }
  225. return $brd;
  226. }
  227. /**
  228. * Determine whether a string is empty.
  229. * @param string $str string to be checked
  230. * @return bool true if string is empty
  231. * @since 4.5.044 (2009-04-16)
  232. * @public static
  233. */
  234. public static function empty_string($str) {
  235. return (is_null($str) OR (is_string($str) AND (strlen($str) == 0)));
  236. }
  237. /**
  238. * Returns a temporary filename for caching object on filesystem.
  239. * @param string $type Type of file (name of the subdir on the tcpdf cache folder).
  240. * @param string $file_id TCPDF file_id.
  241. * @return string filename.
  242. * @since 4.5.000 (2008-12-31)
  243. * @public static
  244. */
  245. public static function getObjFilename($type='tmp', $file_id='') {
  246. return tempnam(K_PATH_CACHE, '__tcpdf_'.$file_id.'_'.$type.'_'.md5(TCPDF_STATIC::getRandomSeed()).'_');
  247. }
  248. /**
  249. * Add "\" before "\", "(" and ")"
  250. * @param string $s string to escape.
  251. * @return string escaped string.
  252. * @public static
  253. */
  254. public static function _escape($s) {
  255. // the chr(13) substitution fixes the Bugs item #1421290.
  256. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r'));
  257. }
  258. /**
  259. * Escape some special characters (&lt; &gt; &amp;) for XML output.
  260. * @param string $str Input string to convert.
  261. * @return string converted string
  262. * @since 5.9.121 (2011-09-28)
  263. * @public static
  264. */
  265. public static function _escapeXML($str) {
  266. $replaceTable = array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
  267. $str = strtr($str === null ? '' : $str, $replaceTable);
  268. return $str;
  269. }
  270. /**
  271. * Creates a copy of a class object
  272. * @param object $object class object to be cloned
  273. * @return object cloned object
  274. * @since 4.5.029 (2009-03-19)
  275. * @public static
  276. */
  277. public static function objclone($object) {
  278. if (($object instanceof Imagick) AND (version_compare(phpversion('imagick'), '3.0.1') !== 1)) {
  279. // on the versions after 3.0.1 the clone() method was deprecated in favour of clone keyword
  280. return @$object->clone();
  281. }
  282. return @clone($object);
  283. }
  284. /**
  285. * Output input data and compress it if possible.
  286. * @param string $data Data to output.
  287. * @param int $length Data length in bytes.
  288. * @since 5.9.086
  289. * @public static
  290. */
  291. public static function sendOutputData($data, $length) {
  292. if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) {
  293. // the content length may vary if the server is using compression
  294. header('Content-Length: '.$length);
  295. }
  296. echo $data;
  297. }
  298. /**
  299. * Replace page number aliases with number.
  300. * @param string $page Page content.
  301. * @param array $replace Array of replacements (array keys are replacement strings, values are alias arrays).
  302. * @param int $diff If passed, this will be set to the total char number difference between alias and replacements.
  303. * @return array replaced page content and updated $diff parameter as array.
  304. * @public static
  305. */
  306. public static function replacePageNumAliases($page, $replace, $diff=0) {
  307. foreach ($replace as $rep) {
  308. foreach ($rep[3] as $a) {
  309. if (strpos($page, $a) !== false) {
  310. $page = str_replace($a, $rep[0], $page);
  311. $diff += ($rep[2] - $rep[1]);
  312. }
  313. }
  314. }
  315. return array($page, $diff);
  316. }
  317. /**
  318. * Returns timestamp in seconds from formatted date-time.
  319. * @param string $date Formatted date-time.
  320. * @return int seconds.
  321. * @since 5.9.152 (2012-03-23)
  322. * @public static
  323. */
  324. public static function getTimestamp($date) {
  325. if (($date[0] == 'D') AND ($date[1] == ':')) {
  326. // remove date prefix if present
  327. $date = substr($date, 2);
  328. }
  329. return strtotime($date);
  330. }
  331. /**
  332. * Returns a formatted date-time.
  333. * @param int $time Time in seconds.
  334. * @return string escaped date string.
  335. * @since 5.9.152 (2012-03-23)
  336. * @public static
  337. */
  338. public static function getFormattedDate($time) {
  339. return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\'';
  340. }
  341. /**
  342. * Returns a string containing random data to be used as a seed for encryption methods.
  343. * @param string $seed starting seed value
  344. * @return string containing random data
  345. * @author Nicola Asuni
  346. * @since 5.9.006 (2010-10-19)
  347. * @public static
  348. */
  349. public static function getRandomSeed($seed='') {
  350. $rnd = uniqid(rand().microtime(true), true);
  351. if (function_exists('posix_getpid')) {
  352. $rnd .= posix_getpid();
  353. }
  354. if (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) {
  355. // this is not used on windows systems because it is very slow for a know bug
  356. $rnd .= openssl_random_pseudo_bytes(512);
  357. } else {
  358. for ($i = 0; $i < 23; ++$i) {
  359. $rnd .= uniqid('', true);
  360. }
  361. }
  362. return $rnd.$seed.__FILE__.serialize($_SERVER).microtime(true);
  363. }
  364. /**
  365. * Encrypts a string using MD5 and returns it's value as a binary string.
  366. * @param string $str input string
  367. * @return string MD5 encrypted binary string
  368. * @since 2.0.000 (2008-01-02)
  369. * @public static
  370. */
  371. public static function _md5_16($str) {
  372. return pack('H*', md5($str));
  373. }
  374. /**
  375. * Returns the input text encrypted using AES algorithm and the specified key.
  376. * This method requires openssl or mcrypt. Text is padded to 16bytes blocks
  377. * @param string $key encryption key
  378. * @param string $text input text to be encrypted
  379. * @return string encrypted text
  380. * @author Nicola Asuni
  381. * @since 5.0.005 (2010-05-11)
  382. * @public static
  383. */
  384. public static function _AES($key, $text) {
  385. // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0)
  386. $padding = 16 - (strlen($text) % 16);
  387. $text .= str_repeat(chr($padding), $padding);
  388. if (extension_loaded('openssl')) {
  389. $algo = 'aes-256-cbc';
  390. if (strlen($key) == 16) {
  391. $algo = 'aes-128-cbc';
  392. }
  393. $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($algo));
  394. $text = openssl_encrypt($text, $algo, $key, OPENSSL_RAW_DATA, $iv);
  395. return $iv.substr($text, 0, -16);
  396. }
  397. $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
  398. $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
  399. $text = $iv.$text;
  400. return $text;
  401. }
  402. /**
  403. * Returns the input text encrypted using AES algorithm and the specified key.
  404. * This method requires openssl or mcrypt. Text is not padded
  405. * @param string $key encryption key
  406. * @param string $text input text to be encrypted
  407. * @return string encrypted text
  408. * @author Nicola Asuni
  409. * @since TODO
  410. * @public static
  411. */
  412. public static function _AESnopad($key, $text) {
  413. if (extension_loaded('openssl')) {
  414. $algo = 'aes-256-cbc';
  415. if (strlen($key) == 16) {
  416. $algo = 'aes-128-cbc';
  417. }
  418. $iv = str_repeat("\x00", openssl_cipher_iv_length($algo));
  419. $text = openssl_encrypt($text, $algo, $key, OPENSSL_RAW_DATA, $iv);
  420. return substr($text, 0, -16);
  421. }
  422. $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  423. $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
  424. return $text;
  425. }
  426. /**
  427. * Returns the input text encrypted using RC4 algorithm and the specified key.
  428. * RC4 is the standard encryption algorithm used in PDF format
  429. * @param string $key Encryption key.
  430. * @param string $text Input text to be encrypted.
  431. * @param string $last_enc_key Reference to last RC4 key encrypted.
  432. * @param string $last_enc_key_c Reference to last RC4 computed key.
  433. * @return string encrypted text
  434. * @since 2.0.000 (2008-01-02)
  435. * @author Klemen Vodopivec, Nicola Asuni
  436. * @public static
  437. */
  438. public static function _RC4($key, $text, &$last_enc_key, &$last_enc_key_c) {
  439. if (function_exists('mcrypt_encrypt') AND ($out = @mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) {
  440. // try to use mcrypt function if exist
  441. return $out;
  442. }
  443. if ($last_enc_key != $key) {
  444. $k = str_repeat($key, (int) ((256 / strlen($key)) + 1));
  445. $rc4 = range(0, 255);
  446. $j = 0;
  447. for ($i = 0; $i < 256; ++$i) {
  448. $t = $rc4[$i];
  449. $j = ($j + $t + ord($k[$i])) % 256;
  450. $rc4[$i] = $rc4[$j];
  451. $rc4[$j] = $t;
  452. }
  453. $last_enc_key = $key;
  454. $last_enc_key_c = $rc4;
  455. } else {
  456. $rc4 = $last_enc_key_c;
  457. }
  458. $len = strlen($text);
  459. $a = 0;
  460. $b = 0;
  461. $out = '';
  462. for ($i = 0; $i < $len; ++$i) {
  463. $a = ($a + 1) % 256;
  464. $t = $rc4[$a];
  465. $b = ($b + $t) % 256;
  466. $rc4[$a] = $rc4[$b];
  467. $rc4[$b] = $t;
  468. $k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
  469. $out .= chr(ord($text[$i]) ^ $k);
  470. }
  471. return $out;
  472. }
  473. /**
  474. * Return the permission code used on encryption (P value).
  475. * @param array $permissions the set of permissions (specify the ones you want to block).
  476. * @param int $mode encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
  477. * @since 5.0.005 (2010-05-12)
  478. * @author Nicola Asuni
  479. * @public static
  480. */
  481. public static function getUserPermissionCode($permissions, $mode=0) {
  482. $options = array(
  483. 'owner' => 2, // bit 2 -- inverted logic: cleared by default
  484. 'print' => 4, // bit 3
  485. 'modify' => 8, // bit 4
  486. 'copy' => 16, // bit 5
  487. 'annot-forms' => 32, // bit 6
  488. 'fill-forms' => 256, // bit 9
  489. 'extract' => 512, // bit 10
  490. 'assemble' => 1024,// bit 11
  491. 'print-high' => 2048 // bit 12
  492. );
  493. $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100)
  494. foreach ($permissions as $permission) {
  495. if (isset($options[$permission])) {
  496. if (($mode > 0) OR ($options[$permission] <= 32)) {
  497. // set only valid permissions
  498. if ($options[$permission] == 2) {
  499. // the logic for bit 2 is inverted (cleared by default)
  500. $protection += $options[$permission];
  501. } else {
  502. $protection -= $options[$permission];
  503. }
  504. }
  505. }
  506. }
  507. return $protection;
  508. }
  509. /**
  510. * Convert hexadecimal string to string
  511. * @param string $bs byte-string to convert
  512. * @return string
  513. * @since 5.0.005 (2010-05-12)
  514. * @author Nicola Asuni
  515. * @public static
  516. */
  517. public static function convertHexStringToString($bs) {
  518. $string = ''; // string to be returned
  519. $bslength = strlen($bs);
  520. if (($bslength % 2) != 0) {
  521. // padding
  522. $bs .= '0';
  523. ++$bslength;
  524. }
  525. for ($i = 0; $i < $bslength; $i += 2) {
  526. $string .= chr(hexdec($bs[$i].$bs[($i + 1)]));
  527. }
  528. return $string;
  529. }
  530. /**
  531. * Convert string to hexadecimal string (byte string)
  532. * @param string $s string to convert
  533. * @return string byte string
  534. * @since 5.0.010 (2010-05-17)
  535. * @author Nicola Asuni
  536. * @public static
  537. */
  538. public static function convertStringToHexString($s) {
  539. $bs = '';
  540. $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);
  541. foreach ($chars as $c) {
  542. $bs .= sprintf('%02s', dechex(ord($c)));
  543. }
  544. return $bs;
  545. }
  546. /**
  547. * Convert encryption P value to a string of bytes, low-order byte first.
  548. * @param string $protection 32bit encryption permission value (P value)
  549. * @return string
  550. * @since 5.0.005 (2010-05-12)
  551. * @author Nicola Asuni
  552. * @public static
  553. */
  554. public static function getEncPermissionsString($protection) {
  555. $binprot = sprintf('%032b', $protection);
  556. $str = chr(bindec(substr($binprot, 24, 8)));
  557. $str .= chr(bindec(substr($binprot, 16, 8)));
  558. $str .= chr(bindec(substr($binprot, 8, 8)));
  559. $str .= chr(bindec(substr($binprot, 0, 8)));
  560. return $str;
  561. }
  562. /**
  563. * Encode a name object.
  564. * @param string $name Name object to encode.
  565. * @return string Encoded name object.
  566. * @author Nicola Asuni
  567. * @since 5.9.097 (2011-06-23)
  568. * @public static
  569. */
  570. public static function encodeNameObject($name) {
  571. $escname = '';
  572. $length = strlen($name);
  573. for ($i = 0; $i < $length; ++$i) {
  574. $chr = $name[$i];
  575. if (preg_match('/[0-9a-zA-Z#_=-]/', $chr) == 1) {
  576. $escname .= $chr;
  577. } else {
  578. $escname .= sprintf('#%02X', ord($chr));
  579. }
  580. }
  581. return $escname;
  582. }
  583. /**
  584. * Convert JavaScript form fields properties array to Annotation Properties array.
  585. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
  586. * @param array $spot_colors Reference to spot colors array.
  587. * @param boolean $rtl True if in Right-To-Left text direction mode, false otherwise.
  588. * @return array of annotation properties
  589. * @author Nicola Asuni
  590. * @since 4.8.000 (2009-09-06)
  591. * @public static
  592. */
  593. public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false) {
  594. if (isset($prop['aopt']) AND is_array($prop['aopt'])) {
  595. // the annotation options are already defined
  596. return $prop['aopt'];
  597. }
  598. $opt = array(); // value to be returned
  599. // alignment: Controls how the text is laid out within the text field.
  600. if (isset($prop['alignment'])) {
  601. switch ($prop['alignment']) {
  602. case 'left': {
  603. $opt['q'] = 0;
  604. break;
  605. }
  606. case 'center': {
  607. $opt['q'] = 1;
  608. break;
  609. }
  610. case 'right': {
  611. $opt['q'] = 2;
  612. break;
  613. }
  614. default: {
  615. $opt['q'] = ($rtl)?2:0;
  616. break;
  617. }
  618. }
  619. }
  620. // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle.
  621. if (isset($prop['lineWidth'])) {
  622. $linewidth = intval($prop['lineWidth']);
  623. } else {
  624. $linewidth = 1;
  625. }
  626. // borderStyle: The border style for a field.
  627. if (isset($prop['borderStyle'])) {
  628. switch ($prop['borderStyle']) {
  629. case 'border.d':
  630. case 'dashed': {
  631. $opt['border'] = array(0, 0, $linewidth, array(3, 2));
  632. $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2));
  633. break;
  634. }
  635. case 'border.b':
  636. case 'beveled': {
  637. $opt['border'] = array(0, 0, $linewidth);
  638. $opt['bs'] = array('w'=>$linewidth, 's'=>'B');
  639. break;
  640. }
  641. case 'border.i':
  642. case 'inset': {
  643. $opt['border'] = array(0, 0, $linewidth);
  644. $opt['bs'] = array('w'=>$linewidth, 's'=>'I');
  645. break;
  646. }
  647. case 'border.u':
  648. case 'underline': {
  649. $opt['border'] = array(0, 0, $linewidth);
  650. $opt['bs'] = array('w'=>$linewidth, 's'=>'U');
  651. break;
  652. }
  653. case 'border.s':
  654. case 'solid': {
  655. $opt['border'] = array(0, 0, $linewidth);
  656. $opt['bs'] = array('w'=>$linewidth, 's'=>'S');
  657. break;
  658. }
  659. default: {
  660. break;
  661. }
  662. }
  663. }
  664. if (isset($prop['border']) AND is_array($prop['border'])) {
  665. $opt['border'] = $prop['border'];
  666. }
  667. if (!isset($opt['mk'])) {
  668. $opt['mk'] = array();
  669. }
  670. if (!isset($opt['mk']['if'])) {
  671. $opt['mk']['if'] = array();
  672. }
  673. $opt['mk']['if']['a'] = array(0.5, 0.5);
  674. // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon.
  675. if (isset($prop['buttonAlignX'])) {
  676. $opt['mk']['if']['a'][0] = $prop['buttonAlignX'];
  677. }
  678. // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon.
  679. if (isset($prop['buttonAlignY'])) {
  680. $opt['mk']['if']['a'][1] = $prop['buttonAlignY'];
  681. }
  682. // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field.
  683. if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) {
  684. $opt['mk']['if']['fb'] = true;
  685. }
  686. // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face.
  687. if (isset($prop['buttonScaleHow'])) {
  688. switch ($prop['buttonScaleHow']) {
  689. case 'scaleHow.proportional': {
  690. $opt['mk']['if']['s'] = 'P';
  691. break;
  692. }
  693. case 'scaleHow.anamorphic': {
  694. $opt['mk']['if']['s'] = 'A';
  695. break;
  696. }
  697. }
  698. }
  699. // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face.
  700. if (isset($prop['buttonScaleWhen'])) {
  701. switch ($prop['buttonScaleWhen']) {
  702. case 'scaleWhen.always': {
  703. $opt['mk']['if']['sw'] = 'A';
  704. break;
  705. }
  706. case 'scaleWhen.never': {
  707. $opt['mk']['if']['sw'] = 'N';
  708. break;
  709. }
  710. case 'scaleWhen.tooBig': {
  711. $opt['mk']['if']['sw'] = 'B';
  712. break;
  713. }
  714. case 'scaleWhen.tooSmall': {
  715. $opt['mk']['if']['sw'] = 'S';
  716. break;
  717. }
  718. }
  719. }
  720. // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face.
  721. if (isset($prop['buttonPosition'])) {
  722. switch ($prop['buttonPosition']) {
  723. case 0:
  724. case 'position.textOnly': {
  725. $opt['mk']['tp'] = 0;
  726. break;
  727. }
  728. case 1:
  729. case 'position.iconOnly': {
  730. $opt['mk']['tp'] = 1;
  731. break;
  732. }
  733. case 2:
  734. case 'position.iconTextV': {
  735. $opt['mk']['tp'] = 2;
  736. break;
  737. }
  738. case 3:
  739. case 'position.textIconV': {
  740. $opt['mk']['tp'] = 3;
  741. break;
  742. }
  743. case 4:
  744. case 'position.iconTextH': {
  745. $opt['mk']['tp'] = 4;
  746. break;
  747. }
  748. case 5:
  749. case 'position.textIconH': {
  750. $opt['mk']['tp'] = 5;
  751. break;
  752. }
  753. case 6:
  754. case 'position.overlay': {
  755. $opt['mk']['tp'] = 6;
  756. break;
  757. }
  758. }
  759. }
  760. // fillColor: Specifies the background color for a field.
  761. if (isset($prop['fillColor'])) {
  762. if (is_array($prop['fillColor'])) {
  763. $opt['mk']['bg'] = $prop['fillColor'];
  764. } else {
  765. $opt['mk']['bg'] = TCPDF_COLORS::convertHTMLColorToDec($prop['fillColor'], $spot_colors);
  766. }
  767. }
  768. // strokeColor: Specifies the stroke color for a field that is used to stroke the rectangle of the field with a line as large as the line width.
  769. if (isset($prop['strokeColor'])) {
  770. if (is_array($prop['strokeColor'])) {
  771. $opt['mk']['bc'] = $prop['strokeColor'];
  772. } else {
  773. $opt['mk']['bc'] = TCPDF_COLORS::convertHTMLColorToDec($prop['strokeColor'], $spot_colors);
  774. }
  775. }
  776. // rotation: The rotation of a widget in counterclockwise increments.
  777. if (isset($prop['rotation'])) {
  778. $opt['mk']['r'] = $prop['rotation'];
  779. }
  780. // charLimit: Limits the number of characters that a user can type into a text field.
  781. if (isset($prop['charLimit'])) {
  782. $opt['maxlen'] = intval($prop['charLimit']);
  783. }
  784. $ff = 0;
  785. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  786. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
  787. $ff += 1 << 0;
  788. }
  789. // required: Specifies whether a field requires a value.
  790. if (isset($prop['required']) AND ($prop['required'] == 'true')) {
  791. $ff += 1 << 1;
  792. }
  793. // multiline: Controls how text is wrapped within the field.
  794. if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) {
  795. $ff += 1 << 12;
  796. }
  797. // password: Specifies whether the field should display asterisks when data is entered in the field.
  798. if (isset($prop['password']) AND ($prop['password'] == 'true')) {
  799. $ff += 1 << 13;
  800. }
  801. // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect.
  802. if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) {
  803. $ff += 1 << 14;
  804. }
  805. // Radio: If set, the field is a set of radio buttons.
  806. if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) {
  807. $ff += 1 << 15;
  808. }
  809. // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value.
  810. if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) {
  811. $ff += 1 << 16;
  812. }
  813. // Combo: If set, the field is a combo box; if clear, the field is a list box.
  814. if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) {
  815. $ff += 1 << 17;
  816. }
  817. // editable: Controls whether a combo box is editable.
  818. if (isset($prop['editable']) AND ($prop['editable'] == 'true')) {
  819. $ff += 1 << 18;
  820. }
  821. // Sort: If set, the field's option items shall be sorted alphabetically.
  822. if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) {
  823. $ff += 1 << 19;
  824. }
  825. // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection).
  826. if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) {
  827. $ff += 1 << 20;
  828. }
  829. // multipleSelection: If true, indicates that a list box allows a multiple selection of items.
  830. if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) {
  831. $ff += 1 << 21;
  832. }
  833. // doNotSpellCheck: If true, spell checking is not performed on this editable text field.
  834. if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) {
  835. $ff += 1 << 22;
  836. }
  837. // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field.
  838. if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) {
  839. $ff += 1 << 23;
  840. }
  841. // comb: If set to true, the field background is drawn as series of boxes (one for each character in the value of the field) and each character of the content is drawn within those boxes. The number of boxes drawn is determined from the charLimit property. It applies only to text fields. The setter will also raise if any of the following field properties are also set multiline, password, and fileSelect. A side-effect of setting this property is that the doNotScroll property is also set.
  842. if (isset($prop['comb']) AND ($prop['comb'] == 'true')) {
  843. $ff += 1 << 24;
  844. }
  845. // radiosInUnison: If false, even if a group of radio buttons have the same name and export value, they behave in a mutually exclusive fashion, like HTML radio buttons.
  846. if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) {
  847. $ff += 1 << 25;
  848. }
  849. // richText: If true, the field allows rich text formatting.
  850. if (isset($prop['richText']) AND ($prop['richText'] == 'true')) {
  851. $ff += 1 << 25;
  852. }
  853. // commitOnSelChange: Controls whether a field value is committed after a selection change.
  854. if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) {
  855. $ff += 1 << 26;
  856. }
  857. $opt['ff'] = $ff;
  858. // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset.
  859. if (isset($prop['defaultValue'])) {
  860. $opt['dv'] = $prop['defaultValue'];
  861. }
  862. $f = 4; // default value for annotation flags
  863. // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
  864. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) {
  865. $f += 1 << 6;
  866. }
  867. // display: Controls whether the field is hidden or visible on screen and in print.
  868. if (isset($prop['display'])) {
  869. if ($prop['display'] == 'display.visible') {
  870. //
  871. } elseif ($prop['display'] == 'display.hidden') {
  872. $f += 1 << 1;
  873. } elseif ($prop['display'] == 'display.noPrint') {
  874. $f -= 1 << 2;
  875. } elseif ($prop['display'] == 'display.noView') {
  876. $f += 1 << 5;
  877. }
  878. }
  879. $opt['f'] = $f;
  880. // currentValueIndices: Reads and writes single or multiple values of a list box or combo box.
  881. if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) {
  882. $opt['i'] = $prop['currentValueIndices'];
  883. }
  884. // value: The value of the field data that the user has entered.
  885. if (isset($prop['value'])) {
  886. if (is_array($prop['value'])) {
  887. $opt['opt'] = array();
  888. foreach ($prop['value'] AS $key => $optval) {
  889. // exportValues: An array of strings representing the export values for the field.
  890. if (isset($prop['exportValues'][$key])) {
  891. $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]);
  892. } else {
  893. $opt['opt'][$key] = $prop['value'][$key];
  894. }
  895. }
  896. } else {
  897. $opt['v'] = $prop['value'];
  898. }
  899. }
  900. // richValue: This property specifies the text contents and formatting of a rich text field.
  901. if (isset($prop['richValue'])) {
  902. $opt['rv'] = $prop['richValue'];
  903. }
  904. // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded).
  905. if (isset($prop['submitName'])) {
  906. $opt['tm'] = $prop['submitName'];
  907. }
  908. // name: Fully qualified field name.
  909. if (isset($prop['name'])) {
  910. $opt['t'] = $prop['name'];
  911. }
  912. // userName: The user name (short description string) of the field.
  913. if (isset($prop['userName'])) {
  914. $opt['tu'] = $prop['userName'];
  915. }
  916. // highlight: Defines how a button reacts when a user clicks it.
  917. if (isset($prop['highlight'])) {
  918. switch ($prop['highlight']) {
  919. case 'none':
  920. case 'highlight.n': {
  921. $opt['h'] = 'N';
  922. break;
  923. }
  924. case 'invert':
  925. case 'highlight.i': {
  926. $opt['h'] = 'i';
  927. break;
  928. }
  929. case 'push':
  930. case 'highlight.p': {
  931. $opt['h'] = 'P';
  932. break;
  933. }
  934. case 'outline':
  935. case 'highlight.o': {
  936. $opt['h'] = 'O';
  937. break;
  938. }
  939. }
  940. }
  941. // Unsupported options:
  942. // - calcOrderIndex: Changes the calculation order of fields in the document.
  943. // - delay: Delays the redrawing of a field's appearance.
  944. // - defaultStyle: This property defines the default style attributes for the form field.
  945. // - style: Allows the user to set the glyph style of a check box or radio button.
  946. // - textColor, textFont, textSize
  947. return $opt;
  948. }
  949. /**
  950. * Format the page numbers.
  951. * This method can be overridden for custom formats.
  952. * @param int $num page number
  953. * @return string
  954. * @since 4.2.005 (2008-11-06)
  955. * @public static
  956. */
  957. public static function formatPageNumber($num) {
  958. return number_format((float)$num, 0, '', '.');
  959. }
  960. /**
  961. * Format the page numbers on the Table Of Content.
  962. * This method can be overridden for custom formats.
  963. * @param int $num page number
  964. * @return string
  965. * @since 4.5.001 (2009-01-04)
  966. * @see addTOC(), addHTMLTOC()
  967. * @public static
  968. */
  969. public static function formatTOCPageNumber($num) {
  970. return number_format((float)$num, 0, '', '.');
  971. }
  972. /**
  973. * Extracts the CSS properties from a CSS string.
  974. * @param string $cssdata string containing CSS definitions.
  975. * @return array An array where the keys are the CSS selectors and the values are the CSS properties.
  976. * @author Nicola Asuni
  977. * @since 5.1.000 (2010-05-25)
  978. * @public static
  979. */
  980. public static function extractCSSproperties($cssdata) {
  981. if (empty($cssdata)) {
  982. return array();
  983. }
  984. // remove comments
  985. $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata);
  986. // remove newlines and multiple spaces
  987. $cssdata = preg_replace('/[\s]+/', ' ', $cssdata);
  988. // remove some spaces
  989. $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata);
  990. // remove empty blocks
  991. $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata);
  992. // replace media type parenthesis
  993. $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata);
  994. $cssdata = preg_replace('/\}\}/si', '}§', $cssdata);
  995. // trim string
  996. $cssdata = trim($cssdata);
  997. // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv)
  998. $cssblocks = array();
  999. $matches = array();
  1000. if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) {
  1001. foreach ($matches[1] as $key => $type) {
  1002. $cssblocks[$type] = $matches[2][$key];
  1003. }
  1004. // remove media blocks
  1005. $cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata);
  1006. }
  1007. // keep 'all' and 'print' media, other media types are discarded
  1008. if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) {
  1009. $cssdata .= $cssblocks['all'];
  1010. }
  1011. if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) {
  1012. $cssdata .= $cssblocks['print'];
  1013. }
  1014. // reset css blocks array
  1015. $cssblocks = array();
  1016. $matches = array();
  1017. // explode css data string into array
  1018. if (substr($cssdata, -1) == '}') {
  1019. // remove last parethesis
  1020. $cssdata = substr($cssdata, 0, -1);
  1021. }
  1022. $matches = explode('}', $cssdata);
  1023. foreach ($matches as $key => $block) {
  1024. // index 0 contains the CSS selector, index 1 contains CSS properties
  1025. $cssblocks[$key] = explode('{', $block);
  1026. if (!isset($cssblocks[$key][1])) {
  1027. // remove empty definitions
  1028. unset($cssblocks[$key]);
  1029. }
  1030. }
  1031. // split groups of selectors (comma-separated list of selectors)
  1032. foreach ($cssblocks as $key => $block) {
  1033. if (strpos($block[0], ',') > 0) {
  1034. $selectors = explode(',', $block[0]);
  1035. foreach ($selectors as $sel) {
  1036. $cssblocks[] = array(0 => trim($sel), 1 => $block[1]);
  1037. }
  1038. unset($cssblocks[$key]);
  1039. }
  1040. }
  1041. // covert array to selector => properties
  1042. $cssdata = array();
  1043. foreach ($cssblocks as $block) {
  1044. $selector = $block[0];
  1045. // calculate selector's specificity
  1046. $matches = array();
  1047. $a = 0; // the declaration is not from is a 'style' attribute
  1048. $b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes
  1049. $c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes
  1050. $c += intval(preg_match_all('/[\:]link|visited|hover|active|focus|target|lang|enabled|disabled|checked|indeterminate|root|nth|first|last|only|empty|contains|not/i', $selector, $matches)); // number of pseudo-classes
  1051. $d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches)); // number of element names
  1052. $d += intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements
  1053. $specificity = $a.$b.$c.$d;
  1054. // add specificity to the beginning of the selector
  1055. $cssdata[$specificity.' '.$selector] = $block[1];
  1056. }
  1057. // sort selectors alphabetically to account for specificity
  1058. ksort($cssdata, SORT_STRING);
  1059. // return array
  1060. return $cssdata;
  1061. }
  1062. /**
  1063. * Cleanup HTML code (requires HTML Tidy library).
  1064. * @param string $html htmlcode to fix
  1065. * @param string $default_css CSS commands to add
  1066. * @param array|null $tagvs parameters for setHtmlVSpace method
  1067. * @param array|null $tidy_options options for tidy_parse_string function
  1068. * @param array $tagvspaces Array of vertical spaces for tags.
  1069. * @return string XHTML code cleaned up
  1070. * @author Nicola Asuni
  1071. * @since 5.9.017 (2010-11-16)
  1072. * @see setHtmlVSpace()
  1073. * @public static
  1074. */
  1075. public static function fixHTMLCode($html, $default_css, $tagvs, $tidy_options, &$tagvspaces) {
  1076. // configure parameters for HTML Tidy
  1077. if (TCPDF_STATIC::empty_string($tidy_options)) {
  1078. $tidy_options = array (
  1079. 'clean' => 1,
  1080. 'drop-empty-paras' => 0,
  1081. 'drop-proprietary-attributes' => 1,
  1082. 'fix-backslash' => 1,
  1083. 'hide-comments' => 1,
  1084. 'join-styles' => 1,
  1085. 'lower-literals' => 1,
  1086. 'merge-divs' => 1,
  1087. 'merge-spans' => 1,
  1088. 'output-xhtml' => 1,
  1089. 'word-2000' => 1,
  1090. 'wrap' => 0,
  1091. 'output-bom' => 0,
  1092. //'char-encoding' => 'utf8',
  1093. //'input-encoding' => 'utf8',
  1094. //'output-encoding' => 'utf8'
  1095. );
  1096. }
  1097. // clean up the HTML code
  1098. $tidy = tidy_parse_string($html, $tidy_options);
  1099. // fix the HTML
  1100. $tidy->cleanRepair();
  1101. // get the CSS part
  1102. $tidy_head = tidy_get_head($tidy);
  1103. $css = $tidy_head->value;
  1104. $css = preg_replace('/<style([^>]+)>/ims', '<style>', $css);
  1105. $css = preg_replace('/<\/style>(.*)<style>/ims', "\n", $css);
  1106. $css = str_replace('/*<![CDATA[*/', '', $css);
  1107. $css = str_replace('/*]]>*/', '', $css);
  1108. preg_match('/<style>(.*)<\/style>/ims', $css, $matches);
  1109. if (isset($matches[1])) {
  1110. $css = strtolower($matches[1]);
  1111. } else {
  1112. $css = '';
  1113. }
  1114. // include default css
  1115. $css = '<style>'.$default_css.$css.'</style>';
  1116. // get the body part
  1117. $tidy_body = tidy_get_body($tidy);
  1118. $html = $tidy_body->value;
  1119. // fix some self-closing tags
  1120. $html = str_replace('<br>', '<br />', $html);
  1121. // remove some empty tag blocks
  1122. $html = preg_replace('/<div([^\>]*)><\/div>/', '', $html);
  1123. $html = preg_replace('/<p([^\>]*)><\/p>/', '', $html);
  1124. if (!TCPDF_STATIC::empty_string($tagvs)) {
  1125. // set vertical space for some XHTML tags
  1126. $tagvspaces = $tagvs;
  1127. }
  1128. // return the cleaned XHTML code + CSS
  1129. return $css.$html;
  1130. }
  1131. /**
  1132. * Returns true if the CSS selector is valid for the selected HTML tag
  1133. * @param array $dom array of HTML tags and properties
  1134. * @param int $key key of the current HTML tag
  1135. * @param string $selector CSS selector string
  1136. * @return true if the selector is valid, false otherwise
  1137. * @since 5.1.000 (2010-05-25)
  1138. * @public static
  1139. */
  1140. public static function isValidCSSSelectorForTag($dom, $key, $selector) {
  1141. $valid = false; // value to be returned
  1142. $tag = $dom[$key]['value'];
  1143. $class = array();
  1144. if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) {
  1145. $class = explode(' ', strtolower($dom[$key]['attribute']['class']));
  1146. }
  1147. $id = '';
  1148. if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) {
  1149. $id = strtolower($dom[$key]['attribute']['id']);
  1150. }
  1151. $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector);
  1152. $matches = array();
  1153. if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) {
  1154. $parentop = array_pop($matches[1]);
  1155. $operator = $parentop[0];
  1156. $offset = $parentop[1];
  1157. $lasttag = array_pop($matches[2]);
  1158. $lasttag = strtolower(trim($lasttag[0]));
  1159. if (($lasttag == '*') OR ($lasttag == $tag)) {
  1160. // the last element on selector is our tag or 'any tag'
  1161. $attrib = array_pop($matches[3]);
  1162. $attrib = strtolower(trim($attrib[0]));
  1163. if (!empty($attrib)) {
  1164. // check if matches class, id, attribute, pseudo-class or pseudo-element
  1165. switch ($attrib[0]) {
  1166. case '.': { // class
  1167. if (in_array(substr($attrib, 1), $class)) {
  1168. $valid = true;
  1169. }
  1170. break;
  1171. }
  1172. case '#': { // ID
  1173. if (substr($attrib, 1) == $id) {
  1174. $valid = true;
  1175. }
  1176. break;
  1177. }
  1178. case '[': { // attribute
  1179. $attrmatch = array();
  1180. if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) {
  1181. $att = strtolower($attrmatch[1]);
  1182. $val = $attrmatch[3];
  1183. if (isset($dom[$key]['attribute'][$att])) {
  1184. switch ($attrmatch[2]) {
  1185. case '=': {
  1186. if ($dom[$key]['attribute'][$att] == $val) {
  1187. $valid = true;
  1188. }
  1189. break;
  1190. }
  1191. case '~=': {
  1192. if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) {
  1193. $valid = true;
  1194. }
  1195. break;
  1196. }
  1197. case '^=': {
  1198. if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) {
  1199. $valid = true;
  1200. }
  1201. break;
  1202. }
  1203. case '$=': {
  1204. if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) {
  1205. $valid = true;
  1206. }
  1207. break;
  1208. }
  1209. case '*=': {
  1210. if (strpos($dom[$key]['attribute'][$att], $val) !== false) {
  1211. $valid = true;
  1212. }
  1213. break;
  1214. }
  1215. case '|=': {
  1216. if ($dom[$key]['attribute'][$att] == $val) {
  1217. $valid = true;
  1218. } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) {
  1219. $valid = true;
  1220. }
  1221. break;
  1222. }
  1223. default: {
  1224. $valid = true;
  1225. }
  1226. }
  1227. }
  1228. }
  1229. break;
  1230. }
  1231. case ':': { // pseudo-class or pseudo-element
  1232. if ($attrib[1] == ':') { // pseudo-element
  1233. // pseudo-elements are not supported!
  1234. // (::first-line, ::first-letter, ::before, ::after)
  1235. } else { // pseudo-class
  1236. // pseudo-classes are not supported!
  1237. // (:root, :nth-child(n), :nth-last-child(n), :nth-of-type(n), :nth-last-of-type(n), :first-child, :last-child, :first-of-type, :last-of-type, :only-child, :only-of-type, :empty, :link, :visited, :active, :hover, :focus, :target, :lang(fr), :enabled, :disabled, :checked)
  1238. }
  1239. break;
  1240. }
  1241. } // end of switch
  1242. } else {
  1243. $valid = true;
  1244. }
  1245. if ($valid AND ($offset > 0)) {
  1246. $valid = false;
  1247. // check remaining selector part
  1248. $selector = substr($selector, 0, $offset);
  1249. switch ($operator) {
  1250. case ' ': { // descendant of an element
  1251. while ($dom[$key]['parent'] > 0) {
  1252. if (self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) {
  1253. $valid = true;
  1254. break;
  1255. } else {
  1256. $key = $dom[$key]['parent'];
  1257. }
  1258. }
  1259. break;
  1260. }
  1261. case '>': { // child of an element
  1262. $valid = self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector);
  1263. break;
  1264. }
  1265. case '+': { // immediately preceded by an element
  1266. for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
  1267. if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
  1268. $valid = self::isValidCSSSelectorForTag($dom, $i, $selector);
  1269. break;
  1270. }
  1271. }
  1272. break;
  1273. }
  1274. case '~': { // preceded by an element
  1275. for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) {
  1276. if ($dom[$i]['tag'] AND $dom[$i]['opening']) {
  1277. if (self::isValidCSSSelectorForTag($dom, $i, $selector)) {
  1278. break;
  1279. }
  1280. }
  1281. }
  1282. break;
  1283. }
  1284. }
  1285. }
  1286. }
  1287. }
  1288. return $valid;
  1289. }
  1290. /**
  1291. * Returns the styles array that apply for the selected HTML tag.
  1292. * @param array $dom array of HTML tags and properties
  1293. * @param int $key key of the current HTML tag
  1294. * @param array $css array of CSS properties
  1295. * @return array containing CSS properties
  1296. * @since 5.1.000 (2010-05-25)
  1297. * @public static
  1298. */
  1299. public static function getCSSdataArray($dom, $key, $css) {
  1300. $cssarray = array(); // style to be returned
  1301. // get parent CSS selectors
  1302. $selectors = array();
  1303. if (isset($dom[($dom[$key]['parent'])]['csssel'])) {
  1304. $selectors = $dom[($dom[$key]['parent'])]['csssel'];
  1305. }
  1306. // get all styles that apply
  1307. foreach($css as $selector => $style) {
  1308. $pos = strpos($selector, ' ');
  1309. // get specificity
  1310. $specificity = substr($selector, 0, $pos);
  1311. // remove specificity
  1312. $selector = substr($selector, $pos);
  1313. // check if this selector apply to current tag
  1314. if (self::isValidCSSSelectorForTag($dom, $key, $selector)) {
  1315. if (!in_array($selector, $selectors)) {
  1316. // add style if not already added on parent selector
  1317. $cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style);
  1318. $selectors[] = $selector;
  1319. }
  1320. }
  1321. }
  1322. if (isset($dom[$key]['attribute']['style'])) {
  1323. // attach inline style (latest properties have high priority)
  1324. $cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']);
  1325. }
  1326. // order the css array to account for specificity
  1327. $cssordered = array();
  1328. foreach ($cssarray as $key => $val) {
  1329. $skey = sprintf('%04d', $key);
  1330. $cssordered[$val['s'].'_'.$skey] = $val;
  1331. }
  1332. // sort selectors alphabetically to account for specificity
  1333. ksort($cssordered, SORT_STRING);
  1334. return array($selectors, $cssordered);
  1335. }
  1336. /**
  1337. * Compact CSS data array into single string.
  1338. * @param array $css array of CSS properties
  1339. * @return string containing merged CSS properties
  1340. * @since 5.9.070 (2011-04-19)
  1341. * @public static
  1342. */
  1343. public static function getTagStyleFromCSSarray($css) {
  1344. $tagstyle = ''; // value to be returned
  1345. foreach ($css as $style) {
  1346. // split single css commands
  1347. $csscmds = explode(';', $style['c']);
  1348. foreach ($csscmds as $cmd) {
  1349. if (!empty($cmd)) {
  1350. $pos = strpos($cmd, ':');
  1351. if ($pos !== false) {
  1352. $cmd = substr($cmd, 0, ($pos + 1));
  1353. if (strpos($tagstyle, $cmd) !== false) {
  1354. // remove duplicate commands (last commands have high priority)
  1355. $tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle);
  1356. }
  1357. }
  1358. }
  1359. }
  1360. $tagstyle .= ';'.$style['c'];
  1361. }
  1362. // remove multiple semicolons
  1363. $tagstyle = preg_replace('/[;]+/', ';', $tagstyle);
  1364. return $tagstyle;
  1365. }
  1366. /**
  1367. * Returns the Roman representation of an integer number
  1368. * @param int $number number to convert
  1369. * @return string roman representation of the specified number
  1370. * @since 4.4.004 (2008-12-10)
  1371. * @public static
  1372. */
  1373. public static function intToRoman($number) {
  1374. $roman = '';
  1375. if ($number >= 4000) {
  1376. // do not represent numbers above 4000 in Roman numerals
  1377. return strval($number);
  1378. }
  1379. while ($number >= 1000) {
  1380. $roman .= 'M';
  1381. $number -= 1000;
  1382. }
  1383. while ($number >= 900) {
  1384. $roman .= 'CM';
  1385. $number -= 900;
  1386. }
  1387. while ($number >= 500) {
  1388. $roman .= 'D';
  1389. $number -= 500;
  1390. }
  1391. while ($number >= 400) {
  1392. $roman .= 'CD';
  1393. $number -= 400;
  1394. }
  1395. while ($number >= 100) {
  1396. $roman .= 'C';
  1397. $number -= 100;
  1398. }
  1399. while ($number >= 90) {
  1400. $roman .= 'XC';
  1401. $number -= 90;
  1402. }
  1403. while ($number >= 50) {
  1404. $roman .= 'L';
  1405. $number -= 50;
  1406. }
  1407. while ($number >= 40) {
  1408. $roman .= 'XL';
  1409. $number -= 40;
  1410. }
  1411. while ($number >= 10) {
  1412. $roman .= 'X';
  1413. $number -= 10;
  1414. }
  1415. while ($number >= 9) {
  1416. $roman .= 'IX';
  1417. $number -= 9;
  1418. }
  1419. while ($number >= 5) {
  1420. $roman .= 'V';
  1421. $number -= 5;
  1422. }
  1423. while ($number >= 4) {
  1424. $roman .= 'IV';
  1425. $number -= 4;
  1426. }
  1427. while ($number >= 1) {
  1428. $roman .= 'I';
  1429. --$number;
  1430. }
  1431. return $roman;
  1432. }
  1433. /**
  1434. * Find position of last occurrence of a substring in a string
  1435. * @param string $haystack The string to search in.
  1436. * @param string $needle substring to search.
  1437. * @param int $offset May be specified to begin searching an arbitrary number of characters into the string.
  1438. * @return int|false Returns the position where the needle exists. Returns FALSE if the needle was not found.
  1439. * @since 4.8.038 (2010-03-13)
  1440. * @public static
  1441. */
  1442. public static function revstrpos($haystack, $needle, $offset = 0) {
  1443. $length = strlen($haystack);
  1444. $offset = ($offset > 0)?($length - $offset):abs($offset);
  1445. $pos = strpos(strrev($haystack), strrev($needle), $offset);
  1446. return ($pos === false)?false:($length - $pos - strlen($needle));
  1447. }
  1448. /**
  1449. * Returns an array of hyphenation patterns.
  1450. * @param string $file TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  1451. * @return array of hyphenation patterns
  1452. * @author Nicola Asuni
  1453. * @since 4.9.012 (2010-04-12)
  1454. * @public static
  1455. */
  1456. public static function getHyphenPatternsFromTEX($file) {
  1457. // TEX patterns are available at:
  1458. // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  1459. $data = file_get_contents($file);
  1460. $patterns = array();
  1461. // remove comments
  1462. $data = preg_replace('/\%[^\n]*/', '', $data);
  1463. // extract the patterns part
  1464. preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches);
  1465. $data = trim(substr($matches[0], 10, -1));
  1466. // extract each pattern
  1467. $patterns_array = preg_split('/[\s]+/', $data);
  1468. // create new language array of patterns
  1469. $patterns = array();
  1470. foreach($patterns_array as $val) {
  1471. if (!TCPDF_STATIC::empty_string($val)) {
  1472. $val = trim($val);
  1473. $val = str_replace('\'', '\\\'', $val);
  1474. $key = preg_replace('/[0-9]+/', '', $val);
  1475. $patterns[$key] = $val;
  1476. }
  1477. }
  1478. return $patterns;
  1479. }
  1480. /**
  1481. * Get the Path-Painting Operators.
  1482. * @param string $style Style of rendering. Possible values are:
  1483. * <ul>
  1484. * <li>S or D: Stroke the path.</li>
  1485. * <li>s or d: Close and stroke the path.</li>
  1486. * <li>f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.</li>
  1487. * <li>f* or F*: Fill the path, using the even-odd rule to determine the region to fill.</li>
  1488. * <li>B or FD or DF: Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill.</li>
  1489. * <li>B* or F*D or DF*: Fill and then stroke the path, using the even-odd rule to determine the region to fill.</li>
  1490. * <li>b or fd or df: Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill.</li>
  1491. * <li>b or f*d or df*: Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill.</li>
  1492. * <li>CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.</li>
  1493. * <li>CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path</li>
  1494. * <li>n: End the path object without filling or stroking it.</li>
  1495. * </ul>
  1496. * @param string $default default style
  1497. * @return string
  1498. * @author Nicola Asuni
  1499. * @since 5.0.000 (2010-04-30)
  1500. * @public static
  1501. */
  1502. public static function getPathPaintOperator($style, $default='S') {
  1503. $op = '';
  1504. switch($style) {
  1505. case 'S':
  1506. case 'D': {
  1507. $op = 'S';
  1508. break;
  1509. }
  1510. case 's':
  1511. case 'd': {
  1512. $op = 's';
  1513. break;
  1514. }
  1515. case 'f':
  1516. case 'F': {
  1517. $op = 'f';
  1518. break;
  1519. }
  1520. case 'f*':
  1521. case 'F*': {
  1522. $op = 'f*';
  1523. break;
  1524. }
  1525. case 'B':
  1526. case 'FD':
  1527. case 'DF': {
  1528. $op = 'B';
  1529. break;
  1530. }
  1531. case 'B*':
  1532. case 'F*D':
  1533. case 'DF*': {
  1534. $op = 'B*';
  1535. break;
  1536. }
  1537. case 'b':
  1538. case 'fd':
  1539. case 'df': {
  1540. $op = 'b';
  1541. break;
  1542. }
  1543. case 'b*':
  1544. case 'f*d':
  1545. case 'df*': {
  1546. $op = 'b*';
  1547. break;
  1548. }
  1549. case 'CNZ': {
  1550. $op = 'W n';
  1551. break;
  1552. }
  1553. case 'CEO': {
  1554. $op = 'W* n';
  1555. break;
  1556. }
  1557. case 'n': {
  1558. $op = 'n';
  1559. break;
  1560. }
  1561. default: {
  1562. if (!empty($default)) {
  1563. $op = self::getPathPaintOperator($default, '');
  1564. } else {
  1565. $op = '';
  1566. }
  1567. }
  1568. }
  1569. return $op;
  1570. }
  1571. /**
  1572. * Get the product of two SVG tranformation matrices
  1573. * @param array $ta first SVG tranformation matrix
  1574. * @param array $tb second SVG tranformation matrix
  1575. * @return array transformation array
  1576. * @author Nicola Asuni
  1577. * @since 5.0.000 (2010-05-02)
  1578. * @public static
  1579. */
  1580. public static function getTransformationMatrixProduct($ta, $tb) {
  1581. $tm = array();
  1582. $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]);
  1583. $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]);
  1584. $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]);
  1585. $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]);
  1586. $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4];
  1587. $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5];
  1588. return $tm;
  1589. }
  1590. /**
  1591. * Get the tranformation matrix from SVG transform attribute
  1592. * @param string $attribute transformation
  1593. * @return array of transformations
  1594. * @author Nicola Asuni
  1595. * @since 5.0.000 (2010-05-02)
  1596. * @public static
  1597. */
  1598. public static function getSVGTransformMatrix($attribute) {
  1599. // identity matrix
  1600. $tm = array(1, 0, 0, 1, 0, 0);
  1601. $transform = array();
  1602. if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) {
  1603. foreach ($transform as $key => $data) {
  1604. if (!empty($data[2])) {
  1605. $a = 1;
  1606. $b = 0;
  1607. $c = 0;
  1608. $d = 1;
  1609. $e = 0;
  1610. $f = 0;
  1611. $regs = array();
  1612. switch ($data[1]) {
  1613. case 'matrix': {
  1614. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1615. $a = $regs[1];
  1616. $b = $regs[2];
  1617. $c = $regs[3];
  1618. $d = $regs[4];
  1619. $e = $regs[5];
  1620. $f = $regs[6];
  1621. }
  1622. break;
  1623. }
  1624. case 'translate': {
  1625. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1626. $e = $regs[1];
  1627. $f = $regs[2];
  1628. } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1629. $e = $regs[1];
  1630. }
  1631. break;
  1632. }
  1633. case 'scale': {
  1634. if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1635. $a = $regs[1];
  1636. $d = $regs[2];
  1637. } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1638. $a = $regs[1];
  1639. $d = $a;
  1640. }
  1641. break;
  1642. }
  1643. case 'rotate': {
  1644. if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) {
  1645. $ang = deg2rad($regs[1]);
  1646. $x = $regs[2];
  1647. $y = $regs[3];
  1648. $a = cos($ang);
  1649. $b = sin($ang);
  1650. $c = -$b;
  1651. $d = $a;
  1652. $e = ($x * (1 - $a)) - ($y * $c);
  1653. $f = ($y * (1 - $d)) - ($x * $b);
  1654. } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  1655. $ang = deg2rad($regs[1]);
  1656. $a = cos($ang);
  1657. $b = sin($ang);
  1658. $c = -$b;
  1659. $d = $a;
  1660. $e = 0;
  1661. $f = 0;
  1662. }
  1663. break;
  1664. }
  1665. case 'skewX': {
  1666. if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  1667. $c = tan(deg2rad($regs[1]));
  1668. }
  1669. break;
  1670. }
  1671. case 'skewY': {
  1672. if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) {
  1673. $b = tan(deg2rad($regs[1]));
  1674. }
  1675. break;
  1676. }
  1677. }
  1678. $tm = self::getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f));
  1679. }
  1680. }
  1681. }
  1682. return $tm;
  1683. }
  1684. /**
  1685. * Returns the angle in radiants between two vectors
  1686. * @param int $x1 X coordinate of first vector point
  1687. * @param int $y1 Y coordinate of first vector point
  1688. * @param int $x2 X coordinate of second vector point
  1689. * @param int $y2 Y coordinate of second vector point
  1690. * @author Nicola Asuni
  1691. * @since 5.0.000 (2010-05-04)
  1692. * @public static
  1693. */
  1694. public static function getVectorsAngle($x1, $y1, $x2, $y2) {
  1695. $dprod = ($x1 * $x2) + ($y1 * $y2);
  1696. $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1));
  1697. $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2));
  1698. $angle = acos($dprod / ($dist1 * $dist2));
  1699. if (is_nan($angle)) {
  1700. $angle = M_PI;
  1701. }
  1702. if ((($x1 * $y2) - ($x2 * $y1)) < 0) {
  1703. $angle *= -1;
  1704. }
  1705. return $angle;
  1706. }
  1707. /**
  1708. * Split string by a regular expression.
  1709. * This is a wrapper for the preg_split function to avoid the bug: https://bugs.php.net/bug.php?id=45850
  1710. * @param string $pattern The regular expression pattern to search for without the modifiers, as a string.
  1711. * @param string $modifiers The modifiers part of the pattern,
  1712. * @param string $subject The input string.
  1713. * @param int $limit If specified, then only substrings up to limit are returned with the rest of the string being placed in the last substring. A limit of -1, 0 or NULL means "no limit" and, as is standard across PHP, you can use NULL to skip to the flags parameter.
  1714. * @param int $flags The flags as specified on the preg_split PHP function.
  1715. * @return array Returns an array containing substrings of subject split along boundaries matched by pattern.modifier
  1716. * @author Nicola Asuni
  1717. * @since 6.0.023
  1718. * @public static
  1719. */
  1720. public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) {
  1721. // PHP 8.1 deprecates nulls for $limit and $flags
  1722. $limit = $limit === null ? -1 : $limit;
  1723. $flags = $flags === null ? 0 : $flags;
  1724. // the bug only happens on PHP 5.2 when using the u modifier
  1725. if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) {
  1726. $ret = preg_split($pattern.$modifiers, $subject, $limit, $flags);
  1727. if ($ret === false) {
  1728. return array();
  1729. }
  1730. return is_array($ret) ? $ret : array();
  1731. }
  1732. // preg_split is bugged - try alternative solution
  1733. $ret = array();
  1734. while (($nl = strpos($subject, "\n")) !== FALSE) {
  1735. $ret = array_merge($ret, preg_split($pattern.$modifiers, substr($subject, 0, $nl), $limit, $flags));
  1736. $ret[] = "\n";
  1737. $subject = substr($subject, ($nl + 1));
  1738. }
  1739. if (strlen($subject) > 0) {
  1740. $ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags));
  1741. }
  1742. return $ret;
  1743. }
  1744. /**
  1745. * Wrapper to use fopen only with local files
  1746. * @param string $filename Name of the file to open
  1747. * @param string $mode
  1748. * @return resource|false Returns a file pointer resource on success, or FALSE on error.
  1749. * @public static
  1750. */
  1751. public static function fopenLocal($filename, $mode) {
  1752. if (strpos($filename, '://') === false) {
  1753. $filename = 'file://'.$filename;
  1754. } elseif (stream_is_local($filename) !== true) {
  1755. return false;
  1756. }
  1757. return fopen($filename, $mode);
  1758. }
  1759. /**
  1760. * Check if the URL exist.
  1761. * @param string $url URL to check.
  1762. * @return bool Returns TRUE if the URL exists; FALSE otherwise.
  1763. * @public static
  1764. * @since 6.2.25
  1765. */
  1766. public static function url_exists($url) {
  1767. $crs = curl_init();
  1768. // encode query params in URL to get right response form the server
  1769. $url = self::encodeUrlQuery($url);
  1770. curl_setopt($crs, CURLOPT_URL, $url);
  1771. curl_setopt($crs, CURLOPT_NOBODY, true);
  1772. curl_setopt($crs, CURLOPT_FAILONERROR, true);
  1773. if ((ini_get('open_basedir') == '') && (!ini_get('safe_mode'))) {
  1774. curl_setopt($crs, CURLOPT_FOLLOWLOCATION, true);
  1775. }
  1776. curl_setopt($crs, CURLOPT_CONNECTTIMEOUT, 5);
  1777. curl_setopt($crs, CURLOPT_TIMEOUT, 30);
  1778. curl_setopt($crs, CURLOPT_SSL_VERIFYPEER, false);
  1779. curl_setopt($crs, CURLOPT_SSL_VERIFYHOST, false);
  1780. curl_setopt($crs, CURLOPT_USERAGENT, 'tc-lib-file');
  1781. curl_setopt($crs, CURLOPT_MAXREDIRS, 5);
  1782. if (defined('CURLOPT_PROTOCOLS')) {
  1783. curl_setopt($crs, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP | CURLPROTO_FTP | CURLPROTO_FTPS);
  1784. }
  1785. curl_exec($crs);
  1786. $code = curl_getinfo($crs, CURLINFO_HTTP_CODE);
  1787. curl_close($crs);
  1788. return ($code == 200);
  1789. }
  1790. /**
  1791. * Encode query params in URL
  1792. *
  1793. * @param string $url
  1794. * @return string
  1795. * @since 6.3.3 (2019-11-01)
  1796. * @public static
  1797. */
  1798. public static function encodeUrlQuery($url) {
  1799. $urlData = parse_url($url);
  1800. if (isset($urlData['query']) && $urlData['query']) {
  1801. $urlQueryData = array();
  1802. parse_str(urldecode($urlData['query']), $urlQueryData);
  1803. $port = isset($urlData['port']) ? ':'.$urlData['port'] : '';
  1804. $updatedUrl = $urlData['scheme'].'://'.$urlData['host'].$port.$urlData['path'].'?'.http_build_query($urlQueryData);
  1805. } else {
  1806. $updatedUrl = $url;
  1807. }
  1808. return $updatedUrl;
  1809. }
  1810. /**
  1811. * Wrapper for file_exists.
  1812. * Checks whether a file or directory exists.
  1813. * Only allows some protocols and local files.
  1814. * @param string $filename Path to the file or directory.
  1815. * @return bool Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.
  1816. * @public static
  1817. */
  1818. public static function file_exists($filename) {
  1819. if (preg_match('|^https?://|', $filename) == 1) {
  1820. return self::url_exists($filename);
  1821. }
  1822. if (strpos($filename, '://')) {
  1823. return false; // only support http and https wrappers for security reasons
  1824. }
  1825. return @file_exists($filename);
  1826. }
  1827. /**
  1828. * Reads entire file into a string.
  1829. * The file can be also an URL.
  1830. * @param string $file Name of the file or URL to read.
  1831. * @return string|false The function returns the read data or FALSE on failure.
  1832. * @author Nicola Asuni
  1833. * @since 6.0.025
  1834. * @public static
  1835. */
  1836. public static function fileGetContents($file) {
  1837. $alt = array($file);
  1838. //
  1839. if ((strlen($file) > 1)
  1840. && ($file[0] === '/')
  1841. && ($file[1] !== '/')
  1842. && !empty($_SERVER['DOCUMENT_ROOT'])
  1843. && ($_SERVER['DOCUMENT_ROOT'] !== '/')
  1844. ) {
  1845. $findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']);
  1846. if (($findroot === false) || ($findroot > 1)) {
  1847. $alt[] = htmlspecialchars_decode(urldecode($_SERVER['DOCUMENT_ROOT'].$file));
  1848. }
  1849. }
  1850. //
  1851. $protocol = 'http';
  1852. if (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) {
  1853. $protocol .= 's';
  1854. }
  1855. //
  1856. $url = $file;
  1857. if (preg_match('%^//%', $url) && !empty($_SERVER['HTTP_HOST'])) {
  1858. $url = $protocol.':'.str_replace(' ', '%20', $url);
  1859. }
  1860. $url = htmlspecialchars_decode($url);
  1861. $alt[] = $url;
  1862. //
  1863. if (preg_match('%^(https?)://%', $url)
  1864. && empty($_SERVER['HTTP_HOST'])
  1865. && empty($_SERVER['DOCUMENT_ROOT'])
  1866. ) {
  1867. $urldata = parse_url($url);
  1868. if (empty($urldata['query'])) {
  1869. $host = $protocol.'://'.$_SERVER['HTTP_HOST'];
  1870. if (strpos($url, $host) === 0) {
  1871. // convert URL to full server path
  1872. $tmp = str_replace($host, $_SERVER['DOCUMENT_ROOT'], $url);
  1873. $alt[] = htmlspecialchars_decode(urldecode($tmp));
  1874. }
  1875. }
  1876. }
  1877. //
  1878. if (isset($_SERVER['SCRIPT_URI'])
  1879. && !preg_match('%^(https?|ftp)://%', $file)
  1880. && !preg_match('%^//%', $file)
  1881. ) {
  1882. $urldata = @parse_url($_SERVER['SCRIPT_URI']);
  1883. $alt[] = $urldata['scheme'].'://'.$urldata['host'].(($file[0] == '/') ? '' : '/').$file;
  1884. }
  1885. //
  1886. $alt = array_unique($alt);
  1887. foreach ($alt as $path) {
  1888. if (!self::file_exists($path)) {
  1889. continue;
  1890. }
  1891. $ret = @file_get_contents($path);
  1892. if ( $ret != false ) {
  1893. return $ret;
  1894. }
  1895. // try to use CURL for URLs
  1896. if (!ini_get('allow_url_fopen')
  1897. && function_exists('curl_init')
  1898. && preg_match('%^(https?|ftp)://%', $path)
  1899. ) {
  1900. // try to get remote file data using cURL
  1901. $crs = curl_init();
  1902. curl_setopt($crs, CURLOPT_URL, $path);
  1903. curl_setopt($crs, CURLOPT_BINARYTRANSFER, true);
  1904. curl_setopt($crs, CURLOPT_FAILONERROR, true);
  1905. curl_setopt($crs, CURLOPT_RETURNTRANSFER, true);
  1906. if ((ini_get('open_basedir') == '') && (!ini_get('safe_mode'))) {
  1907. curl_setopt($crs, CURLOPT_FOLLOWLOCATION, true);
  1908. }
  1909. curl_setopt($crs, CURLOPT_CONNECTTIMEOUT, 5);
  1910. curl_setopt($crs, CURLOPT_TIMEOUT, 30);
  1911. curl_setopt($crs, CURLOPT_SSL_VERIFYPEER, false);
  1912. curl_setopt($crs, CURLOPT_SSL_VERIFYHOST, false);
  1913. curl_setopt($crs, CURLOPT_USERAGENT, 'tc-lib-file');
  1914. curl_setopt($crs, CURLOPT_MAXREDIRS, 5);
  1915. if (defined('CURLOPT_PROTOCOLS')) {
  1916. curl_setopt($crs, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP | CURLPROTO_FTP | CURLPROTO_FTPS);
  1917. }
  1918. $ret = curl_exec($crs);
  1919. curl_close($crs);
  1920. if ($ret !== false) {
  1921. return $ret;
  1922. }
  1923. }
  1924. }
  1925. return false;
  1926. }
  1927. /**
  1928. * Get ULONG from string (Big Endian 32-bit unsigned integer).
  1929. * @param string $str string from where to extract value
  1930. * @param int $offset point from where to read the data
  1931. * @return int 32 bit value
  1932. * @author Nicola Asuni
  1933. * @since 5.2.000 (2010-06-02)
  1934. * @public static
  1935. */
  1936. public static function _getULONG($str, $offset) {
  1937. $v = unpack('Ni', substr($str, $offset, 4));
  1938. return $v['i'];
  1939. }
  1940. /**
  1941. * Get USHORT from string (Big Endian 16-bit unsigned integer).
  1942. * @param string $str string from where to extract value
  1943. * @param int $offset point from where to read the data
  1944. * @return int 16 bit value
  1945. * @author Nicola Asuni
  1946. * @since 5.2.000 (2010-06-02)
  1947. * @public static
  1948. */
  1949. public static function _getUSHORT($str, $offset) {
  1950. $v = unpack('ni', substr($str, $offset, 2));
  1951. return $v['i'];
  1952. }
  1953. /**
  1954. * Get SHORT from string (Big Endian 16-bit signed integer).
  1955. * @param string $str String from where to extract value.
  1956. * @param int $offset Point from where to read the data.
  1957. * @return int 16 bit value
  1958. * @author Nicola Asuni
  1959. * @since 5.2.000 (2010-06-02)
  1960. * @public static
  1961. */
  1962. public static function _getSHORT($str, $offset) {
  1963. $v = unpack('si', substr($str, $offset, 2));
  1964. return $v['i'];
  1965. }
  1966. /**
  1967. * Get FWORD from string (Big Endian 16-bit signed integer).
  1968. * @param string $str String from where to extract value.
  1969. * @param int $offset Point from where to read the data.
  1970. * @return int 16 bit value
  1971. * @author Nicola Asuni
  1972. * @since 5.9.123 (2011-09-30)
  1973. * @public static
  1974. */
  1975. public static function _getFWORD($str, $offset) {
  1976. $v = self::_getUSHORT($str, $offset);
  1977. if ($v > 0x7fff) {
  1978. $v -= 0x10000;
  1979. }
  1980. return $v;
  1981. }
  1982. /**
  1983. * Get UFWORD from string (Big Endian 16-bit unsigned integer).
  1984. * @param string $str string from where to extract value
  1985. * @param int $offset point from where to read the data
  1986. * @return int 16 bit value
  1987. * @author Nicola Asuni
  1988. * @since 5.9.123 (2011-09-30)
  1989. * @public static
  1990. */
  1991. public static function _getUFWORD($str, $offset) {
  1992. $v = self::_getUSHORT($str, $offset);
  1993. return $v;
  1994. }
  1995. /**
  1996. * Get FIXED from string (32-bit signed fixed-point number (16.16).
  1997. * @param string $str string from where to extract value
  1998. * @param int $offset point from where to read the data
  1999. * @return int 16 bit value
  2000. * @author Nicola Asuni
  2001. * @since 5.9.123 (2011-09-30)
  2002. * @public static
  2003. */
  2004. public static function _getFIXED($str, $offset) {
  2005. // mantissa
  2006. $m = self::_getFWORD($str, $offset);
  2007. // fraction
  2008. $f = self::_getUSHORT($str, ($offset + 2));
  2009. $v = floatval(''.$m.'.'.$f.'');
  2010. return $v;
  2011. }
  2012. /**
  2013. * Get BYTE from string (8-bit unsigned integer).
  2014. * @param string $str String from where to extract value.
  2015. * @param int $offset Point from where to read the data.
  2016. * @return int 8 bit value
  2017. * @author Nicola Asuni
  2018. * @since 5.2.000 (2010-06-02)
  2019. * @public static
  2020. */
  2021. public static function _getBYTE($str, $offset) {
  2022. $v = unpack('Ci', substr($str, $offset, 1));
  2023. return $v['i'];
  2024. }
  2025. /**
  2026. * Binary-safe and URL-safe file read.
  2027. * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.
  2028. * @param resource $handle
  2029. * @param int $length
  2030. * @return string|false Returns the read string or FALSE in case of error.
  2031. * @author Nicola Asuni
  2032. * @since 4.5.027 (2009-03-16)
  2033. * @public static
  2034. */
  2035. public static function rfread($handle, $length) {
  2036. $data = fread($handle, $length);
  2037. if ($data === false) {
  2038. return false;
  2039. }
  2040. $rest = ($length - strlen($data));
  2041. if (($rest > 0) && !feof($handle)) {
  2042. $data .= self::rfread($handle, $rest);
  2043. }
  2044. return $data;
  2045. }
  2046. /**
  2047. * Read a 4-byte (32 bit) integer from file.
  2048. * @param resource $f file resource.
  2049. * @return int 4-byte integer
  2050. * @public static
  2051. */
  2052. public static function _freadint($f) {
  2053. $a = unpack('Ni', fread($f, 4));
  2054. return $a['i'];
  2055. }
  2056. /**
  2057. * Array of page formats
  2058. * measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4)
  2059. * @public static
  2060. *
  2061. * @var array<string,float[]>
  2062. */
  2063. public static $page_formats = array(
  2064. // ISO 216 A Series + 2 SIS 014711 extensions
  2065. 'A0' => array( 2383.937, 3370.394), // = ( 841 x 1189 ) mm = ( 33.11 x 46.81 ) in
  2066. 'A1' => array( 1683.780, 2383.937), // = ( 594 x 841 ) mm = ( 23.39 x 33.11 ) in
  2067. 'A2' => array( 1190.551, 1683.780), // = ( 420 x 594 ) mm = ( 16.54 x 23.39 ) in
  2068. 'A3' => array( 841.890, 1190.551), // = ( 297 x 420 ) mm = ( 11.69 x 16.54 ) in
  2069. 'A4' => array( 595.276, 841.890), // = ( 210 x 297 ) mm = ( 8.27 x 11.69 ) in
  2070. 'A5' => array( 419.528, 595.276), // = ( 148 x 210 ) mm = ( 5.83 x 8.27 ) in
  2071. 'A6' => array( 297.638, 419.528), // = ( 105 x 148 ) mm = ( 4.13 x 5.83 ) in
  2072. 'A7' => array( 209.764, 297.638), // = ( 74 x 105 ) mm = ( 2.91 x 4.13 ) in
  2073. 'A8' => array( 147.402, 209.764), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in
  2074. 'A9' => array( 104.882, 147.402), // = ( 37 x 52 ) mm = ( 1.46 x 2.05 ) in
  2075. 'A10' => array( 73.701, 104.882), // = ( 26 x 37 ) mm = ( 1.02 x 1.46 ) in
  2076. 'A11' => array( 51.024, 73.701), // = ( 18 x 26 ) mm = ( 0.71 x 1.02 ) in
  2077. 'A12' => array( 36.850, 51.024), // = ( 13 x 18 ) mm = ( 0.51 x 0.71 ) in
  2078. // ISO 216 B Series + 2 SIS 014711 extensions
  2079. 'B0' => array( 2834.646, 4008.189), // = ( 1000 x 1414 ) mm = ( 39.37 x 55.67 ) in
  2080. 'B1' => array( 2004.094, 2834.646), // = ( 707 x 1000 ) mm = ( 27.83 x 39.37 ) in
  2081. 'B2' => array( 1417.323, 2004.094), // = ( 500 x 707 ) mm = ( 19.69 x 27.83 ) in
  2082. 'B3' => array( 1000.630, 1417.323), // = ( 353 x 500 ) mm = ( 13.90 x 19.69 ) in
  2083. 'B4' => array( 708.661, 1000.630), // = ( 250 x 353 ) mm = ( 9.84 x 13.90 ) in
  2084. 'B5' => array( 498.898, 708.661), // = ( 176 x 250 ) mm = ( 6.93 x 9.84 ) in
  2085. 'B6' => array( 354.331, 498.898), // = ( 125 x 176 ) mm = ( 4.92 x 6.93 ) in
  2086. 'B7' => array( 249.449, 354.331), // = ( 88 x 125 ) mm = ( 3.46 x 4.92 ) in
  2087. 'B8' => array( 175.748, 249.449), // = ( 62 x 88 ) mm = ( 2.44 x 3.46 ) in
  2088. 'B9' => array( 124.724, 175.748), // = ( 44 x 62 ) mm = ( 1.73 x 2.44 ) in
  2089. 'B10' => array( 87.874, 124.724), // = ( 31 x 44 ) mm = ( 1.22 x 1.73 ) in
  2090. 'B11' => array( 62.362, 87.874), // = ( 22 x 31 ) mm = ( 0.87 x 1.22 ) in
  2091. 'B12' => array( 42.520, 62.362), // = ( 15 x 22 ) mm = ( 0.59 x 0.87 ) in
  2092. // ISO 216 C Series + 2 SIS 014711 extensions + 5 EXTENSION
  2093. 'C0' => array( 2599.370, 3676.535), // = ( 917 x 1297 ) mm = ( 36.10 x 51.06 ) in
  2094. 'C1' => array( 1836.850, 2599.370), // = ( 648 x 917 ) mm = ( 25.51 x 36.10 ) in
  2095. 'C2' => array( 1298.268, 1836.850), // = ( 458 x 648 ) mm = ( 18.03 x 25.51 ) in
  2096. 'C3' => array( 918.425, 1298.268), // = ( 324 x 458 ) mm = ( 12.76 x 18.03 ) in
  2097. 'C4' => array( 649.134, 918.425), // = ( 229 x 324 ) mm = ( 9.02 x 12.76 ) in
  2098. 'C5' => array( 459.213, 649.134), // = ( 162 x 229 ) mm = ( 6.38 x 9.02 ) in
  2099. 'C6' => array( 323.150, 459.213), // = ( 114 x 162 ) mm = ( 4.49 x 6.38 ) in
  2100. 'C7' => array( 229.606, 323.150), // = ( 81 x 114 ) mm = ( 3.19 x 4.49 ) in
  2101. 'C8' => array( 161.575, 229.606), // = ( 57 x 81 ) mm = ( 2.24 x 3.19 ) in
  2102. 'C9' => array( 113.386, 161.575), // = ( 40 x 57 ) mm = ( 1.57 x 2.24 ) in
  2103. 'C10' => array( 79.370, 113.386), // = ( 28 x 40 ) mm = ( 1.10 x 1.57 ) in
  2104. 'C11' => array( 56.693, 79.370), // = ( 20 x 28 ) mm = ( 0.79 x 1.10 ) in
  2105. 'C12' => array( 39.685, 56.693), // = ( 14 x 20 ) mm = ( 0.55 x 0.79 ) in
  2106. 'C76' => array( 229.606, 459.213), // = ( 81 x 162 ) mm = ( 3.19 x 6.38 ) in
  2107. 'DL' => array( 311.811, 623.622), // = ( 110 x 220 ) mm = ( 4.33 x 8.66 ) in
  2108. 'DLE' => array( 323.150, 637.795), // = ( 114 x 225 ) mm = ( 4.49 x 8.86 ) in
  2109. 'DLX' => array( 340.158, 666.142), // = ( 120 x 235 ) mm = ( 4.72 x 9.25 ) in
  2110. 'DLP' => array( 280.630, 595.276), // = ( 99 x 210 ) mm = ( 3.90 x 8.27 ) in (1/3 A4)
  2111. // SIS 014711 E Series
  2112. 'E0' => array( 2491.654, 3517.795), // = ( 879 x 1241 ) mm = ( 34.61 x 48.86 ) in
  2113. 'E1' => array( 1757.480, 2491.654), // = ( 620 x 879 ) mm = ( 24.41 x 34.61 ) in
  2114. 'E2' => array( 1247.244, 1757.480), // = ( 440 x 620 ) mm = ( 17.32 x 24.41 ) in
  2115. 'E3' => array( 878.740, 1247.244), // = ( 310 x 440 ) mm = ( 12.20 x 17.32 ) in
  2116. 'E4' => array( 623.622, 878.740), // = ( 220 x 310 ) mm = ( 8.66 x 12.20 ) in
  2117. 'E5' => array( 439.370, 623.622), // = ( 155 x 220 ) mm = ( 6.10 x 8.66 ) in
  2118. 'E6' => array( 311.811, 439.370), // = ( 110 x 155 ) mm = ( 4.33 x 6.10 ) in
  2119. 'E7' => array( 221.102, 311.811), // = ( 78 x 110 ) mm = ( 3.07 x 4.33 ) in
  2120. 'E8' => array( 155.906, 221.102), // = ( 55 x 78 ) mm = ( 2.17 x 3.07 ) in
  2121. 'E9' => array( 110.551, 155.906), // = ( 39 x 55 ) mm = ( 1.54 x 2.17 ) in
  2122. 'E10' => array( 76.535, 110.551), // = ( 27 x 39 ) mm = ( 1.06 x 1.54 ) in
  2123. 'E11' => array( 53.858, 76.535), // = ( 19 x 27 ) mm = ( 0.75 x 1.06 ) in
  2124. 'E12' => array( 36.850, 53.858), // = ( 13 x 19 ) mm = ( 0.51 x 0.75 ) in
  2125. // SIS 014711 G Series
  2126. 'G0' => array( 2715.591, 3838.110), // = ( 958 x 1354 ) mm = ( 37.72 x 53.31 ) in
  2127. 'G1' => array( 1919.055, 2715.591), // = ( 677 x 958 ) mm = ( 26.65 x 37.72 ) in
  2128. 'G2' => array( 1357.795, 1919.055), // = ( 479 x 677 ) mm = ( 18.86 x 26.65 ) in
  2129. 'G3' => array( 958.110, 1357.795), // = ( 338 x 479 ) mm = ( 13.31 x 18.86 ) in
  2130. 'G4' => array( 677.480, 958.110), // = ( 239 x 338 ) mm = ( 9.41 x 13.31 ) in
  2131. 'G5' => array( 479.055, 677.480), // = ( 169 x 239 ) mm = ( 6.65 x 9.41 ) in
  2132. 'G6' => array( 337.323, 479.055), // = ( 119 x 169 ) mm = ( 4.69 x 6.65 ) in
  2133. 'G7' => array( 238.110, 337.323), // = ( 84 x 119 ) mm = ( 3.31 x 4.69 ) in
  2134. 'G8' => array( 167.244, 238.110), // = ( 59 x 84 ) mm = ( 2.32 x 3.31 ) in
  2135. 'G9' => array( 119.055, 167.244), // = ( 42 x 59 ) mm = ( 1.65 x 2.32 ) in
  2136. 'G10' => array( 82.205, 119.055), // = ( 29 x 42 ) mm = ( 1.14 x 1.65 ) in
  2137. 'G11' => array( 59.528, 82.205), // = ( 21 x 29 ) mm = ( 0.83 x 1.14 ) in
  2138. 'G12' => array( 39.685, 59.528), // = ( 14 x 21 ) mm = ( 0.55 x 0.83 ) in
  2139. // ISO Press
  2140. 'RA0' => array( 2437.795, 3458.268), // = ( 860 x 1220 ) mm = ( 33.86 x 48.03 ) in
  2141. 'RA1' => array( 1729.134, 2437.795), // = ( 610 x 860 ) mm = ( 24.02 x 33.86 ) in
  2142. 'RA2' => array( 1218.898, 1729.134), // = ( 430 x 610 ) mm = ( 16.93 x 24.02 ) in
  2143. 'RA3' => array( 864.567, 1218.898), // = ( 305 x 430 ) mm = ( 12.01 x 16.93 ) in
  2144. 'RA4' => array( 609.449, 864.567), // = ( 215 x 305 ) mm = ( 8.46 x 12.01 ) in
  2145. 'SRA0' => array( 2551.181, 3628.346), // = ( 900 x 1280 ) mm = ( 35.43 x 50.39 ) in
  2146. 'SRA1' => array( 1814.173, 2551.181), // = ( 640 x 900 ) mm = ( 25.20 x 35.43 ) in
  2147. 'SRA2' => array( 1275.591, 1814.173), // = ( 450 x 640 ) mm = ( 17.72 x 25.20 ) in
  2148. 'SRA3' => array( 907.087, 1275.591), // = ( 320 x 450 ) mm = ( 12.60 x 17.72 ) in
  2149. 'SRA4' => array( 637.795, 907.087), // = ( 225 x 320 ) mm = ( 8.86 x 12.60 ) in
  2150. // German DIN 476
  2151. '4A0' => array( 4767.874, 6740.787), // = ( 1682 x 2378 ) mm = ( 66.22 x 93.62 ) in
  2152. '2A0' => array( 3370.394, 4767.874), // = ( 1189 x 1682 ) mm = ( 46.81 x 66.22 ) in
  2153. // Variations on the ISO Standard
  2154. 'A2_EXTRA' => array( 1261.417, 1754.646), // = ( 445 x 619 ) mm = ( 17.52 x 24.37 ) in
  2155. 'A3+' => array( 932.598, 1369.134), // = ( 329 x 483 ) mm = ( 12.95 x 19.02 ) in
  2156. 'A3_EXTRA' => array( 912.756, 1261.417), // = ( 322 x 445 ) mm = ( 12.68 x 17.52 ) in
  2157. 'A3_SUPER' => array( 864.567, 1440.000), // = ( 305 x 508 ) mm = ( 12.01 x 20.00 ) in
  2158. 'SUPER_A3' => array( 864.567, 1380.472), // = ( 305 x 487 ) mm = ( 12.01 x 19.17 ) in
  2159. 'A4_EXTRA' => array( 666.142, 912.756), // = ( 235 x 322 ) mm = ( 9.25 x 12.68 ) in
  2160. 'A4_SUPER' => array( 649.134, 912.756), // = ( 229 x 322 ) mm = ( 9.02 x 12.68 ) in
  2161. 'SUPER_A4' => array( 643.465, 1009.134), // = ( 227 x 356 ) mm = ( 8.94 x 14.02 ) in
  2162. 'A4_LONG' => array( 595.276, 986.457), // = ( 210 x 348 ) mm = ( 8.27 x 13.70 ) in
  2163. 'F4' => array( 595.276, 935.433), // = ( 210 x 330 ) mm = ( 8.27 x 12.99 ) in
  2164. 'SO_B5_EXTRA' => array( 572.598, 782.362), // = ( 202 x 276 ) mm = ( 7.95 x 10.87 ) in
  2165. 'A5_EXTRA' => array( 490.394, 666.142), // = ( 173 x 235 ) mm = ( 6.81 x 9.25 ) in
  2166. // ANSI Series
  2167. 'ANSI_E' => array( 2448.000, 3168.000), // = ( 864 x 1118 ) mm = ( 34.00 x 44.00 ) in
  2168. 'ANSI_D' => array( 1584.000, 2448.000), // = ( 559 x 864 ) mm = ( 22.00 x 34.00 ) in
  2169. 'ANSI_C' => array( 1224.000, 1584.000), // = ( 432 x 559 ) mm = ( 17.00 x 22.00 ) in
  2170. 'ANSI_B' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
  2171. 'ANSI_A' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
  2172. // Traditional 'Loose' North American Paper Sizes
  2173. 'USLEDGER' => array( 1224.000, 792.000), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in
  2174. 'LEDGER' => array( 1224.000, 792.000), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in
  2175. 'ORGANIZERK' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
  2176. 'BIBLE' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
  2177. 'USTABLOID' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
  2178. 'TABLOID' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
  2179. 'ORGANIZERM' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
  2180. 'USLETTER' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
  2181. 'LETTER' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
  2182. 'USLEGAL' => array( 612.000, 1008.000), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in
  2183. 'LEGAL' => array( 612.000, 1008.000), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in
  2184. 'GOVERNMENTLETTER' => array( 576.000, 756.000), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in
  2185. 'GLETTER' => array( 576.000, 756.000), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in
  2186. 'JUNIORLEGAL' => array( 576.000, 360.000), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in
  2187. 'JLEGAL' => array( 576.000, 360.000), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in
  2188. // Other North American Paper Sizes
  2189. 'QUADDEMY' => array( 2520.000, 3240.000), // = ( 889 x 1143 ) mm = ( 35.00 x 45.00 ) in
  2190. 'SUPER_B' => array( 936.000, 1368.000), // = ( 330 x 483 ) mm = ( 13.00 x 19.00 ) in
  2191. 'QUARTO' => array( 648.000, 792.000), // = ( 229 x 279 ) mm = ( 9.00 x 11.00 ) in
  2192. 'GOVERNMENTLEGAL' => array( 612.000, 936.000), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in
  2193. 'FOLIO' => array( 612.000, 936.000), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in
  2194. 'MONARCH' => array( 522.000, 756.000), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in
  2195. 'EXECUTIVE' => array( 522.000, 756.000), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in
  2196. 'ORGANIZERL' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
  2197. 'STATEMENT' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
  2198. 'MEMO' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
  2199. 'FOOLSCAP' => array( 595.440, 936.000), // = ( 210 x 330 ) mm = ( 8.27 x 13.00 ) in
  2200. 'COMPACT' => array( 306.000, 486.000), // = ( 108 x 171 ) mm = ( 4.25 x 6.75 ) in
  2201. 'ORGANIZERJ' => array( 198.000, 360.000), // = ( 70 x 127 ) mm = ( 2.75 x 5.00 ) in
  2202. // Canadian standard CAN 2-9.60M
  2203. 'P1' => array( 1587.402, 2437.795), // = ( 560 x 860 ) mm = ( 22.05 x 33.86 ) in
  2204. 'P2' => array( 1218.898, 1587.402), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in
  2205. 'P3' => array( 793.701, 1218.898), // = ( 280 x 430 ) mm = ( 11.02 x 16.93 ) in
  2206. 'P4' => array( 609.449, 793.701), // = ( 215 x 280 ) mm = ( 8.46 x 11.02 ) in
  2207. 'P5' => array( 396.850, 609.449), // = ( 140 x 215 ) mm = ( 5.51 x 8.46 ) in
  2208. 'P6' => array( 303.307, 396.850), // = ( 107 x 140 ) mm = ( 4.21 x 5.51 ) in
  2209. // North American Architectural Sizes
  2210. 'ARCH_E' => array( 2592.000, 3456.000), // = ( 914 x 1219 ) mm = ( 36.00 x 48.00 ) in
  2211. 'ARCH_E1' => array( 2160.000, 3024.000), // = ( 762 x 1067 ) mm = ( 30.00 x 42.00 ) in
  2212. 'ARCH_D' => array( 1728.000, 2592.000), // = ( 610 x 914 ) mm = ( 24.00 x 36.00 ) in
  2213. 'BROADSHEET' => array( 1296.000, 1728.000), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in
  2214. 'ARCH_C' => array( 1296.000, 1728.000), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in
  2215. 'ARCH_B' => array( 864.000, 1296.000), // = ( 305 x 457 ) mm = ( 12.00 x 18.00 ) in
  2216. 'ARCH_A' => array( 648.000, 864.000), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in
  2217. // -- North American Envelope Sizes
  2218. // - Announcement Envelopes
  2219. 'ANNENV_A2' => array( 314.640, 414.000), // = ( 111 x 146 ) mm = ( 4.37 x 5.75 ) in
  2220. 'ANNENV_A6' => array( 342.000, 468.000), // = ( 121 x 165 ) mm = ( 4.75 x 6.50 ) in
  2221. 'ANNENV_A7' => array( 378.000, 522.000), // = ( 133 x 184 ) mm = ( 5.25 x 7.25 ) in
  2222. 'ANNENV_A8' => array( 396.000, 584.640), // = ( 140 x 206 ) mm = ( 5.50 x 8.12 ) in
  2223. 'ANNENV_A10' => array( 450.000, 692.640), // = ( 159 x 244 ) mm = ( 6.25 x 9.62 ) in
  2224. 'ANNENV_SLIM' => array( 278.640, 638.640), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in
  2225. // - Commercial Envelopes
  2226. 'COMMENV_N6_1/4' => array( 252.000, 432.000), // = ( 89 x 152 ) mm = ( 3.50 x 6.00 ) in
  2227. 'COMMENV_N6_3/4' => array( 260.640, 468.000), // = ( 92 x 165 ) mm = ( 3.62 x 6.50 ) in
  2228. 'COMMENV_N8' => array( 278.640, 540.000), // = ( 98 x 191 ) mm = ( 3.87 x 7.50 ) in
  2229. 'COMMENV_N9' => array( 278.640, 638.640), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in
  2230. 'COMMENV_N10' => array( 296.640, 684.000), // = ( 105 x 241 ) mm = ( 4.12 x 9.50 ) in
  2231. 'COMMENV_N11' => array( 324.000, 746.640), // = ( 114 x 263 ) mm = ( 4.50 x 10.37 ) in
  2232. 'COMMENV_N12' => array( 342.000, 792.000), // = ( 121 x 279 ) mm = ( 4.75 x 11.00 ) in
  2233. 'COMMENV_N14' => array( 360.000, 828.000), // = ( 127 x 292 ) mm = ( 5.00 x 11.50 ) in
  2234. // - Catalogue Envelopes
  2235. 'CATENV_N1' => array( 432.000, 648.000), // = ( 152 x 229 ) mm = ( 6.00 x 9.00 ) in
  2236. 'CATENV_N1_3/4' => array( 468.000, 684.000), // = ( 165 x 241 ) mm = ( 6.50 x 9.50 ) in
  2237. 'CATENV_N2' => array( 468.000, 720.000), // = ( 165 x 254 ) mm = ( 6.50 x 10.00 ) in
  2238. 'CATENV_N3' => array( 504.000, 720.000), // = ( 178 x 254 ) mm = ( 7.00 x 10.00 ) in
  2239. 'CATENV_N6' => array( 540.000, 756.000), // = ( 191 x 267 ) mm = ( 7.50 x 10.50 ) in
  2240. 'CATENV_N7' => array( 576.000, 792.000), // = ( 203 x 279 ) mm = ( 8.00 x 11.00 ) in
  2241. 'CATENV_N8' => array( 594.000, 810.000), // = ( 210 x 286 ) mm = ( 8.25 x 11.25 ) in
  2242. 'CATENV_N9_1/2' => array( 612.000, 756.000), // = ( 216 x 267 ) mm = ( 8.50 x 10.50 ) in
  2243. 'CATENV_N9_3/4' => array( 630.000, 810.000), // = ( 222 x 286 ) mm = ( 8.75 x 11.25 ) in
  2244. 'CATENV_N10_1/2' => array( 648.000, 864.000), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in
  2245. 'CATENV_N12_1/2' => array( 684.000, 900.000), // = ( 241 x 318 ) mm = ( 9.50 x 12.50 ) in
  2246. 'CATENV_N13_1/2' => array( 720.000, 936.000), // = ( 254 x 330 ) mm = ( 10.00 x 13.00 ) in
  2247. 'CATENV_N14_1/4' => array( 810.000, 882.000), // = ( 286 x 311 ) mm = ( 11.25 x 12.25 ) in
  2248. 'CATENV_N14_1/2' => array( 828.000, 1044.000), // = ( 292 x 368 ) mm = ( 11.50 x 14.50 ) in
  2249. // Japanese (JIS P 0138-61) Standard B-Series
  2250. 'JIS_B0' => array( 2919.685, 4127.244), // = ( 1030 x 1456 ) mm = ( 40.55 x 57.32 ) in
  2251. 'JIS_B1' => array( 2063.622, 2919.685), // = ( 728 x 1030 ) mm = ( 28.66 x 40.55 ) in
  2252. 'JIS_B2' => array( 1459.843, 2063.622), // = ( 515 x 728 ) mm = ( 20.28 x 28.66 ) in
  2253. 'JIS_B3' => array( 1031.811, 1459.843), // = ( 364 x 515 ) mm = ( 14.33 x 20.28 ) in
  2254. 'JIS_B4' => array( 728.504, 1031.811), // = ( 257 x 364 ) mm = ( 10.12 x 14.33 ) in
  2255. 'JIS_B5' => array( 515.906, 728.504), // = ( 182 x 257 ) mm = ( 7.17 x 10.12 ) in
  2256. 'JIS_B6' => array( 362.835, 515.906), // = ( 128 x 182 ) mm = ( 5.04 x 7.17 ) in
  2257. 'JIS_B7' => array( 257.953, 362.835), // = ( 91 x 128 ) mm = ( 3.58 x 5.04 ) in
  2258. 'JIS_B8' => array( 181.417, 257.953), // = ( 64 x 91 ) mm = ( 2.52 x 3.58 ) in
  2259. 'JIS_B9' => array( 127.559, 181.417), // = ( 45 x 64 ) mm = ( 1.77 x 2.52 ) in
  2260. 'JIS_B10' => array( 90.709, 127.559), // = ( 32 x 45 ) mm = ( 1.26 x 1.77 ) in
  2261. 'JIS_B11' => array( 62.362, 90.709), // = ( 22 x 32 ) mm = ( 0.87 x 1.26 ) in
  2262. 'JIS_B12' => array( 45.354, 62.362), // = ( 16 x 22 ) mm = ( 0.63 x 0.87 ) in
  2263. // PA Series
  2264. 'PA0' => array( 2381.102, 3174.803), // = ( 840 x 1120 ) mm = ( 33.07 x 44.09 ) in
  2265. 'PA1' => array( 1587.402, 2381.102), // = ( 560 x 840 ) mm = ( 22.05 x 33.07 ) in
  2266. 'PA2' => array( 1190.551, 1587.402), // = ( 420 x 560 ) mm = ( 16.54 x 22.05 ) in
  2267. 'PA3' => array( 793.701, 1190.551), // = ( 280 x 420 ) mm = ( 11.02 x 16.54 ) in
  2268. 'PA4' => array( 595.276, 793.701), // = ( 210 x 280 ) mm = ( 8.27 x 11.02 ) in
  2269. 'PA5' => array( 396.850, 595.276), // = ( 140 x 210 ) mm = ( 5.51 x 8.27 ) in
  2270. 'PA6' => array( 297.638, 396.850), // = ( 105 x 140 ) mm = ( 4.13 x 5.51 ) in
  2271. 'PA7' => array( 198.425, 297.638), // = ( 70 x 105 ) mm = ( 2.76 x 4.13 ) in
  2272. 'PA8' => array( 147.402, 198.425), // = ( 52 x 70 ) mm = ( 2.05 x 2.76 ) in
  2273. 'PA9' => array( 99.213, 147.402), // = ( 35 x 52 ) mm = ( 1.38 x 2.05 ) in
  2274. 'PA10' => array( 73.701, 99.213), // = ( 26 x 35 ) mm = ( 1.02 x 1.38 ) in
  2275. // Standard Photographic Print Sizes
  2276. 'PASSPORT_PHOTO' => array( 99.213, 127.559), // = ( 35 x 45 ) mm = ( 1.38 x 1.77 ) in
  2277. 'E' => array( 233.858, 340.157), // = ( 82 x 120 ) mm = ( 3.25 x 4.72 ) in
  2278. 'L' => array( 252.283, 360.000), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in
  2279. '3R' => array( 252.283, 360.000), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in
  2280. 'KG' => array( 289.134, 430.866), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in
  2281. '4R' => array( 289.134, 430.866), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in
  2282. '4D' => array( 340.157, 430.866), // = ( 120 x 152 ) mm = ( 4.72 x 5.98 ) in
  2283. '2L' => array( 360.000, 504.567), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in
  2284. '5R' => array( 360.000, 504.567), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in
  2285. '8P' => array( 430.866, 575.433), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in
  2286. '6R' => array( 430.866, 575.433), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in
  2287. '6P' => array( 575.433, 720.000), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in
  2288. '8R' => array( 575.433, 720.000), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in
  2289. '6PW' => array( 575.433, 864.567), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in
  2290. 'S8R' => array( 575.433, 864.567), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in
  2291. '4P' => array( 720.000, 864.567), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in
  2292. '10R' => array( 720.000, 864.567), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in
  2293. '4PW' => array( 720.000, 1080.000), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in
  2294. 'S10R' => array( 720.000, 1080.000), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in
  2295. '11R' => array( 790.866, 1009.134), // = ( 279 x 356 ) mm = ( 10.98 x 14.02 ) in
  2296. 'S11R' => array( 790.866, 1224.567), // = ( 279 x 432 ) mm = ( 10.98 x 17.01 ) in
  2297. '12R' => array( 864.567, 1080.000), // = ( 305 x 381 ) mm = ( 12.01 x 15.00 ) in
  2298. 'S12R' => array( 864.567, 1292.598), // = ( 305 x 456 ) mm = ( 12.01 x 17.95 ) in
  2299. // Common Newspaper Sizes
  2300. 'NEWSPAPER_BROADSHEET' => array( 2125.984, 1700.787), // = ( 750 x 600 ) mm = ( 29.53 x 23.62 ) in
  2301. 'NEWSPAPER_BERLINER' => array( 1332.283, 892.913), // = ( 470 x 315 ) mm = ( 18.50 x 12.40 ) in
  2302. 'NEWSPAPER_TABLOID' => array( 1218.898, 793.701), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in
  2303. 'NEWSPAPER_COMPACT' => array( 1218.898, 793.701), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in
  2304. // Business Cards
  2305. 'CREDIT_CARD' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
  2306. 'BUSINESS_CARD' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
  2307. 'BUSINESS_CARD_ISO7810' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
  2308. 'BUSINESS_CARD_ISO216' => array( 147.402, 209.764), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in
  2309. 'BUSINESS_CARD_IT' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
  2310. 'BUSINESS_CARD_UK' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
  2311. 'BUSINESS_CARD_FR' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
  2312. 'BUSINESS_CARD_DE' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
  2313. 'BUSINESS_CARD_ES' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
  2314. 'BUSINESS_CARD_CA' => array( 144.567, 252.283), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in
  2315. 'BUSINESS_CARD_US' => array( 144.567, 252.283), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in
  2316. 'BUSINESS_CARD_JP' => array( 155.906, 257.953), // = ( 55 x 91 ) mm = ( 2.17 x 3.58 ) in
  2317. 'BUSINESS_CARD_HK' => array( 153.071, 255.118), // = ( 54 x 90 ) mm = ( 2.13 x 3.54 ) in
  2318. 'BUSINESS_CARD_AU' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
  2319. 'BUSINESS_CARD_DK' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
  2320. 'BUSINESS_CARD_SE' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
  2321. 'BUSINESS_CARD_RU' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
  2322. 'BUSINESS_CARD_CZ' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
  2323. 'BUSINESS_CARD_FI' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
  2324. 'BUSINESS_CARD_HU' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
  2325. 'BUSINESS_CARD_IL' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
  2326. // Billboards
  2327. '4SHEET' => array( 2880.000, 4320.000), // = ( 1016 x 1524 ) mm = ( 40.00 x 60.00 ) in
  2328. '6SHEET' => array( 3401.575, 5102.362), // = ( 1200 x 1800 ) mm = ( 47.24 x 70.87 ) in
  2329. '12SHEET' => array( 8640.000, 4320.000), // = ( 3048 x 1524 ) mm = (120.00 x 60.00 ) in
  2330. '16SHEET' => array( 5760.000, 8640.000), // = ( 2032 x 3048 ) mm = ( 80.00 x 120.00) in
  2331. '32SHEET' => array(11520.000, 8640.000), // = ( 4064 x 3048 ) mm = (160.00 x 120.00) in
  2332. '48SHEET' => array(17280.000, 8640.000), // = ( 6096 x 3048 ) mm = (240.00 x 120.00) in
  2333. '64SHEET' => array(23040.000, 8640.000), // = ( 8128 x 3048 ) mm = (320.00 x 120.00) in
  2334. '96SHEET' => array(34560.000, 8640.000), // = (12192 x 3048 ) mm = (480.00 x 120.00) in
  2335. // -- Old European Sizes
  2336. // - Old Imperial English Sizes
  2337. 'EN_EMPEROR' => array( 3456.000, 5184.000), // = ( 1219 x 1829 ) mm = ( 48.00 x 72.00 ) in
  2338. 'EN_ANTIQUARIAN' => array( 2232.000, 3816.000), // = ( 787 x 1346 ) mm = ( 31.00 x 53.00 ) in
  2339. 'EN_GRAND_EAGLE' => array( 2070.000, 3024.000), // = ( 730 x 1067 ) mm = ( 28.75 x 42.00 ) in
  2340. 'EN_DOUBLE_ELEPHANT' => array( 1926.000, 2880.000), // = ( 679 x 1016 ) mm = ( 26.75 x 40.00 ) in
  2341. 'EN_ATLAS' => array( 1872.000, 2448.000), // = ( 660 x 864 ) mm = ( 26.00 x 34.00 ) in
  2342. 'EN_COLOMBIER' => array( 1692.000, 2484.000), // = ( 597 x 876 ) mm = ( 23.50 x 34.50 ) in
  2343. 'EN_ELEPHANT' => array( 1656.000, 2016.000), // = ( 584 x 711 ) mm = ( 23.00 x 28.00 ) in
  2344. 'EN_DOUBLE_DEMY' => array( 1620.000, 2556.000), // = ( 572 x 902 ) mm = ( 22.50 x 35.50 ) in
  2345. 'EN_IMPERIAL' => array( 1584.000, 2160.000), // = ( 559 x 762 ) mm = ( 22.00 x 30.00 ) in
  2346. 'EN_PRINCESS' => array( 1548.000, 2016.000), // = ( 546 x 711 ) mm = ( 21.50 x 28.00 ) in
  2347. 'EN_CARTRIDGE' => array( 1512.000, 1872.000), // = ( 533 x 660 ) mm = ( 21.00 x 26.00 ) in
  2348. 'EN_DOUBLE_LARGE_POST' => array( 1512.000, 2376.000), // = ( 533 x 838 ) mm = ( 21.00 x 33.00 ) in
  2349. 'EN_ROYAL' => array( 1440.000, 1800.000), // = ( 508 x 635 ) mm = ( 20.00 x 25.00 ) in
  2350. 'EN_SHEET' => array( 1404.000, 1692.000), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in
  2351. 'EN_HALF_POST' => array( 1404.000, 1692.000), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in
  2352. 'EN_SUPER_ROYAL' => array( 1368.000, 1944.000), // = ( 483 x 686 ) mm = ( 19.00 x 27.00 ) in
  2353. 'EN_DOUBLE_POST' => array( 1368.000, 2196.000), // = ( 483 x 775 ) mm = ( 19.00 x 30.50 ) in
  2354. 'EN_MEDIUM' => array( 1260.000, 1656.000), // = ( 445 x 584 ) mm = ( 17.50 x 23.00 ) in
  2355. 'EN_DEMY' => array( 1260.000, 1620.000), // = ( 445 x 572 ) mm = ( 17.50 x 22.50 ) in
  2356. 'EN_LARGE_POST' => array( 1188.000, 1512.000), // = ( 419 x 533 ) mm = ( 16.50 x 21.00 ) in
  2357. 'EN_COPY_DRAUGHT' => array( 1152.000, 1440.000), // = ( 406 x 508 ) mm = ( 16.00 x 20.00 ) in
  2358. 'EN_POST' => array( 1116.000, 1386.000), // = ( 394 x 489 ) mm = ( 15.50 x 19.25 ) in
  2359. 'EN_CROWN' => array( 1080.000, 1440.000), // = ( 381 x 508 ) mm = ( 15.00 x 20.00 ) in
  2360. 'EN_PINCHED_POST' => array( 1062.000, 1332.000), // = ( 375 x 470 ) mm = ( 14.75 x 18.50 ) in
  2361. 'EN_BRIEF' => array( 972.000, 1152.000), // = ( 343 x 406 ) mm = ( 13.50 x 16.00 ) in
  2362. 'EN_FOOLSCAP' => array( 972.000, 1224.000), // = ( 343 x 432 ) mm = ( 13.50 x 17.00 ) in
  2363. 'EN_SMALL_FOOLSCAP' => array( 954.000, 1188.000), // = ( 337 x 419 ) mm = ( 13.25 x 16.50 ) in
  2364. 'EN_POTT' => array( 900.000, 1080.000), // = ( 318 x 381 ) mm = ( 12.50 x 15.00 ) in
  2365. // - Old Imperial Belgian Sizes
  2366. 'BE_GRAND_AIGLE' => array( 1984.252, 2948.031), // = ( 700 x 1040 ) mm = ( 27.56 x 40.94 ) in
  2367. 'BE_COLOMBIER' => array( 1757.480, 2409.449), // = ( 620 x 850 ) mm = ( 24.41 x 33.46 ) in
  2368. 'BE_DOUBLE_CARRE' => array( 1757.480, 2607.874), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in
  2369. 'BE_ELEPHANT' => array( 1746.142, 2182.677), // = ( 616 x 770 ) mm = ( 24.25 x 30.31 ) in
  2370. 'BE_PETIT_AIGLE' => array( 1700.787, 2381.102), // = ( 600 x 840 ) mm = ( 23.62 x 33.07 ) in
  2371. 'BE_GRAND_JESUS' => array( 1559.055, 2069.291), // = ( 550 x 730 ) mm = ( 21.65 x 28.74 ) in
  2372. 'BE_JESUS' => array( 1530.709, 2069.291), // = ( 540 x 730 ) mm = ( 21.26 x 28.74 ) in
  2373. 'BE_RAISIN' => array( 1417.323, 1842.520), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in
  2374. 'BE_GRAND_MEDIAN' => array( 1303.937, 1714.961), // = ( 460 x 605 ) mm = ( 18.11 x 23.82 ) in
  2375. 'BE_DOUBLE_POSTE' => array( 1233.071, 1601.575), // = ( 435 x 565 ) mm = ( 17.13 x 22.24 ) in
  2376. 'BE_COQUILLE' => array( 1218.898, 1587.402), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in
  2377. 'BE_PETIT_MEDIAN' => array( 1176.378, 1502.362), // = ( 415 x 530 ) mm = ( 16.34 x 20.87 ) in
  2378. 'BE_RUCHE' => array( 1020.472, 1303.937), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in
  2379. 'BE_PROPATRIA' => array( 977.953, 1218.898), // = ( 345 x 430 ) mm = ( 13.58 x 16.93 ) in
  2380. 'BE_LYS' => array( 898.583, 1125.354), // = ( 317 x 397 ) mm = ( 12.48 x 15.63 ) in
  2381. 'BE_POT' => array( 870.236, 1088.504), // = ( 307 x 384 ) mm = ( 12.09 x 15.12 ) in
  2382. 'BE_ROSETTE' => array( 765.354, 983.622), // = ( 270 x 347 ) mm = ( 10.63 x 13.66 ) in
  2383. // - Old Imperial French Sizes
  2384. 'FR_UNIVERS' => array( 2834.646, 3685.039), // = ( 1000 x 1300 ) mm = ( 39.37 x 51.18 ) in
  2385. 'FR_DOUBLE_COLOMBIER' => array( 2551.181, 3571.654), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in
  2386. 'FR_GRANDE_MONDE' => array( 2551.181, 3571.654), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in
  2387. 'FR_DOUBLE_SOLEIL' => array( 2267.717, 3401.575), // = ( 800 x 1200 ) mm = ( 31.50 x 47.24 ) in
  2388. 'FR_DOUBLE_JESUS' => array( 2154.331, 3174.803), // = ( 760 x 1120 ) mm = ( 29.92 x 44.09 ) in
  2389. 'FR_GRAND_AIGLE' => array( 2125.984, 3004.724), // = ( 750 x 1060 ) mm = ( 29.53 x 41.73 ) in
  2390. 'FR_PETIT_AIGLE' => array( 1984.252, 2664.567), // = ( 700 x 940 ) mm = ( 27.56 x 37.01 ) in
  2391. 'FR_DOUBLE_RAISIN' => array( 1842.520, 2834.646), // = ( 650 x 1000 ) mm = ( 25.59 x 39.37 ) in
  2392. 'FR_JOURNAL' => array( 1842.520, 2664.567), // = ( 650 x 940 ) mm = ( 25.59 x 37.01 ) in
  2393. 'FR_COLOMBIER_AFFICHE' => array( 1785.827, 2551.181), // = ( 630 x 900 ) mm = ( 24.80 x 35.43 ) in
  2394. 'FR_DOUBLE_CAVALIER' => array( 1757.480, 2607.874), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in
  2395. 'FR_CLOCHE' => array( 1700.787, 2267.717), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in
  2396. 'FR_SOLEIL' => array( 1700.787, 2267.717), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in
  2397. 'FR_DOUBLE_CARRE' => array( 1587.402, 2551.181), // = ( 560 x 900 ) mm = ( 22.05 x 35.43 ) in
  2398. 'FR_DOUBLE_COQUILLE' => array( 1587.402, 2494.488), // = ( 560 x 880 ) mm = ( 22.05 x 34.65 ) in
  2399. 'FR_JESUS' => array( 1587.402, 2154.331), // = ( 560 x 760 ) mm = ( 22.05 x 29.92 ) in
  2400. 'FR_RAISIN' => array( 1417.323, 1842.520), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in
  2401. 'FR_CAVALIER' => array( 1303.937, 1757.480), // = ( 460 x 620 ) mm = ( 18.11 x 24.41 ) in
  2402. 'FR_DOUBLE_COURONNE' => array( 1303.937, 2040.945), // = ( 460 x 720 ) mm = ( 18.11 x 28.35 ) in
  2403. 'FR_CARRE' => array( 1275.591, 1587.402), // = ( 450 x 560 ) mm = ( 17.72 x 22.05 ) in
  2404. 'FR_COQUILLE' => array( 1247.244, 1587.402), // = ( 440 x 560 ) mm = ( 17.32 x 22.05 ) in
  2405. 'FR_DOUBLE_TELLIERE' => array( 1247.244, 1927.559), // = ( 440 x 680 ) mm = ( 17.32 x 26.77 ) in
  2406. 'FR_DOUBLE_CLOCHE' => array( 1133.858, 1700.787), // = ( 400 x 600 ) mm = ( 15.75 x 23.62 ) in
  2407. 'FR_DOUBLE_POT' => array( 1133.858, 1757.480), // = ( 400 x 620 ) mm = ( 15.75 x 24.41 ) in
  2408. 'FR_ECU' => array( 1133.858, 1474.016), // = ( 400 x 520 ) mm = ( 15.75 x 20.47 ) in
  2409. 'FR_COURONNE' => array( 1020.472, 1303.937), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in
  2410. 'FR_TELLIERE' => array( 963.780, 1247.244), // = ( 340 x 440 ) mm = ( 13.39 x 17.32 ) in
  2411. 'FR_POT' => array( 878.740, 1133.858), // = ( 310 x 400 ) mm = ( 12.20 x 15.75 ) in
  2412. );
  2413. /**
  2414. * Get page dimensions from format name.
  2415. * @param mixed $format The format name @see self::$page_format<ul>
  2416. * @return array containing page width and height in points
  2417. * @since 5.0.010 (2010-05-17)
  2418. * @public static
  2419. */
  2420. public static function getPageSizeFromFormat($format) {
  2421. if (isset(self::$page_formats[$format])) {
  2422. return self::$page_formats[$format];
  2423. }
  2424. return self::$page_formats['A4'];
  2425. }
  2426. /**
  2427. * Set page boundaries.
  2428. * @param int $page page number
  2429. * @param string $type valid values are: <ul><li>'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;</li><li>'CropBox' : the visible region of default user space;</li><li>'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;</li><li>'TrimBox' : the intended dimensions of the finished page after trimming;</li><li>'ArtBox' : the page's meaningful content (including potential white space).</li></ul>
  2430. * @param float $llx lower-left x coordinate in user units.
  2431. * @param float $lly lower-left y coordinate in user units.
  2432. * @param float $urx upper-right x coordinate in user units.
  2433. * @param float $ury upper-right y coordinate in user units.
  2434. * @param boolean $points If true uses user units as unit of measure, otherwise uses PDF points.
  2435. * @param float $k Scale factor (number of points in user unit).
  2436. * @param array $pagedim Array of page dimensions.
  2437. * @return array pagedim array of page dimensions.
  2438. * @since 5.0.010 (2010-05-17)
  2439. * @public static
  2440. */
  2441. public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points, $k, $pagedim=array()) {
  2442. if (!isset($pagedim[$page])) {
  2443. // initialize array
  2444. $pagedim[$page] = array();
  2445. }
  2446. if (!in_array($type, self::$pageboxes)) {
  2447. return;
  2448. }
  2449. if ($points) {
  2450. $k = 1;
  2451. }
  2452. $pagedim[$page][$type]['llx'] = ($llx * $k);
  2453. $pagedim[$page][$type]['lly'] = ($lly * $k);
  2454. $pagedim[$page][$type]['urx'] = ($urx * $k);
  2455. $pagedim[$page][$type]['ury'] = ($ury * $k);
  2456. return $pagedim;
  2457. }
  2458. /**
  2459. * Swap X and Y coordinates of page boxes (change page boxes orientation).
  2460. * @param int $page page number
  2461. * @param array $pagedim Array of page dimensions.
  2462. * @return array pagedim array of page dimensions.
  2463. * @since 5.0.010 (2010-05-17)
  2464. * @public static
  2465. */
  2466. public static function swapPageBoxCoordinates($page, $pagedim) {
  2467. foreach (self::$pageboxes as $type) {
  2468. // swap X and Y coordinates
  2469. if (isset($pagedim[$page][$type])) {
  2470. $tmp = $pagedim[$page][$type]['llx'];
  2471. $pagedim[$page][$type]['llx'] = $pagedim[$page][$type]['lly'];
  2472. $pagedim[$page][$type]['lly'] = $tmp;
  2473. $tmp = $pagedim[$page][$type]['urx'];
  2474. $pagedim[$page][$type]['urx'] = $pagedim[$page][$type]['ury'];
  2475. $pagedim[$page][$type]['ury'] = $tmp;
  2476. }
  2477. }
  2478. return $pagedim;
  2479. }
  2480. /**
  2481. * Get the canonical page layout mode.
  2482. * @param string $layout The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
  2483. * @return string Canonical page layout name.
  2484. * @public static
  2485. */
  2486. public static function getPageLayoutMode($layout='SinglePage') {
  2487. switch ($layout) {
  2488. case 'default':
  2489. case 'single':
  2490. case 'SinglePage': {
  2491. $layout_mode = 'SinglePage';
  2492. break;
  2493. }
  2494. case 'continuous':
  2495. case 'OneColumn': {
  2496. $layout_mode = 'OneColumn';
  2497. break;
  2498. }
  2499. case 'two':
  2500. case 'TwoColumnLeft': {
  2501. $layout_mode = 'TwoColumnLeft';
  2502. break;
  2503. }
  2504. case 'TwoColumnRight': {
  2505. $layout_mode = 'TwoColumnRight';
  2506. break;
  2507. }
  2508. case 'TwoPageLeft': {
  2509. $layout_mode = 'TwoPageLeft';
  2510. break;
  2511. }
  2512. case 'TwoPageRight': {
  2513. $layout_mode = 'TwoPageRight';
  2514. break;
  2515. }
  2516. default: {
  2517. $layout_mode = 'SinglePage';
  2518. }
  2519. }
  2520. return $layout_mode;
  2521. }
  2522. /**
  2523. * Get the canonical page layout mode.
  2524. * @param string $mode A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
  2525. * @return string Canonical page mode name.
  2526. * @public static
  2527. */
  2528. public static function getPageMode($mode='UseNone') {
  2529. switch ($mode) {
  2530. case 'UseNone': {
  2531. $page_mode = 'UseNone';
  2532. break;
  2533. }
  2534. case 'UseOutlines': {
  2535. $page_mode = 'UseOutlines';
  2536. break;
  2537. }
  2538. case 'UseThumbs': {
  2539. $page_mode = 'UseThumbs';
  2540. break;
  2541. }
  2542. case 'FullScreen': {
  2543. $page_mode = 'FullScreen';
  2544. break;
  2545. }
  2546. case 'UseOC': {
  2547. $page_mode = 'UseOC';
  2548. break;
  2549. }
  2550. case '': {
  2551. $page_mode = 'UseAttachments';
  2552. break;
  2553. }
  2554. default: {
  2555. $page_mode = 'UseNone';
  2556. }
  2557. }
  2558. return $page_mode;
  2559. }
  2560. } // END OF TCPDF_STATIC CLASS
  2561. //============================================================+
  2562. // END OF FILE
  2563. //============================================================+