function _print_pdf_dompdf in Printer, email and PDF versions 5.x
Same name and namespace in other branches
- 5.4 print_pdf/print_pdf.pages.inc \_print_pdf_dompdf()
- 5.3 print_pdf/print_pdf.pages.inc \_print_pdf_dompdf()
- 6 print_pdf/print_pdf.pages.inc \_print_pdf_dompdf()
- 7 print_pdf/print_pdf.pages.inc \_print_pdf_dompdf()
Generate the PDF file using the dompdf library
Parameters
$print: array containing the configured data
$html: contents of the post-processed template already with the node data
$filename: name of the PDF file to be generated
See also
1 call to _print_pdf_dompdf()
- print_pdf_generate_html in print_pdf/
print_pdf.pages.inc
File
- print_pdf/
print_pdf.pages.inc, line 153
Code
function _print_pdf_dompdf($print, $html, $filename = NULL) {
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
$print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
$print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
$print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
define("DOMPDF_ENABLE_PHP", FALSE);
define("DOMPDF_ENABLE_REMOTE", TRUE);
define("DOMPDF_TEMP_DIR", file_directory_temp());
define("DOMPDF_UNICODE_ENABLED", variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT));
}
require_once $print_pdf_pdf_tool;
if (function_exists('spl_autoload_register')) {
spl_autoload_register('DOMPDF_autoload');
}
// Try to use local file access for image files
$html = _print_pdf_file_access_images($html);
// dompdf seems to have problems with something in system.css so let's not use it
$html = preg_replace('!<link.*?modules/system/system.css.*?/>!', '', $html);
$url_array = parse_url($print['url']);
$protocol = $url_array['scheme'] . '://';
$host = $url_array['host'];
$path = dirname($url_array['path']) . '/';
$dompdf = new DOMPDF();
$dompdf
->set_base_path($path);
$dompdf
->set_host($host);
$dompdf
->set_paper(drupal_strtolower($print_pdf_paper_size), $print_pdf_page_orientation);
$dompdf
->set_protocol($protocol);
// dompdf can't handle footers cleanly, so disable the following
// $html = theme('print_pdf_dompdf_footer', $html);
// If dompdf Unicode support is disabled, try to convert to ISO-8859-1 and then to HTML entities
if (!variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT)) {
// Convert the euro sign to an HTML entity
$html = str_replace('€', '€', $html);
// Convert from UTF-8 to ISO 8859-1 and then to HTML entities
if (function_exists('utf8_decode')) {
$html = utf8_decode($html);
}
elseif (function_exists('mb_convert_encoding')) {
$html = mb_convert_encoding($html, 'ISO-8859-1', 'UTF-8');
}
elseif (function_exists('recode_string')) {
$html = recode_string('UTF-8..ISO_8859-1', $html);
}
$html = htmlspecialchars_decode(htmlentities($html, ENT_NOQUOTES, 'ISO-8859-1'), ENT_NOQUOTES);
}
//must get rid of tbody (dompdf goes into recursion)
$html = preg_replace('!<tbody[^>]*?>|</tbody>!i', '', $html);
$dompdf
->load_html($html);
$dompdf
->render();
if ($filename) {
$dompdf
->stream($filename, array(
'Attachment' => $print_pdf_content_disposition == 2,
));
return TRUE;
}
else {
return $dompdf
->output();
}
}