Issue #938838 by pillarsdotnet: disable TCPDF font subsetting by default
[project/print.git] / print_pdf / print_pdf.pages.inc
1 <?php
2
3 /**
4 * @file
5 * Generates the PDF versions of the pages
6 *
7 * This file is included by the print_pdf module and includes the
8 * functions that interface with the PDF generation packages.
9 *
10 * @ingroup print
11 */
12
13 require_once(drupal_get_path('module', 'print') .'/print.pages.inc');
14
15 /**
16 * Generate a PDF version of the printer-friendly page
17 *
18 * @see print_controller()
19 * @see _print_pdf_dompdf()
20 * @see _print_pdf_tcpdf()
21 */
22 function print_pdf_controller() {
23 global $base_url;
24
25 // Disable caching for generated PDFs, as Drupal doesn't ouput the proper headers from the cache
26 $GLOBALS['conf']['cache'] = FALSE;
27
28 $args = func_get_args();
29 $path = implode('/', $args);
30 $cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
31
32 $print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
33
34 $print = print_controller($path, $cid, PRINT_PDF_FORMAT);
35 if ($print === FALSE) {
36 return;
37 }
38
39 // Img elements must be set to absolute
40 $pattern = '!<(img\s[^>]*?)>!is';
41 $print['content'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['content']);
42 $print['logo'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['logo']);
43 $print['footer_message'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['footer_message']);
44
45 // Send to printer option causes problems with PDF
46 $print['sendtoprinter'] = '';
47
48 $node = $print['node'];
49 $html = theme('print_page', $print, PRINT_PDF_FORMAT, $node);
50 $html = drupal_final_markup($html);
51
52 // Convert the a href elements, to make sure no relative links remain
53 $pattern = '!<(a\s[^>]*?)>!is';
54 $html = preg_replace_callback($pattern, '_print_rewrite_urls', $html);
55 // And make anchor links relative again, to permit in-PDF navigation
56 $html = preg_replace("!${base_url}/". PRINTPDF_PATH ."/.*?%2523!", '#', $html);
57
58 $pdf_filename = variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT);
59 if (function_exists('token_replace') && !empty($pdf_filename)) {
60 $pdf_filename = token_replace($pdf_filename, 'node', $node) .'.pdf';
61 }
62 else {
63 $pdf_filename = str_replace('/', '_', $path) .'.pdf';
64 }
65 if (function_exists('transliteration_clean_filename')) {
66 $pdf_filename = transliteration_clean_filename($pdf_filename, language_default('language'));
67 }
68
69 if (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
70 _print_pdf_dompdf($print, $html, $pdf_filename);
71 }
72 elseif (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
73 _print_pdf_tcpdf($print, $html, $pdf_filename);
74 }
75 elseif (substr(basename($print_pdf_pdf_tool, '.exe'), 0, 11) == 'wkhtmltopdf') {
76 _print_pdf_wkhtmltopdf($print, $html, $pdf_filename);
77 }
78 else {
79 return drupal_not_found();
80 }
81
82 $nodepath = (isset($node->path)) ? drupal_get_normal_path($node->path) : 'node/'. $path;
83 db_query("UPDATE {print_pdf_page_counter} SET totalcount = totalcount + 1, timestamp = %d WHERE path = '%s'", time(), $nodepath);
84 // If we affected 0 rows, this is the first time viewing the node.
85 if (!db_affected_rows()) {
86 // We must create a new row to store counters for the new node.
87 db_query("INSERT INTO {print_pdf_page_counter} (path, totalcount, timestamp) VALUES ('%s', 1, %d)", $nodepath, time());
88 }
89 }
90
91 /**
92 * Convert image paths to the file:// protocol
93 *
94 * In some Drupal setups, the use of the 'private' filesystem or Apache's
95 * configuration prevent access to the images of the page. This function
96 * tries to circumnvent those problems by accessing files in the local
97 * filesystem.
98 *
99 * @param $html
100 * contents of the post-processed template already with the node data
101 * @see print_pdf_controller()
102 */
103 function _print_pdf_file_access_images($html) {
104 global $base_url, $language;
105
106 // And converted from private to public paths
107 switch (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE)) {
108 case LANGUAGE_NEGOTIATION_PATH_DEFAULT:
109 case LANGUAGE_NEGOTIATION_PATH:
110 $lang = $language->language;
111 break;
112 default:
113 $lang = '';
114 break;
115 }
116 $file_downloads = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC);
117 if ($file_downloads == FILE_DOWNLOADS_PRIVATE) {
118 $pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?system/files/([^>]*?>)!is";
119 $replacement = '$1file://'. realpath(file_directory_path()) .'/$2';
120 $html = preg_replace($pattern, $replacement, $html);
121 }
122 $pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?([^>]*?>)!is";
123 $replacement = '$1file://'. dirname($_SERVER['SCRIPT_FILENAME']) .'/$2';
124 $html = preg_replace($pattern, $replacement, $html);
125
126 return $html;
127 }
128
129 /**
130 * Generate the PDF file using the dompdf library
131 *
132 * @param $print
133 * array containing the configured data
134 * @param $html
135 * contents of the post-processed template already with the node data
136 * @param $filename
137 * name of the PDF file to be generated
138 * @see print_pdf_controller()
139 */
140 function _print_pdf_dompdf($print, $html, $filename) {
141 $print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
142 $print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
143 $print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
144 $print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
145
146 if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
147 define("DOMPDF_ENABLE_PHP", FALSE);
148 define("DOMPDF_ENABLE_REMOTE", TRUE);
149 define("DOMPDF_TEMP_DIR", file_directory_temp());
150 define("DOMPDF_UNICODE_ENABLED", variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT));
151 }
152
153 require_once($print_pdf_pdf_tool);
154 if (function_exists('spl_autoload_register')) {
155 spl_autoload_register('DOMPDF_autoload');
156 }
157
158 // Try to use local file access for image files
159 $html = _print_pdf_file_access_images($html);
160
161 // dompdf seems to have problems with something in system.css so let's not use it
162 $html = preg_replace('!<link.*?modules/system/system.css.*?/>!', '', $html);
163
164 $url_array = parse_url($print['url']);
165
166 $protocol = $url_array['scheme'] .'://';
167 $host = $url_array['host'];
168 $path = dirname($url_array['path']) .'/';
169
170 $dompdf = new DOMPDF();
171 $dompdf->set_base_path($path);
172 $dompdf->set_host($host);
173 $dompdf->set_paper(drupal_strtolower($print_pdf_paper_size), $print_pdf_page_orientation);
174 $dompdf->set_protocol($protocol);
175
176 // dompdf can't handle footers cleanly, so disable the following
177 // $html = theme('print_pdf_dompdf_footer', $html);
178
179 // If dompdf Unicode support is disabled, try to convert to ISO-8859-1 and then to HTML entities
180 if (!variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT)) {
181 // Convert the euro sign to an HTML entity
182 $html = str_replace('€', '&#0128;', $html);
183
184 // Convert from UTF-8 to ISO 8859-1 and then to HTML entities
185 if (function_exists('utf8_decode')) {
186 $html = utf8_decode($html);
187 }
188 // iconv fails silently when it encounters something that it doesn't know, so don't use it
189 // else if (function_exists('iconv')) {
190 // $html = iconv('UTF-8', 'ISO-8859-1', $html);
191 // }
192 elseif (function_exists('mb_convert_encoding')) {
193 $html = mb_convert_encoding($html, 'ISO-8859-1', 'UTF-8');
194 }
195 elseif (function_exists('recode_string')) {
196 $html = recode_string('UTF-8..ISO_8859-1', $html);
197 }
198 $html = htmlspecialchars_decode(htmlentities($html, ENT_NOQUOTES, 'ISO-8859-1'), ENT_NOQUOTES);
199 }
200
201 //must get rid of tbody (dompdf goes into recursion)
202 $html = preg_replace('!<tbody[^>]*?>|</tbody>!i', '', $html);
203
204 $dompdf->load_html($html);
205
206 $dompdf->render();
207 $dompdf->stream($filename, array('Attachment' => ($print_pdf_content_disposition == 2)));
208 }
209
210 /**
211 * Generate the PDF file using the TCPDF library
212 *
213 * @param $print
214 * array containing the configured data
215 * @param $html
216 * contents of the post-processed template already with the node data
217 * @param $filename
218 * name of the PDF file to be generated
219 * @see print_pdf_controller()
220 */
221 function _print_pdf_tcpdf($print, $html, $filename) {
222 global $base_url, $language;
223
224 $print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
225 $print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
226 $print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
227 $print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
228
229 $pdf_tool_path = realpath(dirname($print_pdf_pdf_tool));
230
231 if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
232 define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
233 define('K_PATH_MAIN', dirname($_SERVER['SCRIPT_FILENAME']));
234 define('K_PATH_URL', $base_url);
235 define('K_PATH_FONTS', $pdf_tool_path .'/fonts/');
236 define('K_PATH_CACHE', $pdf_tool_path .'/cache/');
237 define('K_PATH_IMAGES', '');
238 define('K_BLANK_IMAGE', $pdf_tool_path .'/images/_blank.png');
239 define('K_CELL_HEIGHT_RATIO', 1.25);
240 define('K_SMALL_RATIO', 2/3);
241 }
242
243 // Try to use local file access for image files
244 $html = _print_pdf_file_access_images($html);
245
246 // Decode HTML entities in image filenames
247 $pattern = "!<img\s[^>]*?src\s*?=\s*?['\"]?{$base_url}[^>]*?>!is";
248 $html = preg_replace_callback($pattern, create_function('$matches', 'return html_entity_decode($matches[0], ENT_QUOTES);'), $html);
249 // Remove queries from the image URL
250 $pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?{$base_url}[^>]*?)(?:%3F|\?)[\w=&]+([^>]*?>)!is";
251 $html = preg_replace($pattern, '$1$2', $html);
252
253 require_once($print_pdf_pdf_tool);
254 if (strpos(PDF_PRODUCER, 'PHP4') === FALSE) {
255 require_once(drupal_get_path('module', 'print_pdf') .'/print_pdf.class.inc');
256 }
257 else {
258 require_once(drupal_get_path('module', 'print_pdf') .'/print_pdf.class_php4.inc');
259 }
260
261 $font = Array(
262 check_plain(variable_get('print_pdf_font_family', PRINT_PDF_FONT_FAMILY_DEFAULT)),
263 '',
264 check_plain(variable_get('print_pdf_font_size', PRINT_PDF_FONT_SIZE_DEFAULT)),
265 );
266 $orientation = drupal_strtoupper($print_pdf_page_orientation[0]);
267
268 // create new PDF document
269 $pdf = new PrintTCPDF($orientation , 'mm', $print_pdf_paper_size, TRUE);
270
271 // set document information
272 $pdf->SetAuthor(strip_tags($print['submitted']));
273 $pdf->SetCreator(variable_get('site_name', 'Drupal'));
274 $pdf->SetTitle(html_entity_decode($print['title'], ENT_QUOTES, 'UTF-8'));
275 $keys = implode(' ', explode("\n", trim(strip_tags($print['taxonomy']))));
276 $pdf->SetKeywords($keys);
277 $pdf->setPDFVersion('1.6');
278 $pdf-setFontSubsetting(variable_get('print_pdf_tcpdf_subsetting',FALSE));
279
280 if ($language->direction == LANGUAGE_RTL) {
281 $pdf->setRTL(TRUE);
282 }
283
284 $pdf = theme('print_pdf_tcpdf_header', $pdf, $html, $font);
285 $pdf = theme('print_pdf_tcpdf_footer', $pdf, $html, $font);
286 $pdf = theme('print_pdf_tcpdf_page', $pdf);
287
288 //initialize document
289 $pdf->AliasNbPages();
290
291 // add a page
292 $pdf->AddPage();
293
294 $pdf = theme('print_pdf_tcpdf_content', $pdf, $html, $font);
295
296 // reset pointer to the last page
297 $pdf->lastPage();
298
299 // try to recover from any warning/error
300 ob_clean();
301
302 //Close and output PDF document
303 $output_dest = ($print_pdf_content_disposition == 2) ? 'D' : 'I';
304 $pdf->Output($filename, $output_dest);
305 }
306
307 /**
308 * Generate the PDF file using wkhtmltopdf
309 *
310 * @param $print
311 * array containing the configured data
312 * @param $html
313 * contents of the post-processed template already with the node data
314 * @param $filename
315 * name of the PDF file to be generated
316 * @see print_pdf_controller()
317 */
318 function _print_pdf_wkhtmltopdf($print, $html, $filename) {
319 $print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
320 $print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
321 $print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
322 $print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
323 $print_pdf_wkhtmltopdf_options = variable_get('print_pdf_wkhtmltopdf_options', PRINT_PDF_WKHTMLTOPDF_OPTIONS);
324
325 $dpi = 96;
326
327 if (function_exists('token_replace') && !empty($print_pdf_wkhtmltopdf_options)) {
328 $print_pdf_wkhtmltopdf_options = token_replace($print_pdf_wkhtmltopdf_options, 'node', $print['node']);
329 }
330
331 $version = _print_pdf_wkhtmltopdf_version();
332
333 // 0.10.0 beta2 identifies itself as 0.9.9
334 if (version_compare($version, '0.9.9', '>=')) {
335 $print_pdf_wkhtmltopdf_options = '--disable-local-file-access '. $print_pdf_wkhtmltopdf_options;
336 }
337 elseif (version_compare($version, '0.9.6', '>=')) {
338 $print_pdf_wkhtmltopdf_options = '--disallow-local-file-access '. $print_pdf_wkhtmltopdf_options;
339 }
340 else {
341 drupal_goto($print['url']);
342 exit;
343 }
344
345 $descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
346 $cmd = realpath($print_pdf_pdf_tool) ." --page-size $print_pdf_paper_size --orientation $print_pdf_page_orientation --dpi $dpi $print_pdf_wkhtmltopdf_options - -";
347
348 $process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
349
350 if (is_resource($process)) {
351 fwrite($pipes[0], $html);
352 fclose($pipes[0]);
353
354 $pdf = stream_get_contents($pipes[1]);
355 fclose($pipes[1]);
356
357 stream_set_blocking($pipes[2], 0);
358 $error = stream_get_contents($pipes[2]);
359 if (!empty($error)) {
360 watchdog('print_pdf', 'wkhtmltopdf: '. $error);
361 }
362 fclose($pipes[2]);
363
364 $retval = proc_terminate($process);
365 }
366
367 if (!empty($pdf)) {
368 if (headers_sent()) {
369 die("Unable to stream pdf: headers already sent");
370 }
371 header("Cache-Control: private");
372 header("Content-Type: application/pdf");
373
374 $attachment = ($print_pdf_content_disposition == 2) ? "attachment" : "inline";
375
376 header("Content-Disposition: $attachment; filename=\"$filename\"");
377
378 echo $pdf;
379 flush();
380 }
381 else {
382 drupal_goto($print['url']);
383 exit;
384 }
385 }
386
387 /**
388 * Format the dompdf footer contents
389 *
390 * @param $html
391 * contents of the body of the HTML from the original node
392 * @see theme_print_pdf_tcpdf_footer()
393 */
394 function theme_print_pdf_dompdf_footer($html) {
395 preg_match('!<div class="print-footer">(.*?)</div>!si', $html, $tpl_footer);
396 $html = str_replace($tpl_footer[0], '', $html);
397
398 $text = '<script type="text/php">
399 if (isset($pdf)) {
400 $font = Font_Metrics::get_font("verdana");;
401 $size = 10;
402 $color = array(0,0,0);
403 $text_height = Font_Metrics::get_font_height($font, $size);
404
405 $w = $pdf->get_width();
406 $h = $pdf->get_height();
407
408 $footer = $pdf->open_object();
409
410 // Draw a line along the bottom
411 $y = $h - 25;
412 $pdf->line(15, $y, $w - 15, $y, $color, 1);
413
414 $y += $text_height / 2;
415 $pdf->page_text(15, $y, \''. addslashes(strip_tags($tpl_footer[1])) .'\', $font, $size, $color);
416
417 $pdf->close_object();
418 $pdf->add_object($footer, "all");
419
420 // Center the text
421 $width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size);
422 $pagenumtxt = t("Page !n of !total", array("!n" => "{PAGE_NUM}", "!total" => "{PAGE_COUNT}"));
423 $pdf->page_text($w - 15 - $width, $y, $pagenumtxt, $font, $size, $color);
424 }
425 </script>';
426
427 return str_replace("<body>", "<body>" . $text, $html);
428 }
429
430 /**
431 * Format the TCPDF header
432 *
433 * @param $pdf
434 * current TCPDF object
435 * @param $html
436 * contents of the body of the HTML from the original node
437 * @param $font
438 * array with the font definition (font name, styles and size)
439 * @see theme_print_pdf_tcpdf_header()
440 */
441 function theme_print_pdf_tcpdf_header($pdf, $html, $font) {
442 preg_match('!<div class="print-logo">(.*?)</div>!si', $html, $tpl_logo);
443 preg_match('!<h1 class="print-title">(.*?)</h1>!si', $html, $tpl_title);
444 preg_match('!<div class="print-site_name">(.*?)</div>!si', $html, $tpl_site_name);
445
446 $ratio = 0;
447 $logo = '';
448 $logo_ret = preg_match('!src\s*=\s*(\'.*?\'|".*?"|[^\s]*)!i', $tpl_logo[1], $matches);
449 if ($logo_ret) {
450 $logo = trim($matches[1], '\'"');
451 $size = getimagesize($logo);
452 $ratio = $size ? ($size[0] / $size[1]) : 0;
453 }
454
455 // set header font
456 $pdf->setHeaderFont($font);
457 // set header margin
458 $pdf->SetHeaderMargin(5);
459 // set header data
460 $pdf->SetHeaderData($logo, 10 * $ratio, html_entity_decode($tpl_title[1], ENT_QUOTES, 'UTF-8'), strip_tags($tpl_site_name[1]));
461
462 return $pdf;
463 }
464
465 /**
466 * Format the TCPDF page settings (margins, etc)
467 *
468 * @param $pdf
469 * current TCPDF object
470 * @see theme_print_pdf_tcpdf_page()
471 */
472 function theme_print_pdf_tcpdf_page($pdf) {
473 // set margins
474 $pdf->SetMargins(15, 20, 15);
475 // set auto page breaks
476 $pdf->SetAutoPageBreak(TRUE, 15);
477 // set image scale factor
478 sscanf(PDF_PRODUCER, "TCPDF %d.%d.%d", $major, $minor, $build);
479 $imagescale = (($major >= 4) && ($minor >= 6) && ($build >= 2)) ? 1 : 4;
480 $pdf->setImageScale($imagescale);
481 // set image compression quality
482 $pdf->setJPEGQuality(100);
483
484 return $pdf;
485 }
486
487 /**
488 * Format the TCPDF page content
489 *
490 * @param $pdf
491 * current TCPDF object
492 * @param $html
493 * contents of the body of the HTML from the original node
494 * @param $font
495 * array with the font definition (font name, styles and size)
496 * @see theme_print_pdf_tcpdf_content()
497 */
498 function theme_print_pdf_tcpdf_content($pdf, $html, $font) {
499 // set content font
500 $pdf->setFont($font[0], $font[1], $font[2]);
501
502 preg_match('!<body.*?>(.*)</body>!sim', $html, $matches);
503 $pattern = '!(?:<div class="print-(?:logo|site_name|breadcrumb|footer)">.*?</div>|<hr class="print-hr" />)!si';
504 $matches[1] = preg_replace($pattern, '', $matches[1]);
505
506 // Make CCK fields look better
507 $matches[1] = preg_replace('!(<div class="field.*?>)\s*!sm', '$1', $matches[1]);
508 $matches[1] = preg_replace('!(<div class="field.*?>.*?</div>)\s*!sm', '$1', $matches[1]);
509 $matches[1] = preg_replace('!<div( class="field-label.*?>.*?)</div>!sm', '<strong$1</strong>', $matches[1]);
510
511 // Since TCPDF's writeHTML is so bad with <p>, do everything possible to make it look nice
512 $matches[1] = preg_replace('!<(?:p(|\s+.*?)/?|/p)>!i', '<br$1 />', $matches[1]);
513 $matches[1] = str_replace(array('<div', 'div>'), array('<span', 'span><br />'), $matches[1]);
514 do {
515 $prev = $matches[1];
516 $matches[1] = preg_replace('!(</span>)<br />(\s*?</span><br />)!s', '$1$2', $matches[1]);
517 } while ($prev != $matches[1]);
518
519 @$pdf->writeHTML($matches[1]);
520
521 return $pdf;
522 }
523
524 /**
525 * Format the TCPDF footer contents
526 *
527 * @param $pdf
528 * current TCPDF object
529 * @param $html
530 * contents of the body of the HTML from the original node
531 * @param $font
532 * array with the font definition (font name, styles and size)
533 * @see theme_print_pdf_tcpdf_footer()
534 */
535 function theme_print_pdf_tcpdf_footer($pdf, $html, $font) {
536 preg_match('!<div class="print-footer">(.*?)</div>!si', $html, $tpl_footer);
537 $footer = trim(preg_replace('!</?div[^>]*?>!i', '', $tpl_footer[1]));
538
539 // set footer font
540 $font[2] *= 0.8;
541 $pdf->setFooterFont($font);
542 // set footer margin
543 $pdf->SetFooterMargin(10);
544 // set footer data
545 $pdf->SetFooterData($footer);
546
547 return $pdf;
548 }
549
550 /**
551 * Format the TCPDF footer layout
552 *
553 * @param $pdf
554 * current TCPDF object
555 * @see theme_print_pdf_tcpdf_footer2()
556 */
557 function theme_print_pdf_tcpdf_footer2($pdf) {
558 //Position at 1.5 cm from bottom
559 $pdf->writeHTMLCell(0, 15, 15, -10, $pdf->footer, 0, 0, 0, TRUE, '');
560
561 $ormargins = $pdf->getOriginalMargins();
562 $pagenumtxt = t('Page !n of !total', array('!n' => $pdf->PageNo(), '!total' => $pdf->getAliasNbPages()));
563 //Print page number
564 if ($pdf->getRTL()) {
565 $pdf->SetX($ormargins['right']);
566 $pdf->Cell(0, 10, $pagenumtxt, 'T', 0, 'L');
567 }
568 else {
569 $pdf->SetX($ormargins['left']);
570 $pdf->Cell(0, 10, $pagenumtxt, 'T', 0, 'R');
571 }
572
573 return $pdf;
574 }