oxpdf.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $myConfig = oxConfig::getInstance();
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 {
00206     public function __construct( $orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false )
00207     {
00208         $myConfig = oxConfig::getInstance();
00209         $unicode  = $myConfig->isUtf();
00210         $encoding = $unicode ? 'UTF-8' : oxLang::getInstance()->translateString( "charset" );
00211 
00212         parent::__construct( $orientation, $unit, $format, $unicode, $encoding, $diskcache );
00213     }
00214 
00232     public function WriteHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
00233     {
00234         //HTML parser
00235         $html = str_replace( "\n", ' ', $html );
00236         $a    = preg_split('/<(.*)>/U', $html, -1, PREG_SPLIT_DELIM_CAPTURE );
00237         foreach ($a as $i=>$e) {
00238             if ($i%2==0) {
00239                 //Text
00240                 if ($this->HREF) {
00241                     $this->PutLink( $this->HREF, $e );
00242                 } else {
00243                     $this->Write( 5, $e );
00244                 }
00245             } else {
00246                 //Tag
00247                 if ($e{0}=='/') {
00248                     $this->CloseTag(strtoupper(substr($e, 1)));
00249                 } else {
00250                     //Extract attributes
00251                     $a2=explode(' ', $e);
00252                     $tag=strtoupper(array_shift($a2));
00253                     $attr=array();
00254                     foreach ($a2 as $v) {
00255                         if (preg_match('/^([^=]*)=["\']?([^"\']*)["\']?$/', $v, $a3)) {
00256                             $attr[strtoupper($a3[1])]=$a3[2];
00257                         }
00258                     }
00259                     $this->OpenTag($tag, $attr);
00260                 }
00261             }
00262         }
00263     }
00264 
00273     public function OpenTag($tag,$attr)
00274     {
00275         if ( $tag=='B' or $tag=='I' or $tag=='U' ) {
00276             $this->SetStyle($tag, true);
00277         }
00278 
00279         if ( $tag=='A' ) {
00280             $this->HREF = $attr['HREF'];
00281         }
00282 
00283         if ( $tag=='BR' ) {
00284             $this->Ln(5);
00285         }
00286     }
00287 
00295     public function CloseTag($tag)
00296     {
00297         if ( $tag=='B' or $tag=='I' or $tag=='U' ) {
00298             $this->SetStyle($tag, false);
00299         }
00300 
00301         if ( $tag=='A' ) {
00302             $this->HREF = '';
00303         }
00304     }
00305 
00314     public function SetStyle($tag,$enable)
00315     {
00316         $this->$tag+=($enable ? 1 : -1);
00317         $style='';
00318         foreach (array('B', 'I', 'U') as $s) {
00319             if ($this->$s>0) {
00320                 $style.=$s;
00321             }
00322         }
00323         $this->SetFont('', $style);
00324     }
00325 
00334     public function PutLink($URL, $txt)
00335     {
00336         $this->SetTextColor( 0, 0, 255 );
00337         $this->SetStyle( 'U', true );
00338         $this->Write( 5, $txt, $URL );
00339         $this->SetStyle( 'U', false );
00340         $this->SetTextColor( 0 );
00341     }
00342 
00360     public function Text($x,$y,$txt, $stroke=0, $clip=false)
00361     {
00362         // replaces some special code to chars
00363         $txt = str_replace( "&nbsp;", " ", $txt );
00364         $txt = str_replace( "&auml;", "ä", $txt );
00365         $txt = str_replace( "&ouml;", "ö", $txt );
00366         $txt = str_replace( "&uuml;", "ü", $txt );
00367         $txt = str_replace( "&Auml;", "Ä", $txt );
00368         $txt = str_replace( "&Ouml;", "Ö", $txt );
00369         $txt = str_replace( "&Uuml;", "Ü", $txt );
00370         $txt = str_replace( "&szlig;", "ß", $txt);
00371 
00372         // replacing html specific codes
00373 
00374         // if this doesn't help, we should create own entity table
00375         // and replace codes to symbols
00376         $txt = html_entity_decode( $txt );
00377 
00378         // cleaning up possible html code
00379         $txt = strip_tags( $txt );
00380 
00381         //parent::Text($x,$y,$txt, $stroke, $clip);
00382         parent::Text( $x, $y, $txt );
00383     }
00384 
00397     public function SetFont($family, $style='', $size=0, $fontfile='')
00398     {
00399         if ( $family == 'Arial' ) {
00400             // overriding standard ..
00401             $family = oxConfig::getInstance()->isUtf() ? 'freesans' : '';
00402         }
00403 
00404         parent::SetFont($family, $style, $size, $fontfile);
00405     }
00406 
00407 }

Generated on Tue Aug 18 09:21:06 2009 for OXID eShop CE by  doxygen 1.5.5