Commit e4e32e42 authored by jcnventura's avatar jcnventura

Issue #1230480: restrict CSS expansion to TCPDF.

parent a529b1bd
......@@ -10,6 +10,19 @@
define('PRINT_PDF_DOMPDF_UNICODE_DEFAULT', 0);
define('PRINT_PDF_DOMPDF_FONT_SUBSETTING_DEFAULT', FALSE);
/**
* Implements hook_pdf_tool_info().
*/
function print_pdf_dompdf_pdf_tool_info() {
return array(
'name' => 'dompdf',
'expand_css' => FALSE,
'write_dirs' => array(
'lib/fonts',
),
);
}
/**
* Implements hook_theme().
*/
......
......@@ -7,6 +7,21 @@
* @ingroup print
*/
/**
* Implements hook_pdf_tool_info().
*/
function print_pdf_mpdf_pdf_tool_info() {
return array(
'name' => 'mPDF',
'expand_css' => FALSE,
'write_dirs' => array(
'graph_cache',
'ttfontdata',
'tmp',
),
);
}
/**
* Implements hook_requirements().
*/
......
......@@ -11,6 +11,20 @@ define('PRINT_PDF_TCPDF_FONT_FAMILY_DEFAULT', 'dejavusans');
define('PRINT_PDF_TCPDF_FONT_SIZE_DEFAULT', 10);
define('PRINT_PDF_TCPDF_FONT_SUBSETTING_DEFAULT', FALSE);
/**
* Implements hook_pdf_tool_info().
*/
function print_pdf_tcpdf_pdf_tool_info() {
return array(
'name' => 'TCPDF',
'expand_css' => TRUE,
'write_dirs' => array(
'cache',
'images',
),
);
}
/**
* Implements hook_theme().
*/
......
......@@ -9,6 +9,17 @@
define('PRINT_PDF_WKHTMLTOPDF_OPTIONS', "--footer-font-size 7 --footer-right '[page]'");
/**
* Implements hook_pdf_tool_info().
*/
function print_pdf_wkhtmltopdf_pdf_tool_info() {
return array(
'name' => 'wkhtmltopdf',
'expand_css' => FALSE,
'write_dirs' => array(),
);
}
/**
* Implements hook_menu().
*/
......
......@@ -10,6 +10,31 @@
* @{
*/
/**
* Provide some information on the needs of the PDF library.
*
* @return
* Associative array with the following data:
* - name: name of the PDF library.
* - expand_css: boolean flag indicating whether to expand the CSS files
* in the HTML passed to the PDF library, or to leave it as a list of
* include directives.
* - write_dirs: directories to which the tool requires write-access.
*
* @ingroup print_hooks
*/
function hook_pdf_tool_info() {
return array(
'name' => 'foopdf',
'expand_css' => FALSE,
'write_dirs' => array(
'fonts',
'cache',
'tmp',
),
);
}
/**
* Generate a PDF version of the provided HTML.
*
......
......@@ -100,7 +100,15 @@ function print_pdf_generate_path($path, $cid = NULL, $pdf_filename = NULL) {
$link = print_pdf_print_link();
$node = print_controller($path, $link['format'], $cid);
if ($node) {
$html = theme('print', array('node' => $node, 'expand_css' => TRUE, 'format' => $link['format']));
// Call the current tool's hook_pdf_tool_info(), to see if we need to expand CSS
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
$function = $pdf_tool[0] . '_pdf_tool_info';
if (function_exists($function)) {
$info = $function();
}
$expand = isset($info['expand_css']) ? $info['expand_css'] : FALSE;
$html = theme('print', array('node' => $node, $expand, 'format' => $link['format']));
// Img elements must be set to absolute
$pattern = '!<(img\s[^>]*?)>!is';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment