oxpdf.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $myConfig = oxRegistry::getConfig();
00004 
00005 $sTcPdfPath = $myConfig->getConfigParam('sCoreDir') . "tcpdf/";
00006 $sTcPdfUrl = $myConfig->getConfigParam('sShopURL') . "/" . $myConfig->getConfigParam('sCoreDir') . "tcpdf/";
00007 
00011 define('K_TCPDF_EXTERNAL_CONFIG', 1);
00012 
00017 define('K_PATH_MAIN', $sTcPdfPath);
00018 
00023 define('K_PATH_URL', $sTcPdfUrl);
00024 
00029 define('K_PATH_FONTS', K_PATH_MAIN . 'fonts/');
00030 
00034 define('K_PATH_CACHE', K_PATH_MAIN . 'cache/');
00035 
00039 define('K_PATH_URL_CACHE', K_PATH_URL . 'cache/');
00040 
00044 define('K_PATH_IMAGES', K_PATH_MAIN . 'images/');
00045 
00049 define('K_BLANK_IMAGE', K_PATH_IMAGES . '_blank.png');
00050 
00054 define('PDF_PAGE_FORMAT', 'A4');
00055 
00059 define('PDF_PAGE_ORIENTATION', 'P');
00060 
00064 define('PDF_CREATOR', 'TCPDF');
00065 
00069 define('PDF_AUTHOR', 'TCPDF');
00070 
00074 define('PDF_HEADER_TITLE', 'TCPDF Example');
00075 
00079 define('PDF_HEADER_STRING', "by Nicola Asuni - Tecnick.com\nwww.tcpdf.org");
00080 
00084 define('PDF_HEADER_LOGO', 'tcpdf_logo.jpg');
00085 
00089 define('PDF_HEADER_LOGO_WIDTH', 30);
00090 
00094 define('PDF_UNIT', 'mm');
00095 
00099 define('PDF_MARGIN_HEADER', 5);
00100 
00104 define('PDF_MARGIN_FOOTER', 10);
00105 
00109 define('PDF_MARGIN_TOP', 27);
00110 
00114 define('PDF_MARGIN_BOTTOM', 25);
00115 
00119 define('PDF_MARGIN_LEFT', 15);
00120 
00124 define('PDF_MARGIN_RIGHT', 15);
00125 
00129 define('PDF_FONT_NAME_MAIN', 'helvetica');
00130 
00134 define('PDF_FONT_SIZE_MAIN', 10);
00135 
00139 define('PDF_FONT_NAME_DATA', 'helvetica');
00140 
00144 define('PDF_FONT_SIZE_DATA', 8);
00145 
00149 define('PDF_FONT_MONOSPACED', 'courier');
00150 
00154 define('PDF_IMAGE_SCALE_RATIO', 1);
00155 
00159 define('HEAD_MAGNIFICATION', 1.1);
00160 
00164 define('K_CELL_HEIGHT_RATIO', 1.25);
00165 
00169 define('K_TITLE_MAGNIFICATION', 1.3);
00170 
00174 define('K_SMALL_RATIO', 2 / 3);
00175 
00179 require_once $sTcPdfPath . "config/lang/eng.php";
00180 
00184 require_once $sTcPdfPath . "tcpdf.php";
00185 
00189 class oxPDF extends TCPDF
00190 {
00191 
00207     public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false)
00208     {
00209         $myConfig = oxRegistry::getConfig();
00210         $unicode = $myConfig->isUtf();
00211         $encoding = $unicode ? 'UTF-8' : oxRegistry::getLang()->translateString("charset");
00212         //#1161: Thin line and unknown characters on every pdf page
00213         //we use myorder::pdfFooter()
00214         $this->setPrintFooter(false);
00215 
00216         parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache);
00217     }
00218 
00235     public function WriteHTML($html, $ln = true, $fill = false, $reseth = false, $cell = false, $align = '')
00236     {
00237         //HTML parser
00238         $html = str_replace("\n", ' ', $html);
00239         $a = preg_split('/<(.*)>/U', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
00240         foreach ($a as $i => $e) {
00241             if ($i % 2 == 0) {
00242                 //Text
00243                 if ($this->HREF) {
00244                     $this->PutLink($this->HREF, $e);
00245                 } else {
00246                     $this->Write(5, $e);
00247                 }
00248             } else {
00249                 //Tag
00250                 if ($e{0} == '/') {
00251                     $this->CloseTag(strtoupper(substr($e, 1)));
00252                 } else {
00253                     //Extract attributes
00254                     $a2 = explode(' ', $e);
00255                     $tag = strtoupper(array_shift($a2));
00256                     $attr = array();
00257                     foreach ($a2 as $v) {
00258                         if (preg_match('/^([^=]*)=["\']?([^"\']*)["\']?$/', $v, $a3)) {
00259                             $attr[strtoupper($a3[1])] = $a3[2];
00260                         }
00261                     }
00262                     $this->OpenTag($tag, $attr);
00263                 }
00264             }
00265         }
00266     }
00267 
00274     public function OpenTag($tag, $attr)
00275     {
00276         if ($tag == 'B' or $tag == 'I' or $tag == 'U') {
00277             $this->SetStyle($tag, true);
00278         }
00279 
00280         if ($tag == 'A') {
00281             $this->HREF = (is_array($attr) && isset($attr['HREF'])) ? $attr['HREF'] : '';
00282         }
00283 
00284         if ($tag == 'BR') {
00285             $this->Ln(5);
00286         }
00287     }
00288 
00294     public function CloseTag($tag)
00295     {
00296         if ($tag == 'B' or $tag == 'I' or $tag == 'U') {
00297             $this->SetStyle($tag, false);
00298         }
00299 
00300         if ($tag == 'A') {
00301             $this->HREF = '';
00302         }
00303     }
00304 
00311     public function SetStyle($tag, $enable)
00312     {
00313         $this->$tag += ($enable ? 1 : -1);
00314         $style = '';
00315         foreach (array('B', 'I', 'U') as $s) {
00316             if ($this->$s > 0) {
00317                 $style .= $s;
00318             }
00319         }
00320         $this->SetFont('', $style);
00321     }
00322 
00329     public function PutLink($sURL, $sText)
00330     {
00331         $this->SetTextColor(0, 0, 255);
00332         $this->SetStyle('U', true);
00333         $this->Write(5, $sText, $sURL);
00334         $this->SetStyle('U', false);
00335         $this->SetTextColor(0);
00336     }
00337 
00348     public function SetFont($family, $style = '', $size = 0, $fontfile = '')
00349     {
00350         if ($family == 'Arial') {
00351             // overriding standard ..
00352             $family = oxRegistry::getConfig()->isUtf() ? 'freesans' : '';
00353         }
00354 
00355         parent::SetFont($family, $style, $size, $fontfile);
00356     }
00357 }