OXID eShop CE  4.10.7
 All Classes Namespaces 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 
191 class oxPDF extends TCPDF
192 {
193 
209  public function __construct($orientation = 'P', $unit = 'mm', $format = 'A4', $unicode = true, $encoding = 'UTF-8', $diskcache = false)
210  {
212  $unicode = $myConfig->isUtf();
213  $encoding = $unicode ? 'UTF-8' : oxRegistry::getLang()->translateString("charset");
214  //#1161: Thin line and unknown characters on every pdf page
215  //we use myorder::pdfFooter()
216  $this->setPrintFooter(false);
217 
218  parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache);
219  }
220 
237  public function WriteHTML($html, $ln = true, $fill = false, $reseth = false, $cell = false, $align = '')
238  {
239  //HTML parser
240  $html = str_replace("\n", ' ', $html);
241  $a = preg_split('/<(.*)>/U', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
242  foreach ($a as $i => $e) {
243  if ($i % 2 == 0) {
244  //Text
245  if ($this->HREF) {
246  $this->PutLink($this->HREF, $e);
247  } else {
248  $this->Write(5, $e);
249  }
250  } else {
251  //Tag
252  if ($e{0} == '/') {
253  $this->CloseTag(strtoupper(substr($e, 1)));
254  } else {
255  //Extract attributes
256  $a2 = explode(' ', $e);
257  $tag = strtoupper(array_shift($a2));
258  $attr = array();
259  foreach ($a2 as $v) {
260  if (preg_match('/^([^=]*)=["\']?([^"\']*)["\']?$/', $v, $a3)) {
261  $attr[strtoupper($a3[1])] = $a3[2];
262  }
263  }
264  $this->OpenTag($tag, $attr);
265  }
266  }
267  }
268  }
269 
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 
296  public function CloseTag($tag)
297  {
298  if ($tag == 'B' or $tag == 'I' or $tag == 'U') {
299  $this->SetStyle($tag, false);
300  }
301 
302  if ($tag == 'A') {
303  $this->HREF = '';
304  }
305  }
306 
313  public function SetStyle($tag, $enable)
314  {
315  $this->$tag += ($enable ? 1 : -1);
316  $style = '';
317  foreach (array('B', 'I', 'U') as $s) {
318  if ($this->$s > 0) {
319  $style .= $s;
320  }
321  }
322  $this->SetFont('', $style);
323  }
324 
331  public function PutLink($sURL, $sText)
332  {
333  $this->SetTextColor(0, 0, 255);
334  $this->SetStyle('U', true);
335  $this->Write(5, $sText, $sURL);
336  $this->SetStyle('U', false);
337  $this->SetTextColor(0);
338  }
339 
350  public function SetFont($family, $style = '', $size = 0, $fontfile = '')
351  {
352  if ($family == 'Arial') {
353  // overriding standard ..
354  $family = oxRegistry::getConfig()->isUtf() ? 'freesans' : '';
355  }
356 
357  parent::SetFont($family, $style, $size, $fontfile);
358  }
359 }