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 {
00204     public function __construct( $orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false )
00205     {
00206         $myConfig = oxConfig::getInstance();
00207         $unicode  = $myConfig->isUtf();
00208         $encoding = $unicode ? 'UTF-8' : oxLang::getInstance()->translateString( "charset" );
00209 
00210         parent::__construct( $orientation, $unit, $format, $unicode, $encoding, $diskcache );
00211     }
00212 
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         {
00239             if($i%2==0)
00240             {
00241                 //Text
00242                 if($this->HREF)
00243                     $this->PutLink($this->HREF,$e);
00244                 else
00245                     $this->Write(5,$e);
00246             }
00247             else
00248             {
00249                 //Tag
00250                 if($e{0}=='/')
00251                     $this->CloseTag(strtoupper(substr($e,1)));
00252                 else
00253                 {
00254                     //Extract attributes
00255                     $a2=explode(' ',$e);
00256                     $tag=strtoupper(array_shift($a2));
00257                     $attr=array();
00258                     foreach($a2 as $v)
00259                         if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
00260                             $attr[strtoupper($a3[1])]=$a3[2];
00261                     $this->OpenTag($tag,$attr);
00262                 }
00263             }
00264         }
00265     }
00266 
00273     public function OpenTag($tag,$attr)
00274     {
00275         //Opening tag
00276         if($tag=='B' or $tag=='I' or $tag=='U')
00277             $this->SetStyle($tag,true);
00278         if($tag=='A')
00279             $this->HREF=$attr['HREF'];
00280         if($tag=='BR')
00281             $this->Ln(5);
00282     }
00283 
00289     public function CloseTag($tag)
00290     {
00291         //Closing tag
00292         if($tag=='B' or $tag=='I' or $tag=='U')
00293             $this->SetStyle($tag,false);
00294         if($tag=='A')
00295             $this->HREF='';
00296     }
00297 
00304     public function SetStyle($tag,$enable)
00305     {
00306         //Modify style and select corresponding font
00307         $this->$tag+=($enable ? 1 : -1);
00308         $style='';
00309         foreach(array('B','I','U') as $s)
00310             if($this->$s>0)
00311                 $style.=$s;
00312         $this->SetFont('',$style);
00313     }
00314 
00321     public function PutLink($URL,$txt)
00322     {
00323         //Put a hyperlink
00324         $this->SetTextColor(0,0,255);
00325         $this->SetStyle('U',true);
00326         $this->Write(5,$txt,$URL);
00327         $this->SetStyle('U',false);
00328         $this->SetTextColor(0);
00329     }
00330 
00345     public function Text($x,$y,$txt, $stroke=0, $clip=false)
00346     {
00347         // replaces some special code to chars
00348         $txt = str_replace( "&nbsp;", " ", $txt);
00349         $txt = str_replace( "&auml;", "ä", $txt);
00350         $txt = str_replace( "&ouml;", "ö", $txt);
00351         $txt = str_replace( "&uuml;", "ü", $txt);
00352         $txt = str_replace( "&Auml;", "Ä", $txt);
00353         $txt = str_replace( "&Ouml;", "Ö", $txt);
00354         $txt = str_replace( "&Uuml;", "Ü", $txt);
00355         $txt = str_replace( "&szlig;", "ß", $txt);
00356 
00357         // replacing html specific codes
00358 
00359         // if this doesn't help, we should create own entity table
00360         // and replace codes to symbols
00361         $txt = html_entity_decode($txt);
00362 
00363         // cleaning up possible html code
00364         $txt = strip_tags($txt);
00365 
00366         //parent::Text($x,$y,$txt, $stroke, $clip);
00367         parent::Text($x,$y,$txt);
00368     }
00369 
00382     public function SetFont($family, $style='', $size=0, $fontfile='')
00383     {
00384         if ( $family == 'Arial' ) {
00385             // overriding standard ..
00386             $family = oxConfig::getInstance()->isUtf() ? 'freesans' : '';
00387         }
00388 
00389         parent::SetFont($family, $style, $size, $fontfile);
00390     }
00391 
00392 }

Generated on Wed May 13 13:25:51 2009 for OXID eShop CE by  doxygen 1.5.5