Révision a2baadd1
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/print/print_pdf/print_pdf.pages.inc | ||
---|---|---|
44 | 44 |
|
45 | 45 |
$pdf_filename = variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT); |
46 | 46 |
if (!empty($pdf_filename) && !empty($node)) { |
47 |
$pdf_filename = token_replace($pdf_filename, array('node' => $node)); |
|
47 |
$pdf_filename = token_replace($pdf_filename, array('node' => $node), array('clear' => TRUE));
|
|
48 | 48 |
} |
49 | 49 |
else { |
50 |
$pdf_filename = token_replace($pdf_filename, array('site')); |
|
51 |
if (empty($pdf_filename) || count(token_scan($pdf_filename))) {
|
|
52 |
// If there are still tokens, use a fallback solution
|
|
50 |
$pdf_filename = token_replace($pdf_filename, array('site'), array('clear' => TRUE));
|
|
51 |
if (empty($pdf_filename)) { |
|
52 |
// If empty, use a fallback solution
|
|
53 | 53 |
$pdf_filename = str_replace('/', '_', $path); |
54 | 54 |
} |
55 | 55 |
} |
... | ... | |
179 | 179 |
$print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT); |
180 | 180 |
|
181 | 181 |
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) { |
182 |
define("DOMPDF_ENABLE_PHP", FALSE); |
|
183 |
define("DOMPDF_ENABLE_REMOTE", TRUE); |
|
184 |
define("DOMPDF_TEMP_DIR", file_directory_temp()); |
|
185 |
define("DOMPDF_UNICODE_ENABLED", variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT)); |
|
186 |
define("DOMPDF_FONT_CACHE", drupal_realpath('public://' . PRINT_PDF_DOMPDF_CACHE_DIR_DEFAULT . '/fonts/')); |
|
182 |
if (!defined('DOMPDF_ENABLE_PHP')) define("DOMPDF_ENABLE_PHP", FALSE);
|
|
183 |
if (!defined('DOMPDF_ENABLE_REMOTE')) define("DOMPDF_ENABLE_REMOTE", TRUE);
|
|
184 |
if (!defined('DOMPDF_TEMP_DIR')) define("DOMPDF_TEMP_DIR", file_directory_temp());
|
|
185 |
if (!defined('DOMPDF_UNICODE_ENABLED')) define("DOMPDF_UNICODE_ENABLED", variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT));
|
|
186 |
if (!defined('DOMPDF_FONT_CACHE')) define("DOMPDF_FONT_CACHE", drupal_realpath('public://' . PRINT_PDF_DOMPDF_CACHE_DIR_DEFAULT . '/fonts/'));
|
|
187 | 187 |
} |
188 | 188 |
|
189 | 189 |
require_once(DRUPAL_ROOT . '/' . $print_pdf_pdf_tool); |
... | ... | |
235 | 235 |
} |
236 | 236 |
$html = htmlspecialchars_decode(htmlentities($html, ENT_NOQUOTES, 'ISO-8859-1'), ENT_NOQUOTES); |
237 | 237 |
} |
238 |
else { |
|
239 |
// Otherwise, ensure the content is properly formatted Unicode. |
|
240 |
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); |
|
241 |
} |
|
238 | 242 |
|
239 | 243 |
// Must get rid of tbody (dompdf goes into recursion) |
240 | 244 |
$html = preg_replace('!<tbody[^>]*?>|</tbody>!i', '', $html); |
... | ... | |
273 | 277 |
$pdf_tool_path = realpath(dirname($print_pdf_pdf_tool)); |
274 | 278 |
|
275 | 279 |
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) { |
276 |
define('K_TCPDF_EXTERNAL_CONFIG', TRUE); |
|
277 |
define('K_PATH_MAIN', dirname($_SERVER['SCRIPT_FILENAME'])); |
|
278 |
define('K_PATH_URL', $base_url); |
|
279 |
define('K_PATH_FONTS', $pdf_tool_path . '/fonts/'); |
|
280 |
define('K_PATH_CACHE', drupal_realpath('public://' . PRINT_PDF_TCPDF_CACHE_DIR_DEFAULT . '/cache/'));
|
|
281 |
define('K_PATH_IMAGES', ''); |
|
282 |
define('K_BLANK_IMAGE', $pdf_tool_path . '/images/_blank.png'); |
|
283 |
define('K_CELL_HEIGHT_RATIO', 1.25); |
|
284 |
define('K_SMALL_RATIO', 2/3); |
|
280 |
if (!defined('K_TCPDF_EXTERNAL_CONFIG')) define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
|
|
281 |
if (!defined('K_PATH_MAIN')) define('K_PATH_MAIN', dirname($_SERVER['SCRIPT_FILENAME']));
|
|
282 |
if (!defined('K_PATH_URL')) define('K_PATH_URL', $base_url);
|
|
283 |
if (!defined('K_PATH_FONTS')) define('K_PATH_FONTS', $pdf_tool_path . '/fonts/');
|
|
284 |
if (!defined('K_PATH_CACHE')) define('K_PATH_CACHE', drupal_realpath('public://' . PRINT_PDF_TCPDF_CACHE_DIR_DEFAULT . '/cache') . '/');
|
|
285 |
if (!defined('K_PATH_IMAGES')) define('K_PATH_IMAGES', '');
|
|
286 |
if (!defined('K_BLANK_IMAGE')) define('K_BLANK_IMAGE', $pdf_tool_path . '/images/_blank.png');
|
|
287 |
if (!defined('K_CELL_HEIGHT_RATIO')) define('K_CELL_HEIGHT_RATIO', 1.25);
|
|
288 |
if (!defined('K_SMALL_RATIO')) define('K_SMALL_RATIO', 2/3);
|
|
285 | 289 |
} |
286 | 290 |
|
287 | 291 |
// Try to use local file access for image files |
... | ... | |
291 | 295 |
$pattern = "!<img\s[^>]*?src\s*?=\s*?['\"]?{$base_url}[^>]*?>!is"; |
292 | 296 |
$html = preg_replace_callback($pattern, create_function('$matches', 'return html_entity_decode($matches[0], ENT_QUOTES);'), $html); |
293 | 297 |
// Remove queries from the image URL |
294 |
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?{$base_url}[^>]*?)(?:%3F|\?)[\w=&]+([^>]*?>)!is";
|
|
298 |
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?{$base_url}[^>]*?)(?:%3F|\?)[^\s'\"]+([^>]*?>)!is";
|
|
295 | 299 |
$html = preg_replace($pattern, '$1$2', $html); |
296 | 300 |
|
297 | 301 |
require_once(DRUPAL_ROOT . '/' . $print_pdf_pdf_tool); |
... | ... | |
315 | 319 |
$pdf->SetTitle(html_entity_decode($print['title'], ENT_QUOTES, 'UTF-8')); |
316 | 320 |
$pdf->setPDFVersion('1.6'); |
317 | 321 |
$pdf->setFontSubsetting(variable_get('print_pdf_font_subsetting', PRINT_PDF_FONT_SUBSETTING_DEFAULT)); |
322 |
$pdf->setTcpdfLink(false); |
|
318 | 323 |
|
319 | 324 |
if ($language->direction == LANGUAGE_RTL) { |
320 | 325 |
$pdf->setRTL(TRUE); |
... | ... | |
367 | 372 |
$dpi = 96; |
368 | 373 |
|
369 | 374 |
if (!empty($print_pdf_wkhtmltopdf_options)) { |
370 |
$print_pdf_wkhtmltopdf_options = token_replace($print_pdf_wkhtmltopdf_options, array('node' => $print['node'])); |
|
375 |
$print_pdf_wkhtmltopdf_options = token_replace($print_pdf_wkhtmltopdf_options, array('node' => $print['node']), array('clear' => TRUE));
|
|
371 | 376 |
} |
372 | 377 |
|
373 | 378 |
$version = _print_pdf_wkhtmltopdf_version(); |
... | ... | |
405 | 410 |
if (empty($error)) { |
406 | 411 |
$error = 'No stderr output available.'; |
407 | 412 |
} |
408 |
watchdog('print_pdf', "wkhtmltopdf (returned $retval): $error");
|
|
413 |
watchdog('print_pdf', 'wkhtmltopdf [%cmd] (returned %ret): %error', array('%cmd' => $cmd, '%ret' => $retval, '%error' => $error));
|
|
409 | 414 |
} |
410 | 415 |
} |
411 | 416 |
|
... | ... | |
431 | 436 |
} |
432 | 437 |
else { |
433 | 438 |
drupal_set_message(t('Unable to generate PDF file.'), 'error'); |
434 |
drupal_goto($meta['url']);
|
|
439 |
drupal_goto($print['url']);
|
|
435 | 440 |
return NULL; |
436 | 441 |
} |
437 | 442 |
} |
... | ... | |
445 | 450 |
*/ |
446 | 451 |
function theme_print_pdf_dompdf_footer($vars) { |
447 | 452 |
preg_match('!<div class="print-footer">(.*?)</div>!si', $vars['html'], $tpl_footer); |
448 |
$html = str_replace($tpl_footer[0], '', $vars['html']); |
|
449 | 453 |
|
450 |
$text = '<script type="text/php"> |
|
451 |
if (isset($pdf)) { |
|
452 |
$font = Font_Metrics::get_font("verdana");; |
|
453 |
$size = 10; |
|
454 |
$color = array(0,0,0); |
|
455 |
$text_height = Font_Metrics::get_font_height($font, $size); |
|
454 |
if (isset($tpl_footer[1])) { |
|
455 |
$html = str_replace($tpl_footer[0], '', $vars['html']); |
|
456 | 456 |
|
457 |
$w = $pdf->get_width(); |
|
458 |
$h = $pdf->get_height(); |
|
457 |
$text = '<script type="text/php"> |
|
458 |
if (isset($pdf)) { |
|
459 |
$font = Font_Metrics::get_font("verdana");; |
|
460 |
$size = 10; |
|
461 |
$color = array(0,0,0); |
|
462 |
$text_height = Font_Metrics::get_font_height($font, $size); |
|
459 | 463 |
|
460 |
$footer = $pdf->open_object(); |
|
464 |
$w = $pdf->get_width(); |
|
465 |
$h = $pdf->get_height(); |
|
461 | 466 |
|
462 |
// Draw a line along the bottom |
|
463 |
$y = $h - 25; |
|
464 |
$pdf->line(15, $y, $w - 15, $y, $color, 1); |
|
467 |
$footer = $pdf->open_object(); |
|
465 | 468 |
|
466 |
$y += $text_height / 2; |
|
467 |
$pdf->page_text(15, $y, \'' . addslashes(strip_tags($tpl_footer[1])) . '\', $font, $size, $color); |
|
469 |
// Draw a line along the bottom |
|
470 |
$y = $h - 25; |
|
471 |
$pdf->line(15, $y, $w - 15, $y, $color, 1); |
|
468 | 472 |
|
469 |
$pdf->close_object();
|
|
470 |
$pdf->add_object($footer, "all");
|
|
473 |
$y += $text_height / 2;
|
|
474 |
$pdf->page_text(15, $y, \'' . addslashes(strip_tags($tpl_footer[1])) . '\', $font, $size, $color);
|
|
471 | 475 |
|
472 |
// Center the text |
|
473 |
$width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size); |
|
474 |
$pagenumtxt = t("Page !n of !total", array("!n" => "{PAGE_NUM}", "!total" => "{PAGE_COUNT}")); |
|
475 |
$pdf->page_text($w - 15 - $width, $y, $pagenumtxt, $font, $size, $color); |
|
476 |
} |
|
477 |
</script>'; |
|
476 |
$pdf->close_object(); |
|
477 |
$pdf->add_object($footer, "all"); |
|
478 | 478 |
|
479 |
return str_replace("<body>", "<body>" . $text, $html); |
|
479 |
// Center the text |
|
480 |
$width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size); |
|
481 |
$pagenumtxt = t("Page !n of !total", array("!n" => "{PAGE_NUM}", "!total" => "{PAGE_COUNT}")); |
|
482 |
$pdf->page_text($w - 15 - $width, $y, $pagenumtxt, $font, $size, $color); |
|
483 |
} |
|
484 |
</script>'; |
|
485 |
|
|
486 |
return str_replace("<body>", "<body>" . $text, $html); |
|
487 |
} else { |
|
488 |
return $vars['html']; |
|
489 |
} |
|
480 | 490 |
} |
481 | 491 |
|
482 | 492 |
/** |
... | ... | |
589 | 599 |
function theme_print_pdf_tcpdf_footer($vars) { |
590 | 600 |
$pdf = $vars['pdf']; |
591 | 601 |
preg_match('!<div class="print-footer">(.*?)</div>!si', $vars['html'], $tpl_footer); |
592 |
$footer = trim(preg_replace('!</?div[^>]*?>!i', '', $tpl_footer[1])); |
|
593 |
|
|
594 |
// set footer font |
|
595 |
$vars['font'][2] *= 0.8; |
|
596 |
$pdf->setFooterFont($vars['font']); |
|
597 |
// set footer margin |
|
598 |
$pdf->SetFooterMargin(10); |
|
599 |
// set footer data |
|
600 |
$pdf->SetFooterData($footer); |
|
602 |
if (isset($tpl_footer[1])) { |
|
603 |
$footer = trim(preg_replace('!</?div[^>]*?>!i', '', $tpl_footer[1])); |
|
604 |
|
|
605 |
// set footer font |
|
606 |
$vars['font'][2] *= 0.8; |
|
607 |
$pdf->setFooterFont($vars['font']); |
|
608 |
// set footer margin |
|
609 |
$pdf->SetFooterMargin(10); |
|
610 |
// set footer data |
|
611 |
$pdf->setFooterContent($footer); |
|
612 |
} |
|
601 | 613 |
|
602 | 614 |
return $pdf; |
603 | 615 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules