updated print

This commit is contained in:
2019-01-27 14:52:28 +01:00
parent 0615369680
commit b764ef206e
73 changed files with 1809 additions and 1990 deletions

View File

@@ -2,17 +2,20 @@ dompdf support:
The dompdf tool produces results that are more faithful to the HTML
printer-friendly page. Good support of CSS 2.1 and partially CSS3.
1. Download dompdf from http://code.google.com/p/dompdf/downloads/list
1. Download dompdf from https://github.com/dompdf/dompdf/releases. Make
sure to download the full release zipfile. If you download only a source
code file, you will also need to download and install the php-font-lib.
2. Extract the contents of the downloaded package into one of the
supported paths.
3. Check if dompdf_config.inc.php fits your installation. In 99% of cases,
no changes are necessary, so just try to use it and only edit anything if
the PDF generation fails.
4. Grant write access to the lib/fonts directory to your webserver user.
5. If you're using dompdf-0.5.1, delete the dompdf.php file as it contains
a security vulnerability
6. If you're using dompdf-0.6 or later, you can try to enable the Unicode
support, but you'll need to add some Unicode fonts. See
3. If using dompdf 0.6 or 0.5, check if dompdf_config.inc.php fits your
installation. In 99% of cases, no changes are necessary, so just try to use
it and only edit anything if the PDF generation fails.
4. If using dompdf 0.6 or 0.5, delete the dompdf.php file as it contains a
security vulnerability. Delete also the index.php and www folder, as they are
not needed.
5. Grant write access to the lib/fonts directory to your webserver user.
6. If you're using dompdf 0.6, you can try to enable the Unicode support, but
you'll need to add some Unicode fonts. See
http://groups.google.com/group/dompdf/browse_thread/thread/9f7bc0162b04d5cf
for further info on this.
7. Check http://code.google.com/p/dompdf/ for further information.
7. Check https://dompdf.github.io/ for further information.

View File

@@ -2,15 +2,14 @@
/**
* @file
* drush integration for print_pdf_dompdf module PDF libraries download.
* Provide drush integration for print_pdf_dompdf module PDF libraries download.
*/
/**
* The PDF project download URL
* The PDF project download URL.
*/
// URI to the the latest dompdf version.. Hardcoded version unfortunately
define('DOMPDF_DOWNLOAD_URI', 'https://github.com/dompdf/dompdf/releases/download/v0.6.1/dompdf-0.6.1.zip');
// URI to the the latest dompdf version.
define('DOMPDF_DOWNLOAD_URI', 'https://api.github.com/repos/dompdf/dompdf/releases/latest');
/**
* Implements hook_drush_command().

View File

@@ -5,9 +5,8 @@ package = "Printer, email and PDF versions"
dependencies[] = print_pdf
configure = admin/config/user-interface/print/pdf/dompdf
; Information added by Drupal.org packaging script on 2014-04-02
version = "7.x-2.0"
; Information added by Drupal.org packaging script on 2018-10-05
version = "7.x-2.2"
core = "7.x"
project = "print"
datestamp = "1396426766"
datestamp = "1538760185"

View File

@@ -14,3 +14,33 @@ function print_pdf_dompdf_uninstall() {
variable_del('print_pdf_dompdf_unicode');
variable_del('print_pdf_dompdf_font_subsetting');
}
/**
* Implements hook_requirements().
*/
function print_pdf_dompdf_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
// On status report page, make sure that a PDF generation tool is selected.
case 'runtime':
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
$tool = explode('|', $print_pdf_pdf_tool);
if (is_array($tool) && ($tool[0] === 'print_pdf_dompdf')) {
$version = print_pdf_dompdf_pdf_tool_version($tool[1]);
// If version is older than 0.6.2, raise warning, except if if is
// disabled in config.
if ((version_compare($version, '0.6.2', '<')) && !variable_get('print_pdf_dompdf_secure_06', FALSE)) {
$requirements['print_pdf_dompdf'] = array(
'title' => $t('dompdf library'),
'value' => $t('Possibly insecure release'),
'description' => $t("dompdf versions prior to 0.6.2 are insecure. Make sure you run at least dompdf 0.6.2. If you are running dompdf 0.6.2, set print_pdf_dompdf_secure_06 to TRUE in settings.php to hide this warning."),
'severity' => REQUIREMENT_WARNING,
);
}
}
break;
}
return $requirements;
}

View File

@@ -16,7 +16,7 @@ define('PRINT_PDF_DOMPDF_FONT_SUBSETTING_DEFAULT', FALSE);
function print_pdf_dompdf_pdf_tool_info() {
return array(
'name' => 'dompdf',
'url' => 'http://code.google.com/p/dompdf/downloads/list',
'url' => 'https://github.com/dompdf/dompdf/releases/latest',
'expand_css' => FALSE,
'public_dirs' => array(
'fonts',
@@ -59,27 +59,49 @@ function print_pdf_dompdf_menu() {
* Implements hook_pdf_tool_version().
*/
function print_pdf_dompdf_pdf_tool_version($pdf_tool) {
require_once(DRUPAL_ROOT . '/' . $pdf_tool);
if (file_exists(DRUPAL_ROOT . '/' . $pdf_tool)) {
include_once DRUPAL_ROOT . '/' . $pdf_tool;
}
// Poor man's way to find dompdf version
if (!defined('DOMPDF_DIR')) {
return 'unknown';
}
elseif (!defined('DOMPDF_CHROOT')) {
return '0.5.1';
}
elseif (!defined('DOMPDF_FONT_CACHE')) {
return '0.5.2';
}
elseif (!defined('DOMPDF_LOG_OUTPUT_FILE')) {
return '0.6.0 beta1';
}
elseif (!defined('DOMPDF_ADMIN_USERNAME')) {
return '0.6.0 beta2';
if (basename($pdf_tool) == 'Dompdf.php') {
$dompdf_base = dirname(dirname($pdf_tool));
$version_file = $dompdf_base . '/VERSION';
if (file_exists($version_file)) {
// From 0.7.0 beta 3 onwards, there's a VERSION file.
return file_get_contents($version_file);
}
elseif (basename(dirname($pdf_tool)) === 'src') {
// The dompdf tool started using PSR-4 in 0.7.0 beta 2.
return '0.7.0 beta 2';
}
elseif (basename(dirname($pdf_tool)) === 'Dompdf') {
// In 0.7.0 beta 1, it was src/Dompdf/Dompdf.php.
return '0.7.0 beta 1';
}
}
else {
return '0.6.0 beta3';
// Poor man's way to find dompdf version pre 0.7.
if (defined('DOMPDF_ENABLE_AUTOLOAD')) {
// It is not possible to tell apart 0.6.0, 0.6.1 or 0.6.2.
return '0.6.0, or higher';
}
elseif (defined('DOMPDF_ADMIN_USERNAME')) {
return '0.6.0 beta3';
}
elseif (defined('DOMPDF_LOG_OUTPUT_FILE')) {
return '0.6.0 beta2';
}
elseif (defined('DOMPDF_FONT_CACHE')) {
return '0.6.0 beta1';
}
elseif (defined('DOMPDF_CHROOT')) {
return '0.5.2';
}
elseif (defined('DOMPDF_DIR')) {
return '0.5.1';
}
}
return 'unknown';
}
/**
@@ -87,9 +109,14 @@ function print_pdf_dompdf_pdf_tool_version($pdf_tool) {
*/
function print_pdf_dompdf_print_pdf_available_libs_alter(&$pdf_tools) {
module_load_include('inc', 'print', 'includes/print');
$tools = _print_scan_libs('dompdf', '!^dompdf_config.inc.php$!');
$tools = _print_scan_libs('dompdf', '!^(dompdf_config.inc.php|Dompdf.php)$!');
foreach ($tools as $tool) {
$pdf_tools['print_pdf_dompdf|' . $tool] = 'dompdf (' . dirname($tool) . ')';
if (basename($tool) == 'Dompdf.php') {
$pdf_tools['print_pdf_dompdf|' . $tool] = 'dompdf (' . dirname(dirname($tool)) . ')';
}
else {
$pdf_tools['print_pdf_dompdf|' . $tool] = 'dompdf (' . dirname($tool) . ')';
}
}
}

View File

@@ -2,10 +2,10 @@
/**
* @file
* Generates the PDF version using dompdf
* Generates the PDF version using dompdf.
*
* This file is included by the print_pdf_dompdf module and includes the
* functions that interface with the dompdf library
* functions that interface with the dompdf library.
*
* @ingroup print
*/
@@ -23,35 +23,80 @@ function print_pdf_dompdf_print_pdf_generate($html, $meta, $paper_size = NULL, $
if (empty($page_orientation)) {
$page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
}
$content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
$unicode = TRUE;
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$unicode = variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT);
$font_subsetting = variable_get('print_pdf_dompdf_font_subsetting', PRINT_PDF_DOMPDF_FONT_SUBSETTING_DEFAULT);
$unicode = variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT);
if (!defined('DOMPDF_ENABLE_PHP')) define('DOMPDF_ENABLE_PHP', FALSE);
if (!defined('DOMPDF_ENABLE_REMOTE')) define('DOMPDF_ENABLE_REMOTE', TRUE);
if (!defined('DOMPDF_TEMP_DIR')) define('DOMPDF_TEMP_DIR', file_directory_temp());
if (!defined('DOMPDF_UNICODE_ENABLED')) define('DOMPDF_UNICODE_ENABLED', $unicode);
if (!defined('DOMPDF_ENABLE_FONTSUBSETTING')) define('DOMPDF_ENABLE_FONTSUBSETTING', $font_subsetting);
if (!defined('DOMPDF_FONT_CACHE')) define('DOMPDF_FONT_CACHE', drupal_realpath('public://print_pdf/print_pdf_dompdf/fonts/'));
if (!defined('DOMPDF_ENABLE_PHP')) {
define('DOMPDF_ENABLE_PHP', FALSE);
}
if (!defined('DOMPDF_ENABLE_REMOTE')) {
define('DOMPDF_ENABLE_REMOTE', TRUE);
}
if (!defined('DOMPDF_TEMP_DIR')) {
define('DOMPDF_TEMP_DIR', file_directory_temp());
}
if (!defined('DOMPDF_UNICODE_ENABLED')) {
define('DOMPDF_UNICODE_ENABLED', $unicode);
}
if (!defined('DOMPDF_ENABLE_FONTSUBSETTING')) {
define('DOMPDF_ENABLE_FONTSUBSETTING', $font_subsetting);
}
if (!defined('DOMPDF_FONT_CACHE')) {
define('DOMPDF_FONT_CACHE', drupal_realpath('public://print_pdf/print_pdf_dompdf/fonts/'));
}
}
require_once(DRUPAL_ROOT . '/' . $pdf_tool[1]);
spl_autoload_register('DOMPDF_autoload');
$version = print_pdf_dompdf_pdf_tool_version($pdf_tool[1]);
if (version_compare($version, '0.7', '<')) {
// Version of dompdf is 0.6.* or 0.5.*.
if (version_compare($version, '0.6', '<')) {
// Version of dompdf is 0.5.
spl_autoload_register('DOMPDF_autoload');
}
// Earlier dompdf versions could generate xml errors. Tell libxml to
// hide them.
libxml_use_internal_errors(TRUE);
$dompdf = new DOMPDF();
}
else {
// Version of dompdf is >= 0.7.
$tool_path = dirname($pdf_tool[1]) . '/../autoload.inc.php';
if (file_exists($tool_path)) {
require_once $tool_path;
}
else {
watchdog('print_pdf', 'Configured PDF tool does not exist at path: %path', array('%path' => $tool_path), WATCHDOG_ERROR);
throw new Exception("Configured PDF tool does not exist, unable to generate PDF.");
}
// Try to use local file access for image files
$dompdf = new \Dompdf\Dompdf();
$unicode = TRUE;
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$dompdf->set_option('enable_php', FALSE);
$dompdf->set_option('enable_remote', TRUE);
$dompdf->set_option('temp_dir', file_directory_temp());
$dompdf->set_option('enable_font_subsetting', $font_subsetting);
$dompdf->set_option('font_cache', drupal_realpath('public://print_pdf/print_pdf_dompdf/fonts/'));
}
}
// Try to use local file access for image files.
$html = _print_access_images_via_file($html, $images_via_file);
// Remove all scripts due to security concerns.
$html = preg_replace('!<script(.*?)>(.*?)</script>!is', '', $html);
// Spaces in img URLs must be replaced with %20, when using external access
// Spaces in img URLs must be replaced with %20, when using external access.
if (!$images_via_file) {
$pattern = '!<(img\s[^>]*?)>!is';
$html = preg_replace_callback($pattern, '_print_replace_spaces', $html);
}
// dompdf seems to have problems with something in system.css so let's not use it
// It seems dompdf has problems with something in system.css, don't use it.
$html = preg_replace('!<link.*?modules/system/system.css.*?/>!', '', $html);
$url_array = parse_url($meta['url']);
@@ -60,28 +105,31 @@ function print_pdf_dompdf_print_pdf_generate($html, $meta, $paper_size = NULL, $
$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($paper_size), $page_orientation);
$dompdf->set_protocol($protocol);
// dompdf can't handle footers cleanly, so disable the following
// $html = theme('print_pdf_dompdf_footer', array('html' => $html));
// It seems dompdf can't handle footers cleanly, so disable the following.
/* $html = theme('print_pdf_dompdf_footer', array('html' => $html)); */
// If dompdf Unicode support is disabled, try to convert to ISO-8859-1 and then to HTML entities
// If dompdf Unicode support is disabled, try to convert to ISO-8859-1 and
// then to HTML entities.
if (!$unicode) {
// Convert the euro sign to an HTML entity
// Convert the euro sign to an HTML entity.
$html = str_replace('€', '&#0128;', $html);
// Convert from UTF-8 to ISO 8859-1 and then to HTML entities
// Convert from UTF-8 to ISO 8859-1 and then to HTML entities.
if (function_exists('utf8_decode')) {
$html = utf8_decode($html);
$html = utf8_decode($html);
}
// iconv fails silently when it encounters something that it doesn't know, so don't use it
// else if (function_exists('iconv')) {
// $html = iconv('UTF-8', 'ISO-8859-1', $html);
// }
// iconv fails silently when it encounters something that it doesn't know,
// so don't use it.
/*
else if (function_exists('iconv')) {
$html = iconv('UTF-8', 'ISO-8859-1', $html);
}
*/
elseif (function_exists('mb_convert_encoding')) {
$html = mb_convert_encoding($html, 'ISO-8859-1', 'UTF-8');
}
@@ -95,7 +143,7 @@ function print_pdf_dompdf_print_pdf_generate($html, $meta, $paper_size = NULL, $
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
}
// Must get rid of tbody (dompdf goes into recursion)
// Must get rid of tbody (dompdf goes into recursion).
$html = preg_replace('!<tbody[^>]*?>|</tbody>!i', '', $html);
$dompdf->load_html($html);
@@ -105,11 +153,11 @@ function print_pdf_dompdf_print_pdf_generate($html, $meta, $paper_size = NULL, $
}
/**
* Format the dompdf footer contents
* Format the dompdf footer contents.
*
* @param array $vars
* An associative array containing:
* - $html: contents of the body of the HTML from the original node
* - $html: contents of the body of the HTML from the original node.
*
* @return string
* customized HTML text
@@ -152,7 +200,8 @@ function theme_print_pdf_dompdf_footer($vars) {
</script>';
return str_replace("<body>", "<body>" . $text, $html);
} else {
}
else {
return $vars['html'];
}
}

View File

@@ -0,0 +1,8 @@
mPDF support:
1. Download mPDF from https://github.com/mpdf/mpdf/releases.
2. Extract the contents of the downloaded package into one of the
supported paths.
3. If using mPDF 7.0 or later don't forget to run 'composer install' in the
mpdf directory.
4. Check https://mpdf.github.io/ for further information.

View File

@@ -2,15 +2,14 @@
/**
* @file
* drush integration for print_pdf_mpdf module PDF libraries download.
* Provides drush integration for print_pdf_mpdf module PDF libraries download.
*/
/**
* The PDF project download URL
* The PDF project download URL.
*/
// URI to the the latest mpdf version.. Hardcoded version unfortunately
define('MPDF_DOWNLOAD_URI', 'http://mpdf1.com/repos/MPDF57.zip');
// URI to the the latest mpdf version.
define('MPDF_DOWNLOAD_URI', 'https://api.github.com/repos/mpdf/mpdf/releases/latest');
/**
* Implements hook_drush_command().

View File

@@ -4,9 +4,8 @@ core = 7.x
package = "Printer, email and PDF versions"
dependencies[] = print_pdf
; Information added by Drupal.org packaging script on 2014-04-02
version = "7.x-2.0"
; Information added by Drupal.org packaging script on 2018-10-05
version = "7.x-2.2"
core = "7.x"
project = "print"
datestamp = "1396426766"
datestamp = "1538760185"

View File

@@ -11,31 +11,47 @@
* Implements hook_pdf_tool_info().
*/
function print_pdf_mpdf_pdf_tool_info() {
return array(
$info = array(
'name' => 'mPDF',
'url' => 'http://www.mpdf1.com/mpdf/download',
'url' => 'https://github.com/mpdf/mpdf/releases/latest',
'expand_css' => FALSE,
'public_dirs' => array(
'ttfontdata',
'tmp',
),
'tool_dirs' => array(
'graph_cache',
),
);
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
if (!isset($pdf_tool[1]) || print_pdf_mpdf_pdf_tool_version($pdf_tool[1]) !== '>= 7.x') {
$info['tool_dirs'] = array(
'graph_cache',
);
}
return $info;
}
/**
* Implements hook_pdf_tool_version().
*/
function print_pdf_mpdf_pdf_tool_version($pdf_tool) {
require_once(DRUPAL_ROOT . '/' . $pdf_tool);
if (file_exists(DRUPAL_ROOT . '/' . $pdf_tool)) {
include_once DRUPAL_ROOT . '/' . $pdf_tool;
}
if (defined('mPDF_VERSION')) {
return mPDF_VERSION;
}
else {
return 'unknown';
// Version 7 of the mpdf library uses a composer autoloader.
// Also there no longer is a way to truly detect the library version, so
// this seems like the best alternative.
$mpdf_version_7_plus = strpos($pdf_tool, 'autoload.php') !== FALSE;
if ($mpdf_version_7_plus) {
return '>= 7.x';
}
else {
return 'unknown';
}
}
}
@@ -49,4 +65,12 @@ function print_pdf_mpdf_print_pdf_available_libs_alter(&$pdf_tools) {
foreach ($tools as $tool) {
$pdf_tools['print_pdf_mpdf|' . $tool] = 'mPDF (' . dirname($tool) . ')';
}
// mPDF >= 7.0 uses a composer autoloader.
$tools = _print_scan_libs('mpdf', '!^autoload.php$!');
foreach ($tools as $tool) {
if (preg_match('!mpdf.*?/vendor/autoload.php$!', $tool)) {
$pdf_tools['print_pdf_mpdf|' . $tool] = 'mPDF (' . dirname(dirname($tool)) . ')';
}
}
}

View File

@@ -2,10 +2,10 @@
/**
* @file
* Generates the PDF version using mPDF
* Generates the PDF version using mPDF.
*
* This file is included by the print_pdf_mpdf module and includes the
* functions that interface with the mPDF library
* functions that interface with the mPDF library.
*
* @ingroup print
*/
@@ -17,48 +17,80 @@ function print_pdf_mpdf_print_pdf_generate($html, $meta, $paper_size = NULL, $pa
module_load_include('inc', 'print', 'includes/print');
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
// Version 7 of the mpdf library uses a composer autoloader.
// Also there no longer is way to truly detect the library version, so this
// seems like the best alternative.
$mpdf_version_7_plus = strpos($pdf_tool[1], 'autoload.php') !== FALSE;
if (empty($paper_size)) {
$paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
}
if (empty($page_orientation)) {
$page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
}
$content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
if (!defined('_MPDF_TTFONTDATAPATH')) define('_MPDF_TTFONTDATAPATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/ttfontdata/'));
if (!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/tmp/'));
$config = array();
if ($mpdf_version_7_plus) {
$config['tempDir'] = drupal_realpath('public://print_pdf/print_pdf_mpdf/');
}
else {
// Deprecated since mpdf v7.x.
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
if (!defined('_MPDF_TTFONTDATAPATH')) {
define('_MPDF_TTFONTDATAPATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/ttfontdata/'));
}
if (!defined('_MPDF_TEMP_PATH')) {
define('_MPDF_TEMP_PATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/tmp/'));
}
}
}
require_once(DRUPAL_ROOT . '/' . $pdf_tool[1]);
$tool_path = DRUPAL_ROOT . '/' . $pdf_tool[1];
if (file_exists($tool_path)) {
require_once $tool_path;
}
else {
watchdog('print_pdf', 'Configured PDF tool does not exist at path: %path', array('%path' => $tool_path), WATCHDOG_ERROR);
throw new Exception("Configured PDF tool does not exist, unable to generate PDF.");
}
$format = ($page_orientation == "landscape") ? $paper_size . "-L" : $paper_size;
// Try to use local file access for image files
// Try to use local file access for image files.
$html = _print_access_images_via_file($html, $images_via_file);
// set document information
$mpdf = new mPDF('UTF-8', $format);
// Set document information.
if ($mpdf_version_7_plus) {
$config['mode'] = 'utf-8';
$config['format'] = $format;
$mpdf = new \Mpdf\Mpdf($config);
}
else {
$mpdf = new mPDF('UTF-8', $format);
}
$mpdf->SetAuthor(strip_tags($meta['name']));
if (isset($meta['name'])) {
$mpdf->SetAuthor(strip_tags($meta['name']));
}
$mpdf->SetCreator(variable_get('site_name', 'Drupal'));
/*
// Pulled from the HTML meta data
// $mpdf->SetTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
$mpdf->SetTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
// $keys = implode(' ', explode("\n", trim(strip_tags($print['taxonomy']))));
// $mpdf->SetKeywords($keys);
$keys = implode(' ', explode("\n", trim(strip_tags($print['taxonomy']))));
$mpdf->SetKeywords($keys);
// Encrypt the file and grant permissions to the user to copy and print
// No password is required to open the document
// Owner has full rights using the password "MyPassword"
// $mpdf->SetProtection(array('copy', 'print'), '', 'MyPassword');
// $mpdf->SetProtection(array('copy', 'print', 'print-highres'), '', '');
$mpdf->SetProtection(array('copy', 'print'), '', 'MyPassword');
$mpdf->SetProtection(array('copy', 'print', 'print-highres'), '', '');
*/
drupal_alter('print_pdf_mpdf', $mpdf, $html, $meta);
$mpdf->WriteHTML($html);
// try to recover from any warning/error
// Try to recover from any warning/error.
ob_clean();
return $mpdf->Output('', 'S');

View File

@@ -28,7 +28,7 @@ function print_pdf_tcpdf_settings() {
'#size' => 60,
'#maxlength' => 250,
'#description' => t('Set the font family to be used. Examples: %examples.', array('%examples' => 'helvetica, times, courier, dejavusans, dejavuserif, freesans, freeserif, freemono')) . '<br />' .
t("CAUTION: TCPDF embeds the complete font in the generated PDF. If you're not using Unicode, then helvetica or times are safe choices that will keep the PDF small. Unicode fonts can increase the size of the PDF to the 1MB region."),
t("CAUTION: TCPDF embeds the complete font in the generated PDF. If you're not using Unicode, then helvetica or times are safe choices that will keep the PDF small. Unicode fonts can increase the size of the PDF to the 1MB region."),
);
$form['settings']['print_pdf_font_size'] = array(
'#type' => 'textfield',
@@ -53,6 +53,11 @@ function print_pdf_tcpdf_settings() {
/**
* Form validation handler for print_pdf_tcpdf_settings().
*
* @param array $form
* Form.
* @param array $form_state
* Form state.
*
* @see print_pdf_tcpdf_settings()
* @ingroup forms
*/

View File

@@ -2,9 +2,9 @@
/**
* @file
* Extend the TCPDF class to be able to customize the Footer
* Extend the TCPDF class to be able to customize the Footer.
*
* This file is included by the _print_pdf_tcpdf function
* This file is included by the _print_pdf_tcpdf function.
*
* @ingroup print
*/
@@ -12,18 +12,31 @@
class PrintTCPDF extends TCPDF {
public $footer;
// Display invisible link at the bottom of all pages.
/**
* Display invisible link at the bottom of all pages.
*
* @param string $tcpdflink
* TCPDF link.
*/
public function setTcpdfLink($tcpdflink) {
$this->tcpdflink = $tcpdflink;
}
// Page footer data
/**
* Page footer data.
*
* @param string $arg
* Footer contents.
*/
public function setFooterContent($arg = '') {
$this->footer = $arg;
}
// Page footer
/**
* Page footer.
*/
public function Footer() {
theme('print_pdf_tcpdf_footer2', array('pdf' => $this));
}
}

View File

@@ -2,14 +2,13 @@
/**
* @file
* drush integration for print_pdf_tcpdf module PDF libraries download.
* Provides drush integration for print_pdf_tcpdf module PDF libraries download.
*/
/**
* The PDF project download URL
* The PDF project download URL.
*/
// TCPDF is in sourceforge, and nicely provides a link to the latest version
// TCPDF is in sourceforge, and nicely provides a link to the latest version.
define('TCPDF_DOWNLOAD_URI', 'http://sourceforge.net/projects/tcpdf/files/latest');
/**

View File

@@ -6,9 +6,8 @@ dependencies[] = print_pdf
files[] = print_pdf_tcpdf.class.inc
configure = admin/config/user-interface/print/pdf/tcpdf
; Information added by Drupal.org packaging script on 2014-04-02
version = "7.x-2.0"
; Information added by Drupal.org packaging script on 2018-10-05
version = "7.x-2.2"
core = "7.x"
project = "print"
datestamp = "1396426766"
datestamp = "1538760185"

View File

@@ -7,7 +7,7 @@
* @ingroup print
*/
define('PRINT_PDF_TCPDF_FONT_FAMILY_DEFAULT', 'dejavusans');
define('PRINT_PDF_TCPDF_FONT_FAMILY_DEFAULT', '');
define('PRINT_PDF_TCPDF_FONT_SIZE_DEFAULT', 10);
define('PRINT_PDF_TCPDF_FONT_SUBSETTING_DEFAULT', FALSE);
@@ -81,12 +81,14 @@ function print_pdf_tcpdf_menu() {
*/
function print_pdf_tcpdf_pdf_tool_version($pdf_tool) {
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
// prevent TCPDF default configs
// Prevent TCPDF default configs.
define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
}
require_once(DRUPAL_ROOT . '/' . $pdf_tool);
if (file_exists(DRUPAL_ROOT . '/' . $pdf_tool)) {
include_once DRUPAL_ROOT . '/' . $pdf_tool;
}
// Hide warnings, as some TCPDF constants may still be undefined
// Hide warnings, as some TCPDF constants may still be undefined.
if (class_exists('TCPDF')) {
@$pdf = new TCPDF();

View File

@@ -2,10 +2,10 @@
/**
* @file
* Generates the PDF version using TCPDF
* Generates the PDF version using TCPDF.
*
* This file is included by the print_pdf_tcpdf module and includes the
* functions that interface with the TCPDF library
* functions that interface with the TCPDF library.
*
* @ingroup print
*/
@@ -25,47 +25,71 @@ function print_pdf_tcpdf_print_pdf_generate($html, $meta, $paper_size = NULL, $p
if (empty($page_orientation)) {
$page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
}
$content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$pdf_tool_path = realpath(dirname($pdf_tool[1]));
if (!defined('K_TCPDF_EXTERNAL_CONFIG')) define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
if (!defined('K_PATH_MAIN')) define('K_PATH_MAIN', dirname($_SERVER['SCRIPT_FILENAME']));
if (!defined('K_PATH_URL')) define('K_PATH_URL', $base_url);
if (!defined('K_PATH_FONTS')) define('K_PATH_FONTS', $pdf_tool_path . '/fonts/');
if (!defined('K_PATH_CACHE')) define('K_PATH_CACHE', drupal_realpath('public://print_pdf/print_pdf_tcpdf/cache') . '/');
if (!defined('K_PATH_IMAGES')) define('K_PATH_IMAGES', '');
if (!defined('K_BLANK_IMAGE')) define('K_BLANK_IMAGE', $pdf_tool_path . '/images/_blank.png');
if (!defined('K_CELL_HEIGHT_RATIO')) define('K_CELL_HEIGHT_RATIO', 1.25);
if (!defined('K_SMALL_RATIO')) define('K_SMALL_RATIO', 2/3);
if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
}
if (!defined('K_PATH_MAIN')) {
define('K_PATH_MAIN', DRUPAL_ROOT);
}
if (!defined('K_PATH_URL')) {
define('K_PATH_URL', $base_url);
}
if (!defined('K_PATH_FONTS')) {
define('K_PATH_FONTS', $pdf_tool_path . '/fonts/');
}
if (!defined('K_PATH_CACHE')) {
define('K_PATH_CACHE', drupal_realpath('public://print_pdf/print_pdf_tcpdf/cache') . '/');
}
if (!defined('K_PATH_IMAGES')) {
define('K_PATH_IMAGES', '');
}
if (!defined('K_BLANK_IMAGE')) {
define('K_BLANK_IMAGE', $pdf_tool_path . '/images/_blank.png');
}
if (!defined('K_CELL_HEIGHT_RATIO')) {
define('K_CELL_HEIGHT_RATIO', 1.25);
}
if (!defined('K_SMALL_RATIO')) {
define('K_SMALL_RATIO', 2 / 3);
}
}
// Try to use local file access for image files
// Try to use local file access for image files.
$html = _print_access_images_via_file($html, $images_via_file);
// Decode HTML entities in image filenames
// 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
// Remove queries from the image URL.
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?{$base_url}[^>]*?)(?:%3F|\?)[^\s'\"]+([^>]*?>)!is";
$html = preg_replace($pattern, '$1$2', $html);
require_once(DRUPAL_ROOT . '/' . $pdf_tool[1]);
$tool_path = DRUPAL_ROOT . '/' . $pdf_tool[1];
if (file_exists($tool_path)) {
require_once $tool_path;
}
else {
watchdog('print_pdf', 'Configured PDF tool does not exist at path: %path', array('%path' => $tool_path), WATCHDOG_ERROR);
throw new Exception("Configured PDF tool does not exist, unable to generate PDF.");
}
module_load_include('inc', 'print_pdf_tcpdf', 'print_pdf_tcpdf.class');
$font = Array(
$font = array(
check_plain(variable_get('print_pdf_font_family', PRINT_PDF_TCPDF_FONT_FAMILY_DEFAULT)),
'',
check_plain(variable_get('print_pdf_font_size', PRINT_PDF_TCPDF_FONT_SIZE_DEFAULT)),
);
$orientation = drupal_strtoupper($page_orientation[0]);
// create new PDF document
$pdf = new PrintTCPDF($orientation , 'mm', $paper_size, TRUE);
// Create new PDF document.
$pdf = new PrintTCPDF($orientation, 'mm', $paper_size, TRUE);
// set document information
// Set document information.
if (isset($meta['name'])) {
$pdf->SetAuthor(strip_tags($meta['name']));
}
@@ -73,35 +97,48 @@ function print_pdf_tcpdf_print_pdf_generate($html, $meta, $paper_size = NULL, $p
$pdf->SetTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
$pdf->setPDFVersion('1.6');
$pdf->setFontSubsetting(variable_get('print_pdf_font_subsetting', PRINT_PDF_TCPDF_FONT_SUBSETTING_DEFAULT));
$pdf->setTcpdfLink(false);
$pdf->setTcpdfLink(FALSE);
if ($language->direction == LANGUAGE_RTL) {
$pdf->setRTL(TRUE);
}
$pdf = theme('print_pdf_tcpdf_header', array('pdf' => $pdf, 'html' => $html, 'font' => $font));
$pdf = theme('print_pdf_tcpdf_footer', array('pdf' => $pdf, 'html' => $html, 'font' => $font));
$pdf = theme('print_pdf_tcpdf_header', array(
'pdf' => $pdf,
'html' => $html,
'font' => $font,
));
$pdf = theme('print_pdf_tcpdf_footer', array(
'pdf' => $pdf,
'html' => $html,
'font' => $font,
));
$pdf = theme('print_pdf_tcpdf_page', array('pdf' => $pdf));
// Enable third-party module to alter the pdf object, via hook_print_pdf_tcpdf_alter()
// Enable third-party module to alter the pdf object, via
// hook_print_pdf_tcpdf_alter().
drupal_alter('print_pdf_tcpdf', $pdf, $html, $meta);
// add a page
// Add a page.
$pdf->AddPage();
$pdf = theme('print_pdf_tcpdf_content', array('pdf' => $pdf, 'html' => $html, 'font' => $font));
$pdf = theme('print_pdf_tcpdf_content', array(
'pdf' => $pdf,
'html' => $html,
'font' => $font,
));
// reset pointer to the last page
// Reset pointer to the last page.
$pdf->lastPage();
// try to recover from any warning/error
// Try to recover from any warning/error.
ob_clean();
return $pdf = $pdf->Output('', 'S');
}
/**
* Format the TCPDF header
* Format the TCPDF header.
*
* @param array $vars
* An associative array containing:
@@ -128,8 +165,8 @@ function theme_print_pdf_tcpdf_header($vars) {
if (isset($tpl_logo[1]) && preg_match('!src\s*=\s*(?:"(.*?)"|\'(.*?)\'|([^\s]*))!i', $tpl_logo[1], $logo_url)) {
$logo = $logo_url[1];
// Make logo relative again
$logo = preg_replace("!^$base_url(.*)!sm", dirname($_SERVER['SCRIPT_FILENAME']) . '$1', $logo);
// Make logo relative again.
$logo = preg_replace("!^$base_url(.*)!sm", DRUPAL_ROOT . '$1', $logo);
if (!empty($logo)) {
$size = getimagesize($logo);
@@ -137,22 +174,22 @@ function theme_print_pdf_tcpdf_header($vars) {
}
}
// set header font
// Set header font.
$pdf->setHeaderFont($vars['font']);
// set header margin
// Set header margin.
$pdf->setHeaderMargin(5);
// set header data
// Set header data.
$pdf->setHeaderData($logo, 10 * $ratio, html_entity_decode($tpl_title[1], ENT_QUOTES, 'UTF-8'), html_entity_decode(strip_tags($tpl_site_name[1]), ENT_QUOTES, 'UTF-8'));
return $pdf;
}
/**
* Format the TCPDF page settings (margins, etc)
* Format the TCPDF page settings (margins, etc).
*
* @param array $vars
* An associative array containing:
* - $pdf: current TCPDF object
* - $pdf: current TCPDF object.
*
* @return object
* modified PDF object
@@ -162,20 +199,20 @@ function theme_print_pdf_tcpdf_header($vars) {
*/
function theme_print_pdf_tcpdf_page($vars) {
$pdf = $vars['pdf'];
// set margins
// Set margins.
$pdf->SetMargins(15, 20, 15);
// set auto page breaks
// Set auto page breaks.
$pdf->SetAutoPageBreak(TRUE, 15);
// set image scale factor
// Set image scale factor.
$pdf->setImageScale(1);
// set image compression quality
// Set image compression quality.
$pdf->setJPEGQuality(100);
return $pdf;
}
/**
* Format the TCPDF page content
* Format the TCPDF page content.
*
* @param array $vars
* An associative array containing:
@@ -191,20 +228,20 @@ function theme_print_pdf_tcpdf_page($vars) {
*/
function theme_print_pdf_tcpdf_content($vars) {
$pdf = $vars['pdf'];
// set content font
// Set content font.
$pdf->setFont($vars['font'][0], $vars['font'][1], $vars['font'][2]);
// Remove the logo, published, breadcrumb and footer from the main content
// Remove the logo, published, breadcrumb and footer from the main content.
preg_match('!<body.*?>(.*)</body>!sim', $vars['html'], $matches);
$pattern = '!(?:<div class="print-(?:logo|site_name|breadcrumb|footer)">.*?</div>|<hr class="print-hr" />)!si';
$matches[1] = preg_replace($pattern, '', $matches[1]);
// Make CCK fields look better
// Make CCK fields look better.
$matches[1] = preg_replace('!(<div class="field.*?>)\s*!sm', '$1', $matches[1]);
$matches[1] = preg_replace('!(<div class="field.*?>.*?</div>)\s*!sm', '$1', $matches[1]);
$matches[1] = preg_replace('!<div( class="field-label.*?>.*?)</div>!sm', '<strong$1</strong>', $matches[1]);
// Since TCPDF's writeHTML is so bad with <p>, do everything possible to make it look nice
// Since TCPDF's writeHTML is so bad with <p>, try to make it look nice.
$matches[1] = preg_replace('!<(?:p(|\s+.*?)/?|/p)>!i', '<br$1 />', $matches[1]);
$matches[1] = str_replace(array('<div', 'div>'), array('<span', 'span><br />'), $matches[1]);
do {
@@ -218,7 +255,7 @@ function theme_print_pdf_tcpdf_content($vars) {
}
/**
* Format the TCPDF footer contents
* Format the TCPDF footer contents.
*
* @param array $vars
* An associative array containing:
@@ -239,12 +276,12 @@ function theme_print_pdf_tcpdf_footer($vars) {
if (isset($tpl_footer[1])) {
$footer = trim(preg_replace('!</?div[^>]*?>!i', '', $tpl_footer[1]));
// set footer font
// Set footer font.
$vars['font'][2] *= 0.8;
$pdf->setFooterFont($vars['font']);
// set footer margin
// Set footer margin.
$pdf->SetFooterMargin(10);
// set footer data
// Set footer data.
$pdf->setFooterContent($footer);
}
@@ -252,11 +289,11 @@ function theme_print_pdf_tcpdf_footer($vars) {
}
/**
* Format the TCPDF footer layout
* Format the TCPDF footer layout.
*
* @param array $vars
* An associative array containing:
* - $pdf: current TCPDF object
* - $pdf: current TCPDF object.
*
* @return object
* modified PDF object
@@ -266,12 +303,12 @@ function theme_print_pdf_tcpdf_footer($vars) {
*/
function theme_print_pdf_tcpdf_footer2($vars) {
$pdf = $vars['pdf'];
// Position at 1.5 cm from bottom
$pdf->writeHTMLCell(0, 15, 15, $pdf->getPageHeight()-15, $pdf->footer);
// Position at 1.5 cm from bottom.
$pdf->writeHTMLCell(0, 15, 15, $pdf->getPageHeight() - 15, $pdf->footer);
$ormargins = $pdf->getOriginalMargins();
$pagenumtxt = t('Page !n of !total', array('!n' => $pdf->PageNo(), '!total' => $pdf->getAliasNbPages()));
// Print page number
// Print page number.
if ($pdf->getRTL()) {
$pdf->SetX($ormargins['right']);
$pdf->Cell(0, 10, $pagenumtxt, 'T', 0, 'L');

View File

@@ -5,13 +5,11 @@ wkhtmltopdf support:
libraries in your site, which may present problems in shared hosting
environments. The best, if you can run it.
1. Download wkhtmltopdf from
http://code.google.com/p/wkhtmltopdf/downloads/list. You can choose to
download the source and compile it or simply download the static binary,
which doesn't require you to compile anything. Note that the compiled
version may require a running X server (static uses patched libs that can
work without one).
2. Place the wkhtmltopdf executable into one of the supported paths.
(usually sites/all/modules/print/lib). You can also place a symbolic link
to the executable.
1. Download wkhtmltopdf from http://wkhtmltopdf.org/downloads.html. You can
choose to download the source and compile it or simply download the installer
for your OS. Note that the compiled version may require a running X server
(the installers use patched libs that can work without one).
2. Place a symbolic link to the executable in one of the supported paths
(usually sites/all/libraries/wkhtmltopdf). Or if you can also place the
wkhtmltopdf executable directly into that folder.
3. Check http://code.google.com/p/wkhtmltopdf/ for further information.

View File

@@ -27,19 +27,21 @@ function print_pdf_wkhtmltopdf_settings() {
'#size' => 60,
'#maxlength' => 500,
'#default_value' => variable_get('print_pdf_wkhtmltopdf_options', PRINT_PDF_WKHTMLTOPDF_OPTIONS),
'#description' => t('(wkhtmltopdf only) Set any additional options to be passed to the wkhtmltopdf executable. Tokens may be used in these options (see list below).'),
'#description' => t('Set any additional options to be passed to the wkhtmltopdf executable. Tokens may be used in these options (see list below).'),
);
$form['settings']['print_pdf_wkhtmltopdf_use_input_file'] = array(
'#type' => 'checkbox',
'#title' => t('Use temporary input file'),
'#default_value' => variable_get('print_pdf_wkhtmltopdf_use_input_file', PRINT_PDF_WKHTMLTOPDF_USE_INPUT_FILE_DEFAULT),
'#description' => t('If you experience trouble when generating a PDF try to enable this feature to adjust the input handling.'),
);
if (module_exists('token')) {
$form['settings']['print_pdf_filename_patterns'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['settings']['print_pdf_filename_patterns']['descriptions'] = array(
'#theme' => 'token_tree',
'#token_types' => array('node'),
'#dialog' => TRUE,
);
}

View File

@@ -2,19 +2,19 @@
/**
* @file
* drush integration for print_pdf_wkhtmltopdf module PDF libraries download.
* Provides drush integration for print_pdf_wkhtmltopdf module.
*/
/**
* The PDF project download URL
* The PDF project download URL.
*/
// wkhtmltopdf is a binary, requiring a different download for each platform
define('WKHTMLTOPDF_AMD64_DOWNLOAD_URI', 'http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz');
define('WKHTMLTOPDF_I386_DOWNLOAD_URI', 'http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-linux-i386_0.12.0-03c001d.tar.xz');
define('WKHTMLTOPDF_WIN64_DOWNLOAD_URI', 'http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-win64_0.12.0-03c001d.exe');
define('WKHTMLTOPDF_WIN_DOWNLOAD_URI', 'http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-win32_0.12.0-03c001d.exe');
define('WKHTMLTOPDF_OSX_DOWNLOAD_URI', 'http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-OSX-0.10.0_rc2-static.tar.bz2');
// Since wkhtmltopdf is a binary, a different URL is required for each platform.
define('WKHTMLTOPDF_LNX64_DOWNLOAD_URI', 'https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz');
define('WKHTMLTOPDF_LNX32_DOWNLOAD_URI', 'https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-i386.tar.xz');
define('WKHTMLTOPDF_WIN64_DOWNLOAD_URI', 'https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.msvc2015-win64.exe');
define('WKHTMLTOPDF_WIN32_DOWNLOAD_URI', 'https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.msvc2015-win32.exe');
define('WKHTMLTOPDF_OSX64_DOWNLOAD_URI', 'https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.macos-cocoa.pkg');
define('WKHTMLTOPDF_OSX32_DOWNLOAD_URI', 'https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.macos-carbon.pkg');
/**
* Implements hook_drush_command().
@@ -36,14 +36,18 @@ function _print_pdf_wkhtmltopdf_drush_download_url() {
switch (drupal_substr(php_uname('s'), 0, 3)) {
case 'Lin':
$ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_AMD64_DOWNLOAD_URI : WKHTMLTOPDF_I386_DOWNLOAD_URI;
drush_log(dt('Please note that generic Linux builds are no longer being generated. See https://wkhtmltopdf.org/downloads.html.'), 'warning');
$ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_LNX64_DOWNLOAD_URI : WKHTMLTOPDF_LNX32_DOWNLOAD_URI;
break;
case 'Win':
$ret = WKHTMLTOPDF_WIN_DOWNLOAD_URI;
$ret = WKHTMLTOPDF_WIN32_DOWNLOAD_URI;
break;
case 'Dar':
$ret = WKHTMLTOPDF_OSX_DOWNLOAD_URI;
$ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_OSX64_DOWNLOAD_URI : WKHTMLTOPDF_OSX32_DOWNLOAD_URI;
break;
default:
drush_log(dt('wkhtmltopdf is not supported in this system, please choose another library.'), 'error');
break;

View File

@@ -5,9 +5,8 @@ package = "Printer, email and PDF versions"
dependencies[] = print_pdf
configure = admin/config/user-interface/print/pdf/wkhtmltopdf
; Information added by Drupal.org packaging script on 2014-04-02
version = "7.x-2.0"
; Information added by Drupal.org packaging script on 2018-10-05
version = "7.x-2.2"
core = "7.x"
project = "print"
datestamp = "1396426766"
datestamp = "1538760185"

View File

@@ -12,4 +12,37 @@
*/
function print_pdf_wkhtmltopdf_uninstall() {
variable_del('print_pdf_wkhtmltopdf_options');
variable_del('print_pdf_wkhtmltopdf_use_input_file');
variable_del('print_pdf_wkhtmltopdf_version');
}
/**
* Implements hook_requirements().
*/
function print_pdf_wkhtmltopdf_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
// On status report page, make sure that a PDF generation tool is selected.
case 'runtime':
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (!empty($print_pdf_pdf_tool)) {
$tool = explode('|', $print_pdf_pdf_tool);
if (is_file($tool[1]) && is_readable($tool[1])) {
if (drupal_substr(basename($tool[1], '.exe'), 0, 11) == 'wkhtmltopdf') {
if (function_exists('is_executable') && !is_executable($tool[1])) {
$requirements['print_pdf_wkhtmltopdf'] = array(
'title' => $t('wkhtmltopdf library'),
'value' => $t('Non-executable permissions'),
'description' => $t('You must modify the permissions of the wkhtmltopdf file (%file) to make it executable.', array('%file' => $tool[1])),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
}
break;
}
return $requirements;
}

View File

@@ -8,6 +8,8 @@
*/
define('PRINT_PDF_WKHTMLTOPDF_OPTIONS', "--footer-font-size 7 --footer-right '[page]'");
define('PRINT_PDF_WKHTMLTOPDF_VERSION_DEFAULT', '');
define('PRINT_PDF_WKHTMLTOPDF_USE_INPUT_FILE_DEFAULT', FALSE);
/**
* Implements hook_pdf_tool_info().
@@ -16,7 +18,7 @@ function print_pdf_wkhtmltopdf_pdf_tool_info() {
return array(
'name' => 'wkhtmltopdf',
'min_version' => '0.9.6',
'url' => 'http://code.google.com/p/wkhtmltopdf/downloads/list',
'url' => 'http://wkhtmltopdf.org/downloads.html',
'expand_css' => FALSE,
);
}
@@ -41,54 +43,49 @@ function print_pdf_wkhtmltopdf_menu() {
}
/**
* Implements hook_requirements().
* Implements hook_flush_caches().
*/
function print_pdf_wkhtmltopdf_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
// At runtime, make sure that a PDF generation tool is selected
case 'runtime':
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (!empty($print_pdf_pdf_tool)) {
$tool = explode('|', $print_pdf_pdf_tool);
if (is_file($tool[1]) && is_readable($tool[1])) {
if (drupal_substr(basename($tool[1], '.exe'), 0, 11) == 'wkhtmltopdf') {
if (function_exists('is_executable') && !is_executable($tool[1])) {
$requirements['print_pdf_wkhtmltopdf'] = array(
'title' => $t('wkhtmltopdf library'),
'value' => $t('Non-executable permissions'),
'description' => $t('You must modify the permissions of the wkhtmltopdf file (%file) to make it executable.', array('%file' => $tool[1])),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
}
break;
}
return $requirements;
function print_pdf_wkhtmltopdf_flush_caches() {
// Delete the cached version info during cache clear.
variable_del('print_pdf_wkhtmltopdf_version');
return array();
}
/**
* Implements hook_pdf_tool_version().
*/
function print_pdf_wkhtmltopdf_pdf_tool_version($pdf_tool) {
$descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
function print_pdf_wkhtmltopdf_pdf_tool_version($pdf_tool, $reset = TRUE) {
$version = variable_get('print_pdf_wkhtmltopdf_version', PRINT_PDF_WKHTMLTOPDF_VERSION_DEFAULT);
$cmd = '"' . realpath($pdf_tool) . '" --version';
$process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
if (is_resource($process)) {
$content = stream_get_contents($pipes[1]);
$out = preg_match('!.*?(\d+\.\d+\.\d+).*$!m', $content, $matches);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
$retval = proc_close($process);
if ($reset || empty($version)) {
// Ask the version information from the executable.
$descriptor = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
$cmd = '"' . realpath($pdf_tool) . '" --version';
$process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
if (is_resource($process)) {
$content = stream_get_contents($pipes[1]);
preg_match('!.*?(\d+\.\d+\.\d+).*$!m', $content, $matches);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
// Cache the results of this expensive operation.
variable_set('print_pdf_wkhtmltopdf_version', $matches[1]);
return ($matches[1]);
}
}
else {
// For performance sake, usually use the cached value.
return $version;
}
return ($matches[1]);
return 'unknown';
}
/**
@@ -98,8 +95,16 @@ function print_pdf_wkhtmltopdf_print_pdf_available_libs_alter(&$pdf_tools) {
module_load_include('inc', 'print', 'includes/print');
$tools = _print_scan_libs('wkhtmltopdf', '!^wkhtmltopdf!');
// See if there is a binary version of wkhtmltopdf available.
if (drupal_substr(php_uname('s'), 0, 3) !== 'Win') {
exec('export PATH="$PATH:/usr/local/bin" ; which wkhtmltopdf', $binary_output, $binary_status);
if (count($binary_output) > 0 && $binary_status == 0) {
$tools[] = $binary_output[0];
}
}
foreach ($tools as $tool) {
$version = print_pdf_wkhtmltopdf_pdf_tool_version($tool);
$version = print_pdf_wkhtmltopdf_pdf_tool_version($tool, TRUE);
$pdf_tools['print_pdf_wkhtmltopdf|' . $tool] = 'wkhtmltopdf ' . $version . ' (' . $tool . ')';
}

View File

@@ -2,10 +2,10 @@
/**
* @file
* Generates the PDF version using wkhtmltopdf
* Generates the PDF version using wkhtmltopdf.
*
* This file is included by the print_pdf_wkhtmltopdf module and includes the
* functions that interface with the wkhtmltopdf library
* functions that interface with the wkhtmltopdf library.
*
* @ingroup print
*/
@@ -21,7 +21,6 @@ function print_pdf_wkhtmltopdf_print_pdf_generate($html, $meta, $paper_size = NU
if (empty($page_orientation)) {
$page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
}
$content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$wkhtmltopdf_options = variable_get('print_pdf_wkhtmltopdf_options', PRINT_PDF_WKHTMLTOPDF_OPTIONS);
$dpi = 96;
@@ -30,9 +29,24 @@ function print_pdf_wkhtmltopdf_print_pdf_generate($html, $meta, $paper_size = NU
$wkhtmltopdf_options = token_replace($wkhtmltopdf_options, array('node' => $meta['node']), array('clear' => TRUE));
}
$version = print_pdf_wkhtmltopdf_pdf_tool_version($pdf_tool[1]);
// Build array of single quoted parts, and the same escaped.
preg_match_all("!'.+?'!", $wkhtmltopdf_options, $matches);
$quoted = array();
foreach ($matches[0] as $match) {
$quoted[escapeshellcmd($match)] = $match;
}
// 0.10.0 beta2 identifies itself as 0.9.9
// Prevent options that could result in execution of arbitrary commands.
$wkhtmltopdf_options = escapeshellcmd($wkhtmltopdf_options);
// Replace sections that were single quoted with original content.
foreach ($quoted as $search => $replace) {
$wkhtmltopdf_options = str_replace($search, $replace, $wkhtmltopdf_options);
}
$version = print_pdf_wkhtmltopdf_pdf_tool_version($pdf_tool[1], FALSE);
// 0.10.0 beta2 identifies itself as 0.9.9.
if (version_compare($version, '0.9.9', '>=')) {
$wkhtmltopdf_options = '--disable-local-file-access ' . $wkhtmltopdf_options;
}
@@ -44,19 +58,40 @@ function print_pdf_wkhtmltopdf_print_pdf_generate($html, $meta, $paper_size = NU
exit;
}
// use basic http authentication to fetch included CSS, etc
// Use basic http authentication to fetch included CSS, etc.
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
$wkhtmltopdf_options .= ' --username ' . check_plain($_SERVER['PHP_AUTH_USER']) . ' --password ' . check_plain($_SERVER['PHP_AUTH_PW']);
$wkhtmltopdf_options .= ' --username ' . escapeshellarg($_SERVER['PHP_AUTH_USER']) . ' --password ' . escapeshellarg($_SERVER['PHP_AUTH_PW']);
}
$descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'a'));
$cmd = '"' . realpath($pdf_tool[1]) . "\" --page-size $paper_size --orientation $page_orientation --dpi $dpi $wkhtmltopdf_options - -";
$use_input_file = variable_get('print_pdf_wkhtmltopdf_use_input_file', PRINT_PDF_WKHTMLTOPDF_USE_INPUT_FILE_DEFAULT);
if ($use_input_file) {
$temp_html = file_unmanaged_save_data($html, drupal_tempnam('temporary://', 'c_html_') . '.html', FILE_EXISTS_RENAME);
if ($temp_html === FALSE) {
watchdog('print_pdf', 'wkhtmltopdf: could not create temporary html file: %file', array('%file' => $temp_html));
drupal_goto($meta['url']);
return NULL;
}
$html_input_parameter = drupal_realpath($temp_html);
}
else {
$temp_html = '';
$html_input_parameter = '-';
}
$descriptor = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'a'),
);
$cmd = '"' . realpath($pdf_tool[1]) . "\" -q --page-size $paper_size --orientation $page_orientation --dpi $dpi $wkhtmltopdf_options $html_input_parameter -";
$process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
if (is_resource($process)) {
fwrite($pipes[0], $html);
fclose($pipes[0]);
if (!$use_input_file) {
fwrite($pipes[0], $html);
fclose($pipes[0]);
}
$pdf = stream_get_contents($pipes[1]);
fclose($pipes[1]);
@@ -70,11 +105,18 @@ function print_pdf_wkhtmltopdf_print_pdf_generate($html, $meta, $paper_size = NU
if (empty($error)) {
$error = 'No stderr output available.';
}
watchdog('print_pdf', 'wkhtmltopdf [%cmd] (returned %ret): %error', array('%cmd' => $cmd, '%ret' => $retval, '%error' => $error));
watchdog('print_pdf', 'wkhtmltopdf [%cmd] (returned %ret): %error',
array('%cmd' => $cmd, '%ret' => $retval, '%error' => $error));
}
}
if ($use_input_file) {
file_unmanaged_delete($temp_html);
}
if (!empty($pdf)) {
// Remove anything before actual PDF content.
$pdf = substr($pdf, strpos($pdf, '%PDF-'));
return $pdf;
}
else {

View File

@@ -23,7 +23,7 @@ function print_pdf_settings() {
$link = print_pdf_print_link();
$current_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
$pdf_tool_default = array_key_exists($current_pdf_tool, $pdf_tools) ? $current_pdf_tool : PRINT_PDF_PDF_TOOL_DEFAULT;
$pdf_tool_default = array_key_exists((string) $current_pdf_tool, $pdf_tools) ? $current_pdf_tool : PRINT_PDF_PDF_TOOL_DEFAULT;
$form['settings'] = array(
'#type' => 'fieldset',
@@ -41,7 +41,11 @@ function print_pdf_settings() {
$form['settings']['print_pdf_content_disposition'] = array(
'#type' => 'radios',
'#title' => t('Open PDF in'),
'#options' => array(t('Same browser window'), t('New browser window'), t('Save dialog')),
'#options' => array(
t('Same browser window'),
t('New browser window'),
t('Save dialog'),
),
'#default_value' => variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT),
'#description' => t("Select the desired method for opening the PDF in the user's browser."),
);
@@ -111,14 +115,9 @@ function print_pdf_settings() {
);
if (module_exists('token')) {
$form['settings']['print_pdf_filename_patterns'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['settings']['print_pdf_filename_patterns']['descriptions'] = array(
'#theme' => 'token_tree',
'#token_types' => array('node'),
'#dialog' => TRUE,
);
}
@@ -163,6 +162,11 @@ function print_pdf_settings() {
/**
* Form validation handler for print_pdf_settings().
*
* @param array $form
* Form.
* @param array $form_state
* Form state.
*
* @see print_pdf_settings()
* @ingroup forms
*/

View File

@@ -13,7 +13,7 @@
/**
* Provide some information on the needs of the PDF library.
*
* @return
* @return array
* Associative array with the following data:
* - name: name of the PDF library.
* - min_version: minimum version of the PDF library supported by the
@@ -47,7 +47,7 @@ function hook_pdf_tool_info() {
}
/**
* Find out the version of the PDF library
* Find out the version of the PDF library.
*
* @param string $pdf_tool
* Filename of the tool to be analysed.
@@ -55,8 +55,8 @@ function hook_pdf_tool_info() {
* @return string
* version number of the library
*/
function hook_pdf_tool_version() {
require_once(DRUPAL_ROOT . '/' . $pdf_tool);
function hook_pdf_tool_version($pdf_tool) {
require_once DRUPAL_ROOT . '/' . $pdf_tool;
return '1.0';
}
@@ -65,26 +65,26 @@ function hook_pdf_tool_version() {
* Generate a PDF version of the provided HTML.
*
* @param string $html
* HTML content of the PDF
* HTML content of the PDF.
* @param array $meta
* Meta information to be used in the PDF
* - url: original URL
* - name: author's name
* - title: Page title
* - node: node object
* - node: node object.
* @param string $paper_size
* (optional) Paper size of the generated PDF
* (optional) Paper size of the generated PDF.
* @param string $page_orientation
* (optional) Page orientation of the generated PDF
* (optional) Page orientation of the generated PDF.
*
* @return
* @return Object|null
* generated PDF page, or NULL in case of error
*
* @see print_pdf_controller_html()
* @ingroup print_hooks
*/
function hook_print_pdf_generate($html, $meta, $paper_size = NULL, $page_orientation = NULL) {
$pdf = new PDF();
$pdf = new PDF($meta, $paper_size, $page_orientation);
$pdf->writeHTML($html);
return $pdf->Output();
@@ -128,7 +128,7 @@ function hook_print_pdf_available_libs_alter(&$pdf_tools) {
* '.pdf' extension, as the module will do that automatically.
*
* @param string $pdf_filename
* current value of the pdf_filename variable, after processing tokens and
* Current value of the pdf_filename variable, after processing tokens and
* any transliteration steps.
* @param string $path
* original alias/system path of the page being converted to PDF.
@@ -136,7 +136,7 @@ function hook_print_pdf_available_libs_alter(&$pdf_tools) {
* @ingroup print_hooks
*/
function hook_print_pdf_filename_alter(&$pdf_filename, &$path) {
$pdf_filename = 'foo';
$pdf_filename = $path . 'foo';
}
/**

View File

@@ -2,7 +2,7 @@
/**
* @file
* drush integration for print_pdf module PDF libraries download.
* Provide drush integration for print_pdf module PDF libraries download.
*/
/**
@@ -23,21 +23,25 @@ function print_pdf_drush_command() {
'path' => dt('A path to the download folder. If omitted Drush will use the default location (@path).', array('@path' => 'sites/all/libraries')),
),
'aliases' => array('pdfdl'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT, // No site or config needed.
// No site or config needed.
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
);
return $items;
}
/**
* Implements of drush_hook_COMMAND_validate().
* Implements drush_hook_COMMAND_validate().
*/
function drush_print_pdf_download_validate($library = NULL) {
if (is_null($library)) {
$pdf_libs = array();
drush_command_invoke_all_ref('drush_pdf_libs_alter', $pdf_libs);
drush_set_error('DRUSH_PDFDL_MISSING_ARG', dt("Usage: drush !cmd <library>\nWhere <library> is one of the following: !libs\n\nTry 'drush !cmd --help' for more information.", array('!cmd' => 'print-pdf-download', '!libs' => implode(', ', array_keys($pdf_libs)))));
drush_set_error('DRUSH_PDFDL_MISSING_ARG', dt("Usage: drush !cmd <library>\nWhere <library> is one of the following: !libs\n\nTry 'drush !cmd --help' for more information.", array(
'!cmd' => 'print-pdf-download',
'!libs' => implode(', ', array_keys($pdf_libs)),
)));
}
}
@@ -45,7 +49,7 @@ function drush_print_pdf_download_validate($library = NULL) {
* Download and extract PDF archive.
*
* @param string $library
* library to download
* Library to download.
*/
function drush_print_pdf_download($library) {
$pdf_libs = array();

View File

@@ -5,9 +5,8 @@ package = "Printer, email and PDF versions"
dependencies[] = print
configure = admin/config/user-interface/print/pdf
; Information added by Drupal.org packaging script on 2014-04-02
version = "7.x-2.0"
; Information added by Drupal.org packaging script on 2018-10-05
version = "7.x-2.2"
core = "7.x"
project = "print"
datestamp = "1396426766"
datestamp = "1538760185"

View File

@@ -11,9 +11,7 @@
* Implements hook_enable().
*/
function print_pdf_enable() {
$t = get_t();
// Module weight
// Module weight.
db_update('system')
->fields(array(
'weight' => 2,
@@ -139,7 +137,98 @@ function print_pdf_schema() {
}
/**
* Remove hardcoded numeric deltas from all blocks
* Implements hook_requirements().
*/
function print_pdf_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
// At runtime, make sure that a PDF generation tool is selected.
case 'runtime':
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (empty($print_pdf_pdf_tool)) {
$requirements['print_pdf_tool'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('No PDF tool selected'),
'description' => $t('Please configure it in the !url.', array('!url' => l($t('PDF settings page'), 'admin/config/user-interface/print/pdf'))),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Tool is defined, get some data from it's handler module.
$tool = explode('|', $print_pdf_pdf_tool);
$function = $tool[0] . '_pdf_tool_info';
$info = function_exists($function) ? $function() : array();
// Is the file there?
if (!is_file($tool[1]) || !is_readable($tool[1])) {
$requirements['print_pdf_tool'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('File not found'),
'description' => $t('The currently selected PDF generation library (%file) is no longer accessible.', array('%file' => $tool[1])),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Get the version number.
$function = $tool[0] . '_pdf_tool_version';
if (function_exists($function)) {
$version = $function($tool[1]);
if (isset($info['min_version']) && version_compare($version, $info['min_version'], '<')) {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('Unsupported %lib version', array('%lib' => $info['name'])),
'description' => $t('The currently selected version of %lib (@version) is not supported. Please update to a !url.', array(
'%lib' => $info['name'],
'@version' => $version,
'!url' => l($t('newer version'), $info['url']),
)),
'severity' => REQUIREMENT_ERROR,
);
}
else {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $info['name'] . ' ' . $version,
);
}
}
}
// If auto-config is on, check for write access to the appropriate dirs.
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$directories = array();
if (isset($info['public_dirs'])) {
foreach ($info['public_dirs'] as $dir) {
$directories[] = 'public://print_pdf/' . $tool[0] . '/' . $dir;
}
}
if (isset($info['tool_dirs'])) {
foreach ($info['tool_dirs'] as $dir) {
$directories[] = dirname($tool[1]) . '/' . $dir;
}
}
foreach ($directories as $dir) {
if (!is_dir($dir) || !is_writable($dir)) {
$requirements['print_pdf_tool_' . $dir] = array(
'title' => $t('%lib directory', array('%lib' => $info['name'])),
'value' => $t('Non-writable permissions'),
'description' => $t('You must change the %libdir permissions to be writable, as %lib requires write-access to that directory.', array('%lib' => $info['name'], '%libdir' => $dir)),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
}
break;
}
return $requirements;
}
/**
* Remove hardcoded numeric deltas from all blocks.
*/
function print_pdf_update_7000(&$sandbox) {
$renamed_deltas = array(
@@ -156,7 +245,7 @@ function print_pdf_update_7000(&$sandbox) {
}
/**
* Delete old variables
* Delete old variables.
*/
function print_pdf_update_7200(&$sandbox) {
variable_del('print_pdf_settings');
@@ -166,13 +255,13 @@ function print_pdf_update_7200(&$sandbox) {
}
/**
* Update pdf_tool variable to new module|path format
* Update pdf_tool variable to new module|path format.
*/
function print_pdf_update_7201(&$sandbox) {
$tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
$tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
if (count($tool) == 1) {
// Not an array yet, update variable to new format
// Not an array yet, update variable to new format.
if (preg_match('!dompdf_config.inc.php$!', $tool[0])) {
$tool[0] = 'print_pdf_dompdf|' . $tool[0];
}
@@ -191,7 +280,7 @@ function print_pdf_update_7201(&$sandbox) {
}
/**
* Enable block and help area links
* Enable block and help area links.
*/
function print_pdf_update_7202(&$sandbox) {
$link_pos = variable_get('print_pdf_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
@@ -201,7 +290,7 @@ function print_pdf_update_7202(&$sandbox) {
}
/**
* Add Size and Orientation fields for per content type Size and Orientation
* Add Size and Orientation fields for per content type Size and Orientation.
*/
function print_pdf_update_7203(&$sandbox) {
$spec = array(
@@ -219,11 +308,11 @@ function print_pdf_update_7203(&$sandbox) {
}
/**
* Enable the PDF generation sub-module being used
* Enable the PDF generation sub-module being used.
*/
function print_pdf_update_7204(&$sandbox) {
// Since update_7201 already has stored the correct module in the array, use that
$tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
// Since update_7201 already stored the correct module in the array, use that.
$tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
if (count($tool) == 2) {
module_enable(array($tool[0]), FALSE);
@@ -231,11 +320,16 @@ function print_pdf_update_7204(&$sandbox) {
}
/**
* Increase size of the path field in the print_pdf_page_counter table
* Increase size of the path field in the print_pdf_page_counter table.
*/
function print_pdf_update_7205(&$sandbox) {
db_drop_primary_key('print_pdf_page_counter');
db_change_field('print_pdf_page_counter', 'path', 'path',
array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'Page path'),
array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Page path',
),
array('primary key' => array('path')));
}

View File

@@ -7,7 +7,7 @@
* @ingroup print
*/
define('PRINT_PDF_PDF_TOOL_DEFAULT', 0);
define('PRINT_PDF_PDF_TOOL_DEFAULT', FALSE);
define('PRINT_PDF_CONTENT_DISPOSITION_DEFAULT', 2);
define('PRINT_PDF_PAPER_SIZE_DEFAULT', 'A4');
define('PRINT_PDF_PAGE_ORIENTATION_DEFAULT', 'portrait');
@@ -15,7 +15,8 @@ define('PRINT_PDF_IMAGES_VIA_FILE_DEFAULT', 0);
define('PRINT_PDF_AUTOCONFIG_DEFAULT', 1);
define('PRINT_PDF_FILENAME_DEFAULT', '[site:name] - [node:title] - [node:changed:custom:Y-m-d]');
define('PRINT_PDF_CACHE_ENABLED_DEFAULT', 0);
define('PRINT_PDF_CACHE_LIFETIME_DEFAULT', 86400); // 1 day
// 1 day.
define('PRINT_PDF_CACHE_LIFETIME_DEFAULT', 86400);
/**
* Implements hook_print_link().
@@ -59,13 +60,12 @@ function print_pdf_init() {
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
$tool = explode('|', $print_pdf_pdf_tool);
$function = $tool[0] . '_pdf_tool_info';
if (function_exists($function)) {
$info = $function();
}
$info = function_exists($function) ? $function() : array();
if (isset($info['public_dirs'])) {
foreach ($info['public_dirs'] as $dir) {
$directory = 'public://print_pdf/' . $tool[0] . '/' . $dir;
/** @var DrupalLocalStreamWrapper $wrapper */
$wrapper = file_stream_wrapper_get_instance_by_uri($directory);
$real_directory_path = $wrapper->getDirectoryPath() . "/" . file_uri_target($directory);
$result = file_prepare_directory($real_directory_path, FILE_CREATE_DIRECTORY);
@@ -160,11 +160,12 @@ function print_pdf_block_info() {
* Implements hook_block_view().
*/
function print_pdf_block_view($delta = 0) {
$block = array();
switch ($delta) {
case 'print_pdf-top':
$block['subject'] = t('Most PDFd');
$result = db_query_range("SELECT path FROM {print_pdf_page_counter} LEFT JOIN {node} n ON path = CONCAT('node/', n.nid) WHERE status <> 0 OR status IS NULL ORDER BY totalcount DESC", 0, 3)
->fetchAll();
->fetchAll();
if (count($result)) {
$items = array();
foreach ($result as $obj) {
@@ -177,96 +178,6 @@ function print_pdf_block_view($delta = 0) {
return $block;
}
/**
* Implements hook_requirements().
*/
function print_pdf_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
// At runtime, make sure that a PDF generation tool is selected
case 'runtime':
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (empty($print_pdf_pdf_tool)) {
$requirements['print_pdf_tool'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('No PDF tool selected'),
'description' => $t('Please configure it in the !url.', array('!url' => l($t('PDF settings page'), 'admin/config/user-interface/print/pdf'))),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Tool is defined, get some data from it's handler module
$tool = explode('|', $print_pdf_pdf_tool);
$function = $tool[0] . '_pdf_tool_info';
if (function_exists($function)) {
$info = $function();
}
// Is the file there?
if (!is_file($tool[1]) || !is_readable($tool[1])) {
$requirements['print_pdf_tool'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('File not found'),
'description' => $t('The currently selected PDF generation library (%file) is no longer accessible.', array('%file' => $tool[1])),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Get the version number
$function = $tool[0] . '_pdf_tool_version';
if (function_exists($function)) {
$version = $function($tool[1]);
if (isset($info['min_version']) && version_compare($version, $info['min_version'], '<')) {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('Unsupported %lib version', array('%lib' => $info['name'])),
'description' => $t('The currently selected version of %lib (@version) is not supported. Please update to a !url.',
array('%lib' => $info['name'], '@version' => $version, '!url' => l($t('newer version'), $info['url']))),
'severity' => REQUIREMENT_ERROR,
);
}
else {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $info['name'] . ' ' . $version,
);
}
}
}
// If auto-config is on, check for write access to the appropriate dirs
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$directories = array();
if (isset($info['public_dirs'])) {
foreach ($info['public_dirs'] as $dir) {
$directories[] = 'public://print_pdf/' . $tool[0] . '/' . $dir;
}
}
if (isset($info['tool_dirs'])) {
foreach ($info['tool_dirs'] as $dir) {
$directories[] = dirname($tool[1]) . '/' . $dir;
}
}
foreach ($directories as $dir) {
if (!is_dir($dir) || !is_writable($dir)) {
$requirements['print_pdf_tool_' . $dir] = array(
'title' => $t('%lib directory', array('%lib' => $info['name'])),
'value' => $t('Non-writable permissions'),
'description' => $t('You must change the %libdir permissions to be writable, as %lib requires write-access to that directory.', array('%lib' => $info['name'], '%libdir' => $dir)),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
}
break;
}
return $requirements;
}
/**
* Implements hook_node_load().
*/
@@ -293,7 +204,7 @@ function print_pdf_node_load($nodes, $types) {
* Implements hook_node_insert().
*/
function print_pdf_node_insert($node) {
return print_pdf_node_update($node);
print_pdf_node_update($node);
}
/**
@@ -306,8 +217,12 @@ function print_pdf_node_update($node) {
$size = 'print_' . $link['format'] . '_size';
$orientation = 'print_' . $link['format'] . '_orientation';
if (!isset($node->{$size})) $node->{$size} = variable_get($size . '_' . $node->type);
if (!isset($node->{$orientation})) $node->{$orientation} = variable_get($orientation . '_' . $node->type);
if (!isset($node->{$size})) {
$node->{$size} = variable_get($size . '_' . $node->type);
}
if (!isset($node->{$orientation})) {
$node->{$orientation} = variable_get($orientation . '_' . $node->type);
}
db_merge('print_pdf_node_conf')
->key(array('nid' => $node->nid))
@@ -336,7 +251,7 @@ function print_pdf_node_delete($node) {
* Implements hook_form_alter().
*/
function print_pdf_form_alter(&$form, &$form_state, $form_id) {
// Add the node-type settings option to activate the printer-friendly version link
// Add the node-type settings to activate the printer-friendly version link.
if ((user_access('administer print') || user_access('node-specific print configuration')) &&
(($form_id == 'node_type_form') || !empty($form['#node_edit_form']))) {
$link = print_pdf_print_link();
@@ -354,7 +269,11 @@ function print_pdf_form_alter(&$form, &$form_state, $form_id) {
$form['print']['print_' . $link['format']][$orientation] = array(
'#type' => 'select',
'#title' => t('Page orientation'),
'#options' => array('' => 'Unchanged', 'portrait' => t('Portrait'), 'landscape' => t('Landscape')),
'#options' => array(
'' => 'Unchanged',
'portrait' => t('Portrait'),
'landscape' => t('Landscape'),
),
'#description' => t('Choose the page orientation of the generated PDF.'),
);
@@ -371,18 +290,18 @@ function print_pdf_form_alter(&$form, &$form_state, $form_id) {
}
/**
* Auxiliary function to display a formatted PDF version link
* Auxiliary function to display a formatted PDF version link.
*
* Function made available so that developers may call this function from
* their defined pages/blocks.
*
* @param string $path
* path to be used in the link. If not specified, the current URL is used.
* Path to be used in the link. If not specified, the current URL is used.
* @param object $node
* node object, to be used in checking node access. If the path argument is
* Node object, to be used in checking node access. If the path argument is
* not provided, the path used will be node/nid.
* @param string $location
* where in the page where the link is being inserted ('link', 'corner',
* Where in the page where the link is being inserted ('link', 'corner',
* 'block', 'help').
*
* @return bool
@@ -392,7 +311,11 @@ function print_pdf_form_alter(&$form, &$form_state, $form_id) {
*/
function print_pdf_insert_link($path = NULL, $node = NULL, $location = '') {
if (function_exists('print_ui_insert_link')) {
return print_ui_insert_link(print_pdf_print_link(), array('path' => $path, 'node' => $node, 'location' => $location));
return print_ui_insert_link(print_pdf_print_link(), array(
'path' => $path,
'node' => $node,
'location' => $location,
));
}
else {
return FALSE;
@@ -400,11 +323,11 @@ function print_pdf_insert_link($path = NULL, $node = NULL, $location = '') {
}
/**
* Check if the link to the PDF version is allowed depending on the settings
* Check if the link to the PDF version is allowed depending on the settings.
*
* @param array $args
* array containing the possible parameters:
* view_mode, node, type, path
* Array containing the possible parameters:
* view_mode, node, type, path.
*
* @return bool
* FALSE if not allowed, TRUE otherwise
@@ -431,11 +354,11 @@ function print_pdf_cache_clean() {
if ($lifetime > 0) {
$files = file_scan_directory(print_pdf_cache_dir(), '!\d+\.pdf$!');
foreach ($files as $file) {
// For all files in the cache directory, see when they were last accessed
// For all files in the cache directory, see when they were last accessed.
$result = db_query("SELECT timestamp FROM {print_pdf_page_counter} WHERE path = :path", array(':path' => 'node/' . $file->name))
->fetchField();
->fetchField();
// Keep the file only if the last access was within the cache max life value
// Keep the file only if last access was within the cache max life value.
if (($result === FALSE) || ($result + $lifetime < REQUEST_TIME)) {
print_pdf_cache_delete($file->name);
}
@@ -450,17 +373,18 @@ function print_pdf_cache_clean() {
* The scheme://path of the cache directory
*/
function print_pdf_cache_dir() {
global $language_url;
$scheme = 'private';
if (!file_stream_wrapper_valid_scheme($scheme)) {
$scheme = 'temporary';
}
return $scheme . '://print_pdf/cache';
return $scheme . '://print_pdf/cache/' . $language_url->language;
}
/**
* Deletes one or more files from the PDF cache directory.
*
* @param int nid
* @param int $nid
* The node ID of the page for which the cached PDF should be deleted.
* If not provided, the entire cache directory will be deleted.
*/
@@ -485,9 +409,9 @@ function print_pdf_cache_delete($nid = NULL) {
* Displays the PDF as inline or a downloadable file.
*
* @param string $pdf
* PDF content string
* PDF content string.
* @param string $filename
* Filename of the generated PDF
* Filename of the generated PDF.
*
* @return string
* The disposed PDF file
@@ -500,7 +424,7 @@ function print_pdf_dispose_content($pdf, $filename) {
header('Content-Type: application/pdf');
$content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$attachment = ($content_disposition == 2) ? 'attachment' : 'inline';
$attachment = ($content_disposition == 2) ? 'attachment' : 'inline';
header("Content-Disposition: $attachment; filename=\"$filename\"");
@@ -514,21 +438,21 @@ function print_pdf_dispose_content($pdf, $filename) {
* Generate a PDF version of the provided HTML.
*
* @param string $html
* HTML content of the PDF
* HTML content of the PDF.
* @param array $meta
* Meta information to be used in the PDF
* - url: original URL
* - name: author's name
* - title: Page title
* - node: node object
* - node: node object.
* @param string $filename
* (optional) Filename of the generated PDF
* (optional) Filename of the generated PDF.
* @param string $paper_size
* (optional) Paper size of the generated PDF
* (optional) Paper size of the generated PDF.
* @param string $page_orientation
* (optional) Page orientation of the generated PDF
* (optional) Page orientation of the generated PDF.
*
* @return
* @return string|null
* generated PDF page, or NULL in case of error
*
* @see print_pdf_controller()
@@ -541,9 +465,7 @@ function print_pdf_generate_html($html, $meta, $filename = NULL, $paper_size = N
module_load_include('inc', $pdf_tool[0], $pdf_tool[0] . '.pages');
$function = $pdf_tool[0] . '_print_pdf_generate';
if (function_exists($function)) {
$pdf = $function($html, $meta, $paper_size, $page_orientation);
}
$pdf = function_exists($function) ? $function($html, $meta, $paper_size, $page_orientation) : NULL;
if ($filename) {
return print_pdf_dispose_content($pdf, $filename);
}
@@ -562,31 +484,67 @@ function print_pdf_views_api() {
}
/**
* Lists all possible paper sizes
* Lists all possible paper sizes.
*
* @return
* @param bool $include_default
* Flag indicating whether to include the tool's default value.
*
* @return array
* array of strings with the available paper sizes
*/
function _print_pdf_paper_sizes($include_default = FALSE) {
$ret = array();
$ret = ($include_default) ? array('' => 'Unchanged') : array();
$ret += array(
'4A0' => '4A0', '2A0' => '2A0', 'A0' => 'A0',
'A1' => 'A1', 'A2' => 'A2', 'A3' => 'A3', 'A4' => 'A4',
'A5' => 'A5', 'A6' => 'A6', 'A7' => 'A7', 'A8' => 'A8',
'A9' => 'A9', 'A10' => 'A10', 'B0' => 'B0', 'B1' => 'B1',
'B2' => 'B2', 'B3' => 'B3', 'B4' => 'B4', 'B5' => 'B5',
'B6' => 'B6', 'B7' => 'B7', 'B8' => 'B8', 'B9' => 'B9',
'B10' => 'B10', 'C0' => 'C0', 'C1' => 'C1', 'C2' => 'C2',
'C3' => 'C3', 'C4' => 'C4', 'C5' => 'C5', 'C6' => 'C6',
'C7' => 'C7', 'C8' => 'C8', 'C9' => 'C9', 'C10' => 'C10',
'RA0' => 'RA0', 'RA1' => 'RA1', 'RA2' => 'RA2',
'RA3' => 'RA3', 'RA4' => 'RA4', 'SRA0' => 'SRA0',
'SRA1' => 'SRA1', 'SRA2' => 'SRA2', 'SRA3' => 'SRA3',
'SRA4' => 'SRA4', 'LETTER' => 'Letter', 'LEGAL' => 'Legal',
'EXECUTIVE' => 'Executive', 'FOLIO' => 'Folio',
'4A0' => '4A0',
'2A0' => '2A0',
'A0' => 'A0',
'A1' => 'A1',
'A2' => 'A2',
'A3' => 'A3',
'A4' => 'A4',
'A5' => 'A5',
'A6' => 'A6',
'A7' => 'A7',
'A8' => 'A8',
'A9' => 'A9',
'A10' => 'A10',
'B0' => 'B0',
'B1' => 'B1',
'B2' => 'B2',
'B3' => 'B3',
'B4' => 'B4',
'B5' => 'B5',
'B6' => 'B6',
'B7' => 'B7',
'B8' => 'B8',
'B9' => 'B9',
'B10' => 'B10',
'C0' => 'C0',
'C1' => 'C1',
'C2' => 'C2',
'C3' => 'C3',
'C4' => 'C4',
'C5' => 'C5',
'C6' => 'C6',
'C7' => 'C7',
'C8' => 'C8',
'C9' => 'C9',
'C10' => 'C10',
'RA0' => 'RA0',
'RA1' => 'RA1',
'RA2' => 'RA2',
'RA3' => 'RA3',
'RA4' => 'RA4',
'SRA0' => 'SRA0',
'SRA1' => 'SRA1',
'SRA2' => 'SRA2',
'SRA3' => 'SRA3',
'SRA4' => 'SRA4',
'LETTER' => 'Letter',
'LEGAL' => 'Legal',
'EXECUTIVE' => 'Executive',
'FOLIO' => 'Folio',
);
return $ret;

View File

@@ -2,7 +2,7 @@
/**
* @file
* Generates the PDF versions of the pages
* Generates the PDF versions of the pages.
*
* This file is included by the print_pdf module and includes the
* functions that interface with the PDF generation packages.
@@ -13,32 +13,34 @@
module_load_include('inc', 'print', 'print.pages');
/**
* Generate a PDF version of the printer-friendly page
* Generate a PDF version of the printer-friendly page.
*
* @see print_controller()
* @see _print_pdf_dompdf()
* @see _print_pdf_tcpdf()
*/
function print_pdf_controller() {
// Disable caching for generated PDFs, as Drupal doesn't ouput the proper headers from the cache
// Disable caching for generated PDFs, as Drupal doesn't output the proper
// headers from the cache.
$GLOBALS['conf']['cache'] = FALSE;
$args = func_get_args();
$path = filter_xss(implode('/', $args));
$cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;
$cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL;
// Handle the query
// Handle the query.
$query = $_GET;
unset($query['q']);
$node = NULL;
if (!empty($path)) {
if ($alias = drupal_lookup_path('source', $path)) {
// Alias
// Alias.
$path_arr = explode('/', $alias);
$node = node_load($path_arr[1]);
}
elseif (ctype_digit($args[0])) {
// normal nid
// Normal nid.
$node = node_load($args[0]);
}
@@ -49,7 +51,7 @@ function print_pdf_controller() {
else {
$pdf_filename = token_replace($pdf_filename, array('site'), array('clear' => TRUE));
if (empty($pdf_filename)) {
// If empty, use a fallback solution
// If empty, use a fallback solution.
$pdf_filename = str_replace('/', '_', $path);
}
}
@@ -72,10 +74,10 @@ function print_pdf_controller() {
$nodepath = (isset($node->nid)) ? 'node/' . $node->nid : drupal_get_normal_path($path);
db_merge('print_pdf_page_counter')
->key(array('path' => $nodepath))
->key(array('path' => substr($nodepath, 0, 255)))
->fields(array(
'totalcount' => 1,
'timestamp' => REQUEST_TIME,
'totalcount' => 1,
'timestamp' => REQUEST_TIME,
))
->expression('totalcount', 'totalcount + 1')
->execute();
@@ -87,18 +89,18 @@ function print_pdf_controller() {
* Gennerate a PDF for a given Drupal path.
*
* @param string $path
* path of the page to convert to PDF
* path of the page to convert to PDF.
* @param array $query
* (optional) array of key/value pairs as used in the url() function for the
* query
* (Optional) array of key/value pairs as used in the url() function for the
* query.
* @param int $cid
* (optional) comment ID of the comment to render.
* (Optional) comment ID of the comment to render.
* @param string $pdf_filename
* (optional) filename of the generated PDF
* (Optional) filename of the generated PDF.
* @param string $view_mode
* (optional) view mode to be used when rendering the content
* (Optional) view mode to be used when rendering the content.
*
* @return
* @return string|null
* generated PDF page, or NULL in case of error
*
* @see print_pdf_controller()
@@ -109,48 +111,56 @@ function print_pdf_generate_path($path, $query = NULL, $cid = NULL, $pdf_filenam
$link = print_pdf_print_link();
$node = print_controller($path, $link['format'], $cid, $view_mode);
if ($node) {
// Call the current tool's hook_pdf_tool_info(), to see if we need to expand CSS
// Call the tool's hook_pdf_tool_info(), to see if CSS must be expanded.
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
$cache_enabled = variable_get('print_pdf_cache_enabled', PRINT_PDF_CACHE_ENABLED_DEFAULT);
$function = $pdf_tool[0] . '_pdf_tool_info';
if (function_exists($function)) {
$info = $function();
}
$info = function_exists($function) ? $function() : array();
$expand = isset($info['expand_css']) ? $info['expand_css'] : FALSE;
$html = theme('print', array('node' => $node, 'query' => $query, $expand, 'format' => $link['format']));
$html = theme('print', array(
'node' => $node,
'query' => $query,
'expand_css' => $expand,
'format' => $link['format'],
));
// Img elements must be set to absolute
// Img elements must be set to absolute.
$pattern = '!<(img\s[^>]*?)>!is';
$html = preg_replace_callback($pattern, '_print_rewrite_urls', $html);
// Convert the a href elements, to make sure no relative links remain
// Convert the a href elements, to make sure no relative links remain.
$pattern = '!<(a\s[^>]*?)>!is';
$html = preg_replace_callback($pattern, '_print_rewrite_urls', $html);
// And make anchor links relative again, to permit in-PDF navigation
// And make anchor links relative again, to permit in-PDF navigation.
$html = preg_replace("!${base_url}/" . $link['path'] . '/.*?#!', '#', $html);
$meta = array(
'node' => $node,
'url' => url(drupal_get_path_alias(empty($node->nid) ? $node->path : "node/$node->nid"), array('absolute' => TRUE)),
);
if (isset($node->name)) $meta['name'] = $node->name;
if (isset($node->title)) $meta['title'] = $node->title;
if (isset($node->name)) {
$meta['name'] = $node->name;
}
if (isset($node->title)) {
$meta['title'] = $node->title;
}
$paper_size = isset($node->print_pdf_size) ? $node->print_pdf_size : NULL;
$page_orientation = isset($node->print_pdf_orientation) ? $node->print_pdf_orientation : NULL;
$pdf = '';
$cachemiss = FALSE;
$cachefile = '';
if ($cache_enabled && isset($node->nid)) {
// See if the file exists in the cache
// See if the file exists in the cache.
$cachefile = drupal_realpath(print_pdf_cache_dir()) . '/' . $node->nid . '.pdf';
if (is_readable($cachefile)) {
// Get the PDF content from the cached file
// Get the PDF content from the cached file.
$pdf = file_get_contents($cachefile);
if ($pdf === FALSE) {
watchdog('print_pdf', 'Failed to read from cached file %file', array('%file' => $cached), WATCHDOG_ERROR);
watchdog('print_pdf', 'Failed to read from cached file %file', array('%file' => $cachefile), WATCHDOG_ERROR);
}
}
else {
@@ -158,23 +168,21 @@ function print_pdf_generate_path($path, $query = NULL, $cid = NULL, $pdf_filenam
}
}
// If cache is off or file is not cached, generate one from scratch
// If cache is off or file is not cached, generate one from scratch.
if (empty($pdf)) {
$pdf = print_pdf_generate_html($html, $meta, NULL, $paper_size, $page_orientation);
}
if (!empty($pdf)) {
// A PDF was created, save it to cache if configured
// A PDF was created, save it to cache if configured.
if ($cachemiss) {
if (file_unmanaged_save_data($pdf, $cachefile, FILE_EXISTS_REPLACE) == FALSE) {
watchdog('print_pdf', 'Failed to write to "%f".', array('%f' => $filename), WATCHDOG_ERROR);
watchdog('print_pdf', 'Failed to write to "%f".', array('%f' => $cachefile), WATCHDOG_ERROR);
}
}
return $pdf_filename ? print_pdf_dispose_content($pdf, $pdf_filename) : $pdf;
}
}
else {
return NULL;
}
return NULL;
}

View File

@@ -2,7 +2,7 @@
/**
* @file
* PDF Version Views integration
* PDF Version Views integration.
*
* @ingroup print
*/
@@ -25,18 +25,16 @@ function print_pdf_views_data() {
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'nid',
// 'type' => 'INNER',
);
$data['print_pdf_page_counter']['table']['join']['node'] = array(
// 'left_field' is the primary key in the referenced table.
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'path',
// 'type' => 'INNER',
'handler' => 'print_join_page_counter',
);
// print_pdf_node_conf fields
// print_pdf_node_conf fields.
$data['print_pdf_node_conf']['link'] = array(
'title' => t('PDF: Show link'),
'help' => t('Whether to show the PDF version link.'),
@@ -114,8 +112,7 @@ function print_pdf_views_data() {
),
);
// print_pdf_page_counter fields
// print_pdf_page_counter fields.
$data['print_pdf_page_counter']['totalcount'] = array(
'title' => t('PDF: Number of page accesses'),
'help' => t('Counter of accesses to the PDF version for this node.'),