function _print_pdf_tcpdf 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_tcpdf()
- 5.3 print_pdf/print_pdf.pages.inc \_print_pdf_tcpdf()
- 6 print_pdf/print_pdf.pages.inc \_print_pdf_tcpdf()
- 7 print_pdf/print_pdf.pages.inc \_print_pdf_tcpdf()
Generate the PDF file using the TCPDF 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_tcpdf()
- print_pdf_generate_html in print_pdf/
print_pdf.pages.inc
File
- print_pdf/
print_pdf.pages.inc, line 240
Code
function _print_pdf_tcpdf($print, $html, $filename = NULL) {
global $base_url, $language;
$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);
$pdf_tool_path = realpath(dirname($print_pdf_pdf_tool));
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
define('K_PATH_MAIN', dirname($_SERVER['SCRIPT_FILENAME']));
define('K_PATH_URL', $base_url);
define('K_PATH_FONTS', $pdf_tool_path . '/fonts/');
define('K_PATH_CACHE', $pdf_tool_path . '/cache/');
define('K_PATH_IMAGES', '');
define('K_BLANK_IMAGE', $pdf_tool_path . '/images/_blank.png');
define('K_CELL_HEIGHT_RATIO', 1.25);
define('K_SMALL_RATIO', 2 / 3);
}
// Try to use local file access for image files
$html = _print_pdf_file_access_images($html);
// Decode HTML entities in image filenames
$pattern = "!<img\\s[^>]*?src\\s*?=\\s*?['\"]?{$base_url}[^>]*?>!is";
$html = preg_replace_callback($pattern, create_function('$matches', 'return html_entity_decode($matches[0], ENT_QUOTES);'), $html);
// Remove queries from the image URL
$pattern = "!(<img\\s[^>]*?src\\s*?=\\s*?['\"]?{$base_url}[^>]*?)(?:%3F|\\?)[\\w=&]+([^>]*?>)!is";
$html = preg_replace($pattern, '$1$2', $html);
require_once $print_pdf_pdf_tool;
if (strpos(PDF_PRODUCER, 'PHP4') === FALSE) {
require_once drupal_get_path('module', 'print_pdf') . '/print_pdf.class.inc';
}
else {
require_once drupal_get_path('module', 'print_pdf') . '/print_pdf.class_php4.inc';
}
$font = array(
check_plain(variable_get('print_pdf_font_family', PRINT_PDF_FONT_FAMILY_DEFAULT)),
'',
check_plain(variable_get('print_pdf_font_size', PRINT_PDF_FONT_SIZE_DEFAULT)),
);
$orientation = drupal_strtoupper($print_pdf_page_orientation[0]);
// create new PDF document
$pdf = new PrintTCPDF($orientation, 'mm', $print_pdf_paper_size, TRUE);
// set document information
$pdf
->SetAuthor(strip_tags($print['submitted']));
$pdf
->SetCreator(variable_get('site_name', 'Drupal'));
$pdf
->SetTitle(html_entity_decode($print['title'], ENT_QUOTES, 'UTF-8'));
$keys = implode(' ', explode("\n", trim(strip_tags($print['taxonomy']))));
$pdf
->SetKeywords($keys);
$pdf
->setPDFVersion('1.6');
$pdf
->setFontSubsetting(variable_get('print_pdf_font_subsetting', FALSE));
if ($language->direction == LANGUAGE_RTL) {
$pdf
->setRTL(TRUE);
}
$pdf = theme('print_pdf_tcpdf_header', $pdf, $html, $font);
$pdf = theme('print_pdf_tcpdf_footer', $pdf, $html, $font);
$pdf = theme('print_pdf_tcpdf_page', $pdf);
//initialize document
$pdf
->AliasNbPages();
// add a page
$pdf
->AddPage();
$pdf = theme('print_pdf_tcpdf_content', $pdf, $html, $font);
// reset pointer to the last page
$pdf
->lastPage();
// try to recover from any warning/error
ob_clean();
if ($filename) {
//Close and output PDF document
$output_dest = $print_pdf_content_disposition == 2 ? 'D' : 'I';
$pdf
->Output($filename, $output_dest);
return TRUE;
}
else {
return $pdf = $pdf
->Output('', 'S');
}
}