OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxpdf.php
Go to the documentation of this file.
1 <?php
2 
4 
5 $sTcPdfPath = $myConfig->getConfigParam( 'sCoreDir' ) . "tcpdf/";
6 $sTcPdfUrl = $myConfig->getConfigParam( 'sShopURL') . "/" . $myConfig->getConfigParam( 'sCoreDir' ) . "tcpdf/";
7 
11 define ('K_TCPDF_EXTERNAL_CONFIG', 1 );
12 
17 define ('K_PATH_MAIN', $sTcPdfPath );
18 
23 define ('K_PATH_URL', $sTcPdfUrl );
24 
29 define ('K_PATH_FONTS', K_PATH_MAIN.'fonts/');
30 
34 define ('K_PATH_CACHE', K_PATH_MAIN.'cache/');
35 
39 define ('K_PATH_URL_CACHE', K_PATH_URL.'cache/');
40 
44 define ('K_PATH_IMAGES', K_PATH_MAIN.'images/');
45 
49 define ('K_BLANK_IMAGE', K_PATH_IMAGES.'_blank.png');
50 
54 define ('PDF_PAGE_FORMAT', 'A4');
55 
59 define ('PDF_PAGE_ORIENTATION', 'P');
60 
64 define ('PDF_CREATOR', 'TCPDF');
65 
69 define ('PDF_AUTHOR', 'TCPDF');
70 
74 define ('PDF_HEADER_TITLE', 'TCPDF Example');
75 
79 define ('PDF_HEADER_STRING', "by Nicola Asuni - Tecnick.com\nwww.tcpdf.org");
80 
84 define ('PDF_HEADER_LOGO', 'tcpdf_logo.jpg');
85 
89 define ('PDF_HEADER_LOGO_WIDTH', 30);
90 
94 define ('PDF_UNIT', 'mm');
95 
99 define ('PDF_MARGIN_HEADER', 5);
100 
104 define ('PDF_MARGIN_FOOTER', 10);
105 
109 define ('PDF_MARGIN_TOP', 27);
110 
114 define ('PDF_MARGIN_BOTTOM', 25);
115 
119 define ('PDF_MARGIN_LEFT', 15);
120 
124 define ('PDF_MARGIN_RIGHT', 15);
125 
129 define ('PDF_FONT_NAME_MAIN', 'helvetica');
130 
134 define ('PDF_FONT_SIZE_MAIN', 10);
135 
139 define ('PDF_FONT_NAME_DATA', 'helvetica');
140 
144 define ('PDF_FONT_SIZE_DATA', 8);
145 
149 define ('PDF_FONT_MONOSPACED', 'courier');
150 
154 define ('PDF_IMAGE_SCALE_RATIO', 1);
155 
159 define('HEAD_MAGNIFICATION', 1.1);
160 
164 define('K_CELL_HEIGHT_RATIO', 1.25);
165 
169 define('K_TITLE_MAGNIFICATION', 1.3);
170 
174 define('K_SMALL_RATIO', 2/3);
175 
179 require_once $sTcPdfPath . "config/lang/eng.php";
180 
184 require_once $sTcPdfPath . "tcpdf.php";
185 
189 class oxPDF extends TCPDF
190 {
206  public function __construct( $orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false )
207  {
209  $unicode = $myConfig->isUtf();
210  $encoding = $unicode ? 'UTF-8' : oxRegistry::getLang()->translateString( "charset" );
211  //#1161: Thin line and unknown characters on every pdf page
212  //we use myorder::pdfFooter()
213  $this->setPrintFooter(false);
214 
215  parent::__construct( $orientation, $unit, $format, $unicode, $encoding, $diskcache );
216  }
217 
235  public function WriteHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
236  {
237  //HTML parser
238  $html = str_replace( "\n", ' ', $html );
239  $a = preg_split('/<(.*)>/U', $html, -1, PREG_SPLIT_DELIM_CAPTURE );
240  foreach ($a as $i=>$e) {
241  if ($i%2==0) {
242  //Text
243  if ($this->HREF) {
244  $this->PutLink( $this->HREF, $e );
245  } else {
246  $this->Write( 5, $e );
247  }
248  } else {
249  //Tag
250  if ($e{0}=='/') {
251  $this->CloseTag(strtoupper(substr($e, 1)));
252  } else {
253  //Extract attributes
254  $a2=explode(' ', $e);
255  $tag=strtoupper(array_shift($a2));
256  $attr=array();
257  foreach ($a2 as $v) {
258  if (preg_match('/^([^=]*)=["\']?([^"\']*)["\']?$/', $v, $a3)) {
259  $attr[strtoupper($a3[1])]=$a3[2];
260  }
261  }
262  $this->OpenTag($tag, $attr);
263  }
264  }
265  }
266  }
267 
276  public function OpenTag($tag,$attr)
277  {
278  if ( $tag=='B' or $tag=='I' or $tag=='U' ) {
279  $this->SetStyle($tag, true);
280  }
281 
282  if ( $tag=='A' ) {
283  $this->HREF = (is_array($attr) && isset($attr['HREF'])) ? $attr['HREF'] : '';
284  }
285 
286  if ( $tag=='BR' ) {
287  $this->Ln(5);
288  }
289  }
290 
298  public function CloseTag($tag)
299  {
300  if ( $tag=='B' or $tag=='I' or $tag=='U' ) {
301  $this->SetStyle($tag, false);
302  }
303 
304  if ( $tag=='A' ) {
305  $this->HREF = '';
306  }
307  }
308 
317  public function SetStyle($tag,$enable)
318  {
319  $this->$tag+=($enable ? 1 : -1);
320  $style='';
321  foreach (array('B', 'I', 'U') as $s) {
322  if ($this->$s>0) {
323  $style.=$s;
324  }
325  }
326  $this->SetFont('', $style);
327  }
328 
337  public function PutLink($sURL, $sText)
338  {
339  $this->SetTextColor( 0, 0, 255 );
340  $this->SetStyle( 'U', true );
341  $this->Write( 5, $sText, $sURL );
342  $this->SetStyle( 'U', false );
343  $this->SetTextColor( 0 );
344  }
345 
358  public function SetFont($family, $style='', $size=0, $fontfile='')
359  {
360  if ( $family == 'Arial' ) {
361  // overriding standard ..
362  $family = oxRegistry::getConfig()->isUtf() ? 'freesans' : '';
363  }
364 
365  parent::SetFont($family, $style, $size, $fontfile);
366  }
367 
368 }