security updates
have to check views and entityreference for custom patches
This commit is contained in:
Binary file not shown.
After Width: | Height: | Size: 518 B |
@@ -0,0 +1,18 @@
|
||||
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
|
||||
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
|
||||
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.
|
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the administrative functions of the print_pdf_dompdf sub-module.
|
||||
*
|
||||
* This file is included by the print_pdf_dompdf module, and includes the
|
||||
* settings form.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form constructor for the dompdf options settings form.
|
||||
*
|
||||
* @ingroup forms
|
||||
*/
|
||||
function print_pdf_dompdf_settings() {
|
||||
$form['settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('dompdf options'),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_dompdf_unicode'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t("Use dompdf's Unicode Mode"),
|
||||
'#default_value' => variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT),
|
||||
'#description' => t("If enabled, dompdf's Unicode mode is used. If not, the module will attempt to convert some non-ASCII chars to ISO-8859-1."),
|
||||
);
|
||||
$form['settings']['print_pdf_dompdf_font_subsetting'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable font subsetting'),
|
||||
'#default_value' => variable_get('print_pdf_dompdf_font_subsetting', PRINT_PDF_DOMPDF_FONT_SUBSETTING_DEFAULT),
|
||||
'#description' => t('Only embed those font characters that are actually used. This can generates smaller PDF files but may significantly slow down processing.'),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* drush integration for print_pdf_dompdf module PDF libraries download.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function print_pdf_dompdf_drush_pdf_libs_alter(&$pdf_libs) {
|
||||
$pdf_libs['dompdf'] = array(
|
||||
'callback' => '_print_pdf_dompdf_drush_download_url',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover the correct URL of the package to download.
|
||||
*
|
||||
* @return string
|
||||
* URL of the file to download, FALSE if not known
|
||||
*/
|
||||
function _print_pdf_dompdf_drush_download_url() {
|
||||
return DOMPDF_DOWNLOAD_URI;
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
name = "dompdf library handler"
|
||||
description = "PDF generation library using dompdf."
|
||||
core = 7.x
|
||||
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"
|
||||
core = "7.x"
|
||||
project = "print"
|
||||
datestamp = "1396426766"
|
||||
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the print_pdf_dompdf module.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function print_pdf_dompdf_uninstall() {
|
||||
variable_del('print_pdf_dompdf_unicode');
|
||||
variable_del('print_pdf_dompdf_font_subsetting');
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Generate a PDF for the print_pdf module using the dompdf library.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
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',
|
||||
'url' => 'http://code.google.com/p/dompdf/downloads/list',
|
||||
'expand_css' => FALSE,
|
||||
'public_dirs' => array(
|
||||
'fonts',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function print_pdf_dompdf_theme() {
|
||||
return array(
|
||||
'print_pdf_dompdf_footer' => array(
|
||||
'variables' => array('html' => ''),
|
||||
'file' => 'print_pdf_dompdf.pages.inc',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function print_pdf_dompdf_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['admin/config/user-interface/print/pdf/dompdf'] = array(
|
||||
'title' => 'dompdf',
|
||||
'description' => 'Configure the dompdf options.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('print_pdf_dompdf_settings'),
|
||||
'access arguments' => array('administer print'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'print_pdf_dompdf.admin.inc',
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_pdf_tool_version().
|
||||
*/
|
||||
function print_pdf_dompdf_pdf_tool_version($pdf_tool) {
|
||||
require_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';
|
||||
}
|
||||
else {
|
||||
return '0.6.0 beta3';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_print_pdf_available_libs_alter().
|
||||
*/
|
||||
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$!');
|
||||
|
||||
foreach ($tools as $tool) {
|
||||
$pdf_tools['print_pdf_dompdf|' . $tool] = 'dompdf (' . dirname($tool) . ')';
|
||||
}
|
||||
}
|
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* 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
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_print_pdf_generate().
|
||||
*/
|
||||
function print_pdf_dompdf_print_pdf_generate($html, $meta, $paper_size = NULL, $page_orientation = NULL) {
|
||||
module_load_include('inc', 'print', 'includes/print');
|
||||
|
||||
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
|
||||
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);
|
||||
$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);
|
||||
|
||||
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');
|
||||
|
||||
// Try to use local file access for image files
|
||||
$html = _print_access_images_via_file($html, $images_via_file);
|
||||
|
||||
// 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
|
||||
$html = preg_replace('!<link.*?modules/system/system.css.*?/>!', '', $html);
|
||||
|
||||
$url_array = parse_url($meta['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($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));
|
||||
|
||||
// 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
|
||||
$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);
|
||||
}
|
||||
// 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');
|
||||
}
|
||||
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);
|
||||
}
|
||||
else {
|
||||
// Otherwise, ensure the content is properly formatted Unicode.
|
||||
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
|
||||
}
|
||||
|
||||
// Must get rid of tbody (dompdf goes into recursion)
|
||||
$html = preg_replace('!<tbody[^>]*?>|</tbody>!i', '', $html);
|
||||
|
||||
$dompdf->load_html($html);
|
||||
|
||||
$dompdf->render();
|
||||
return $dompdf->output();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the dompdf footer contents
|
||||
*
|
||||
* @param array $vars
|
||||
* An associative array containing:
|
||||
* - $html: contents of the body of the HTML from the original node
|
||||
*
|
||||
* @return string
|
||||
* customized HTML text
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
function theme_print_pdf_dompdf_footer($vars) {
|
||||
preg_match('!<div class="print-footer">(.*?)</div>!si', $vars['html'], $tpl_footer);
|
||||
if (isset($tpl_footer[1])) {
|
||||
$html = str_replace($tpl_footer[0], '', $vars['html']);
|
||||
|
||||
$text = '<script type="text/php">
|
||||
if (isset($pdf)) {
|
||||
$font = Font_Metrics::get_font("verdana");;
|
||||
$size = 10;
|
||||
$color = array(0,0,0);
|
||||
$text_height = Font_Metrics::get_font_height($font, $size);
|
||||
|
||||
$w = $pdf->get_width();
|
||||
$h = $pdf->get_height();
|
||||
|
||||
$footer = $pdf->open_object();
|
||||
|
||||
// Draw a line along the bottom
|
||||
$y = $h - 25;
|
||||
$pdf->line(15, $y, $w - 15, $y, $color, 1);
|
||||
|
||||
$y += $text_height / 2;
|
||||
$pdf->page_text(15, $y, \'' . addslashes(strip_tags($tpl_footer[1])) . '\', $font, $size, $color);
|
||||
|
||||
$pdf->close_object();
|
||||
$pdf->add_object($footer, "all");
|
||||
|
||||
// Center the text
|
||||
$width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size);
|
||||
$pagenumtxt = t("Page !n of !total", array("!n" => "{PAGE_NUM}", "!total" => "{PAGE_COUNT}"));
|
||||
$pdf->page_text($w - 15 - $width, $y, $pagenumtxt, $font, $size, $color);
|
||||
}
|
||||
</script>';
|
||||
|
||||
return str_replace("<body>", "<body>" . $text, $html);
|
||||
} else {
|
||||
return $vars['html'];
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* drush integration for print_pdf_mpdf module PDF libraries download.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function print_pdf_mpdf_drush_pdf_libs_alter(&$pdf_libs) {
|
||||
$pdf_libs['mpdf'] = array(
|
||||
'callback' => '_print_pdf_mpdf_drush_download_url',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover the correct URL of the package to download.
|
||||
*
|
||||
* @return string
|
||||
* URL of the file to download, FALSE if not known
|
||||
*/
|
||||
function _print_pdf_mpdf_drush_download_url() {
|
||||
return MPDF_DOWNLOAD_URI;
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
name = "mPDF library handler"
|
||||
description = "PDF generation library using mPDF."
|
||||
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"
|
||||
core = "7.x"
|
||||
project = "print"
|
||||
datestamp = "1396426766"
|
||||
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Generate a PDF for the print_pdf module using the mPDF library.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_pdf_tool_info().
|
||||
*/
|
||||
function print_pdf_mpdf_pdf_tool_info() {
|
||||
return array(
|
||||
'name' => 'mPDF',
|
||||
'url' => 'http://www.mpdf1.com/mpdf/download',
|
||||
'expand_css' => FALSE,
|
||||
'public_dirs' => array(
|
||||
'ttfontdata',
|
||||
'tmp',
|
||||
),
|
||||
'tool_dirs' => array(
|
||||
'graph_cache',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_pdf_tool_version().
|
||||
*/
|
||||
function print_pdf_mpdf_pdf_tool_version($pdf_tool) {
|
||||
require_once(DRUPAL_ROOT . '/' . $pdf_tool);
|
||||
|
||||
if (defined('mPDF_VERSION')) {
|
||||
return mPDF_VERSION;
|
||||
}
|
||||
else {
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_print_pdf_available_libs_alter().
|
||||
*/
|
||||
function print_pdf_mpdf_print_pdf_available_libs_alter(&$pdf_tools) {
|
||||
module_load_include('inc', 'print', 'includes/print');
|
||||
$tools = _print_scan_libs('mpdf', '!^mpdf.php$!');
|
||||
|
||||
foreach ($tools as $tool) {
|
||||
$pdf_tools['print_pdf_mpdf|' . $tool] = 'mPDF (' . dirname($tool) . ')';
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* 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
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_print_pdf_generate().
|
||||
*/
|
||||
function print_pdf_mpdf_print_pdf_generate($html, $meta, $paper_size = NULL, $page_orientation = NULL) {
|
||||
module_load_include('inc', 'print', 'includes/print');
|
||||
|
||||
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
|
||||
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/'));
|
||||
}
|
||||
|
||||
require_once(DRUPAL_ROOT . '/' . $pdf_tool[1]);
|
||||
|
||||
$format = ($page_orientation == "landscape") ? $paper_size . "-L" : $paper_size;
|
||||
|
||||
// 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);
|
||||
|
||||
$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'));
|
||||
|
||||
// $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'), '', '');
|
||||
drupal_alter('print_pdf_mpdf', $mpdf, $html, $meta);
|
||||
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// try to recover from any warning/error
|
||||
ob_clean();
|
||||
|
||||
return $mpdf->Output('', 'S');
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
TCPDF support:
|
||||
TCPDF's support for CSS is considerably worse than the other tools.
|
||||
Unicode is supported (use of Unicode fonts result in HUGE files). Page
|
||||
header and footer are supported. This module requires TCPDF >= 5.9.012.
|
||||
|
||||
1. Download TCPDF from http://sourceforge.net/projects/tcpdf/
|
||||
2. Extract the contents of the downloaded package into one of the
|
||||
supported paths. There is no need to modify the config/tcpdf_config.php
|
||||
file, as the module self-configures TCPDF.
|
||||
3. Grant write access to the cache and images directories to your
|
||||
webserver user.
|
||||
4. Check http://tcpdf.sourceforge.net/ for further information.
|
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the administrative functions of the print_pdf_tcpdf sub-module.
|
||||
*
|
||||
* This file is included by the print_pdf_tcpdf module, and includes the
|
||||
* settings form.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form constructor for the TCPDF options settings form.
|
||||
*
|
||||
* @ingroup forms
|
||||
*/
|
||||
function print_pdf_tcpdf_settings() {
|
||||
$form['settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('TCPDF options'),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_font_family'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Font family'),
|
||||
'#default_value' => variable_get('print_pdf_font_family', PRINT_PDF_TCPDF_FONT_FAMILY_DEFAULT),
|
||||
'#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."),
|
||||
);
|
||||
$form['settings']['print_pdf_font_size'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Font size'),
|
||||
'#default_value' => variable_get('print_pdf_font_size', PRINT_PDF_TCPDF_FONT_SIZE_DEFAULT),
|
||||
'#size' => 2,
|
||||
'#maxlength' => 3,
|
||||
'#description' => t('Set the font size to be used for normal text. This is the base value for the scaling applied to other text styles.'),
|
||||
);
|
||||
$form['settings']['print_pdf_font_subsetting'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable font subsetting'),
|
||||
'#default_value' => variable_get('print_pdf_font_subsetting', PRINT_PDF_TCPDF_FONT_SUBSETTING_DEFAULT),
|
||||
'#description' => t('Only embed those font characters that are actually used. This can generates smaller PDF files but may significantly slow down processing.'),
|
||||
);
|
||||
|
||||
$form['#validate'][] = '_print_pdf_tcpdf_settings_validate';
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form validation handler for print_pdf_tcpdf_settings().
|
||||
*
|
||||
* @see print_pdf_tcpdf_settings()
|
||||
* @ingroup forms
|
||||
*/
|
||||
function _print_pdf_tcpdf_settings_validate($form, &$form_state) {
|
||||
if ($form_state['values']['print_pdf_font_size'] < 1) {
|
||||
form_set_error('print_pdf_font_size', t("Font size must be at least 1."));
|
||||
}
|
||||
}
|
@@ -12,8 +12,13 @@
|
||||
class PrintTCPDF extends TCPDF {
|
||||
public $footer;
|
||||
|
||||
// Display invisible link at the bottom of all pages.
|
||||
public function setTcpdfLink($tcpdflink) {
|
||||
$this->tcpdflink = $tcpdflink;
|
||||
}
|
||||
|
||||
// Page footer data
|
||||
public function SetFooterData($arg = '') {
|
||||
public function setFooterContent($arg = '') {
|
||||
$this->footer = $arg;
|
||||
}
|
||||
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* drush integration for print_pdf_tcpdf module PDF libraries download.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The PDF project download URL
|
||||
*/
|
||||
|
||||
// TCPDF is in sourceforge, and nicely provides a link to the latest version
|
||||
define('TCPDF_DOWNLOAD_URI', 'http://sourceforge.net/projects/tcpdf/files/latest');
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function print_pdf_tcpdf_drush_pdf_libs_alter(&$pdf_libs) {
|
||||
$pdf_libs['tcpdf'] = array(
|
||||
'callback' => '_print_pdf_tcpdf_drush_download_url',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover the correct URL of the package to download.
|
||||
*
|
||||
* @return string
|
||||
* URL of the file to download, FALSE if not known
|
||||
*/
|
||||
function _print_pdf_tcpdf_drush_download_url() {
|
||||
return TCPDF_DOWNLOAD_URI;
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
name = "TCPDF library handler"
|
||||
description = "PDF generation library using TCPDF."
|
||||
core = 7.x
|
||||
package = "Printer, email and PDF versions"
|
||||
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"
|
||||
core = "7.x"
|
||||
project = "print"
|
||||
datestamp = "1396426766"
|
||||
|
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the print_pdf_tcpdf module.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function print_pdf_tcpdf_uninstall() {
|
||||
variable_del('print_pdf_font_family');
|
||||
variable_del('print_pdf_font_size');
|
||||
variable_del('print_pdf_font_subsetting');
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Generate a PDF for the print_pdf module using the TCPDF library.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
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',
|
||||
'min_version' => '5.9.001',
|
||||
'url' => 'http://sourceforge.net/projects/tcpdf/files/latest',
|
||||
'expand_css' => TRUE,
|
||||
'public_dirs' => array(
|
||||
'cache',
|
||||
),
|
||||
'tool_dirs' => array(
|
||||
'images',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function print_pdf_tcpdf_theme() {
|
||||
return array(
|
||||
'print_pdf_tcpdf_header' => array(
|
||||
'variables' => array('pdf' => NULL, 'html' => '', 'font' => array()),
|
||||
'file' => 'print_pdf_tcpdf.pages.inc',
|
||||
),
|
||||
'print_pdf_tcpdf_page' => array(
|
||||
'variables' => array('pdf' => NULL),
|
||||
'file' => 'print_pdf_tcpdf.pages.inc',
|
||||
),
|
||||
'print_pdf_tcpdf_content' => array(
|
||||
'variables' => array('pdf' => NULL, 'html' => '', 'font' => array()),
|
||||
'file' => 'print_pdf_tcpdf.pages.inc',
|
||||
),
|
||||
'print_pdf_tcpdf_footer' => array(
|
||||
'variables' => array('pdf' => NULL, 'html' => '', 'font' => array()),
|
||||
'file' => 'print_pdf_tcpdf.pages.inc',
|
||||
),
|
||||
'print_pdf_tcpdf_footer2' => array(
|
||||
'variables' => array('pdf' => NULL),
|
||||
'file' => 'print_pdf_tcpdf.pages.inc',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function print_pdf_tcpdf_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['admin/config/user-interface/print/pdf/tcpdf'] = array(
|
||||
'title' => 'TCPDF',
|
||||
'description' => 'Configure the TCPDF options.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('print_pdf_tcpdf_settings'),
|
||||
'access arguments' => array('administer print'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'print_pdf_tcpdf.admin.inc',
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_pdf_tool_version().
|
||||
*/
|
||||
function print_pdf_tcpdf_pdf_tool_version($pdf_tool) {
|
||||
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
|
||||
// prevent TCPDF default configs
|
||||
define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
|
||||
}
|
||||
require_once(DRUPAL_ROOT . '/' . $pdf_tool);
|
||||
|
||||
// Hide warnings, as some TCPDF constants may still be undefined
|
||||
if (class_exists('TCPDF')) {
|
||||
@$pdf = new TCPDF();
|
||||
|
||||
if (class_exists('TCPDF_STATIC')) {
|
||||
return TCPDF_STATIC::getTCPDFVersion();
|
||||
}
|
||||
elseif (method_exists($pdf, 'getTCPDFVersion')) {
|
||||
return $pdf->getTCPDFVersion();
|
||||
}
|
||||
elseif (defined('PDF_PRODUCER')) {
|
||||
sscanf(PDF_PRODUCER, "TCPDF %s", $version);
|
||||
|
||||
return $version;
|
||||
}
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_print_pdf_available_libs_alter().
|
||||
*/
|
||||
function print_pdf_tcpdf_print_pdf_available_libs_alter(&$pdf_tools) {
|
||||
module_load_include('inc', 'print', 'includes/print');
|
||||
$tools = _print_scan_libs('tcpdf', '!^tcpdf.php$!');
|
||||
|
||||
foreach ($tools as $tool) {
|
||||
$pdf_tools['print_pdf_tcpdf|' . $tool] = 'TCPDF (' . dirname($tool) . ')';
|
||||
}
|
||||
}
|
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* 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
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_print_pdf_generate().
|
||||
*/
|
||||
function print_pdf_tcpdf_print_pdf_generate($html, $meta, $paper_size = NULL, $page_orientation = NULL) {
|
||||
global $base_url, $language;
|
||||
|
||||
module_load_include('inc', 'print', 'includes/print');
|
||||
|
||||
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
|
||||
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)) {
|
||||
$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);
|
||||
}
|
||||
|
||||
// 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
|
||||
$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|\?)[^\s'\"]+([^>]*?>)!is";
|
||||
$html = preg_replace($pattern, '$1$2', $html);
|
||||
|
||||
require_once(DRUPAL_ROOT . '/' . $pdf_tool[1]);
|
||||
module_load_include('inc', 'print_pdf_tcpdf', 'print_pdf_tcpdf.class');
|
||||
|
||||
$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);
|
||||
|
||||
// set document information
|
||||
if (isset($meta['name'])) {
|
||||
$pdf->SetAuthor(strip_tags($meta['name']));
|
||||
}
|
||||
$pdf->SetCreator(variable_get('site_name', 'Drupal'));
|
||||
$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);
|
||||
|
||||
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_page', array('pdf' => $pdf));
|
||||
|
||||
// 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
|
||||
$pdf->AddPage();
|
||||
|
||||
$pdf = theme('print_pdf_tcpdf_content', array('pdf' => $pdf, 'html' => $html, 'font' => $font));
|
||||
|
||||
// reset pointer to the last page
|
||||
$pdf->lastPage();
|
||||
|
||||
// try to recover from any warning/error
|
||||
ob_clean();
|
||||
|
||||
return $pdf = $pdf->Output('', 'S');
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF header
|
||||
*
|
||||
* @param array $vars
|
||||
* An associative array containing:
|
||||
* - $pdf: current TCPDF object
|
||||
* - $html: contents of the body of the HTML from the original node
|
||||
* - $font: array with the font definition (font name, styles and size)
|
||||
*
|
||||
* @return object
|
||||
* modified PDF object
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_header($vars) {
|
||||
global $base_url;
|
||||
|
||||
$pdf = $vars['pdf'];
|
||||
preg_match('!<div class="print-logo">(.*?)</div>!si', $vars['html'], $tpl_logo);
|
||||
preg_match('!<title>(.*?)</title>!si', $vars['html'], $tpl_title);
|
||||
preg_match('!<div class="print-site_name">(.*?)</div>!si', $vars['html'], $tpl_site_name);
|
||||
|
||||
$ratio = 0;
|
||||
$logo = '';
|
||||
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);
|
||||
|
||||
if (!empty($logo)) {
|
||||
$size = getimagesize($logo);
|
||||
$ratio = $size ? ($size[0] / $size[1]) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
// set header font
|
||||
$pdf->setHeaderFont($vars['font']);
|
||||
// set header margin
|
||||
$pdf->setHeaderMargin(5);
|
||||
// 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)
|
||||
*
|
||||
* @param array $vars
|
||||
* An associative array containing:
|
||||
* - $pdf: current TCPDF object
|
||||
*
|
||||
* @return object
|
||||
* modified PDF object
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_page($vars) {
|
||||
$pdf = $vars['pdf'];
|
||||
// set margins
|
||||
$pdf->SetMargins(15, 20, 15);
|
||||
// set auto page breaks
|
||||
$pdf->SetAutoPageBreak(TRUE, 15);
|
||||
// set image scale factor
|
||||
$pdf->setImageScale(1);
|
||||
// set image compression quality
|
||||
$pdf->setJPEGQuality(100);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF page content
|
||||
*
|
||||
* @param array $vars
|
||||
* An associative array containing:
|
||||
* - $pdf: current TCPDF object
|
||||
* - $html: contents of the body of the HTML from the original node
|
||||
* - $font: array with the font definition (font name, styles and size)
|
||||
*
|
||||
* @return object
|
||||
* modified PDF object
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_content($vars) {
|
||||
$pdf = $vars['pdf'];
|
||||
// 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
|
||||
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
|
||||
$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
|
||||
$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 {
|
||||
$prev = $matches[1];
|
||||
$matches[1] = preg_replace('!(</span>)<br />(\s*?</span><br />)!s', '$1$2', $matches[1]);
|
||||
} while ($prev != $matches[1]);
|
||||
|
||||
@$pdf->writeHTML($matches[1]);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF footer contents
|
||||
*
|
||||
* @param array $vars
|
||||
* An associative array containing:
|
||||
* - $pdf: current TCPDF object
|
||||
* - $html: contents of the body of the HTML from the original node
|
||||
* - $font: array with the font definition (font name, styles and size)
|
||||
*
|
||||
* @return object
|
||||
* modified PDF object
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_footer($vars) {
|
||||
$pdf = $vars['pdf'];
|
||||
preg_match('!<div class="print-footer">(.*?)</div>!si', $vars['html'], $tpl_footer);
|
||||
|
||||
if (isset($tpl_footer[1])) {
|
||||
$footer = trim(preg_replace('!</?div[^>]*?>!i', '', $tpl_footer[1]));
|
||||
|
||||
// set footer font
|
||||
$vars['font'][2] *= 0.8;
|
||||
$pdf->setFooterFont($vars['font']);
|
||||
// set footer margin
|
||||
$pdf->SetFooterMargin(10);
|
||||
// set footer data
|
||||
$pdf->setFooterContent($footer);
|
||||
}
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF footer layout
|
||||
*
|
||||
* @param array $vars
|
||||
* An associative array containing:
|
||||
* - $pdf: current TCPDF object
|
||||
*
|
||||
* @return object
|
||||
* modified PDF object
|
||||
*
|
||||
* @ingroup themeable
|
||||
* @ingroup print_themeable
|
||||
*/
|
||||
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);
|
||||
|
||||
$ormargins = $pdf->getOriginalMargins();
|
||||
$pagenumtxt = t('Page !n of !total', array('!n' => $pdf->PageNo(), '!total' => $pdf->getAliasNbPages()));
|
||||
// Print page number
|
||||
if ($pdf->getRTL()) {
|
||||
$pdf->SetX($ormargins['right']);
|
||||
$pdf->Cell(0, 10, $pagenumtxt, 'T', 0, 'L');
|
||||
}
|
||||
else {
|
||||
$pdf->SetX($ormargins['left']);
|
||||
$pdf->Cell(0, 10, $pagenumtxt, 'T', 0, 'R');
|
||||
}
|
||||
|
||||
return $pdf;
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
wkhtmltopdf support:
|
||||
wkhtmltopdf is a webkit-based tool that actually is a browser in order to
|
||||
generate the PDF. Resource hungry: expect to need some 30Mb+ of RAM and
|
||||
some seconds of CPU power. The static binaries may need additional
|
||||
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.
|
||||
3. Check http://code.google.com/p/wkhtmltopdf/ for further information.
|
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the administrative functions of the print_pdf_wkhtmltopdf module.
|
||||
*
|
||||
* This file is included by the print_pdf_wkhtmltopdf module, and includes the
|
||||
* settings form.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form constructor for the wkhtmltopdf options settings form.
|
||||
*
|
||||
* @ingroup forms
|
||||
*/
|
||||
function print_pdf_wkhtmltopdf_settings() {
|
||||
$form['settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('wkhtmltopdf options'),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_wkhtmltopdf_options'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('wkhtmltopdf options'),
|
||||
'#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).'),
|
||||
);
|
||||
|
||||
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'),
|
||||
);
|
||||
}
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* drush integration for print_pdf_wkhtmltopdf module PDF libraries download.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function print_pdf_wkhtmltopdf_drush_pdf_libs_alter(&$pdf_libs) {
|
||||
$pdf_libs['wkhtmltopdf'] = array(
|
||||
'callback' => '_print_pdf_wkhtmltopdf_drush_download_url',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover the correct URL of the package to download.
|
||||
*
|
||||
* @return string
|
||||
* URL of the file to download, FALSE if not known
|
||||
*/
|
||||
function _print_pdf_wkhtmltopdf_drush_download_url() {
|
||||
$ret = FALSE;
|
||||
|
||||
switch (drupal_substr(php_uname('s'), 0, 3)) {
|
||||
case 'Lin':
|
||||
$ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_AMD64_DOWNLOAD_URI : WKHTMLTOPDF_I386_DOWNLOAD_URI;
|
||||
break;
|
||||
case 'Win':
|
||||
$ret = WKHTMLTOPDF_WIN_DOWNLOAD_URI;
|
||||
break;
|
||||
case 'Dar':
|
||||
$ret = WKHTMLTOPDF_OSX_DOWNLOAD_URI;
|
||||
break;
|
||||
default:
|
||||
drush_log(dt('wkhtmltopdf is not supported in this system, please choose another library.'), 'error');
|
||||
break;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
name = "wkhtmltopdf library handler"
|
||||
description = "PDF generation library using wkhtmltopdf."
|
||||
core = 7.x
|
||||
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"
|
||||
core = "7.x"
|
||||
project = "print"
|
||||
datestamp = "1396426766"
|
||||
|
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the print_pdf_wkhtmltopdf module.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function print_pdf_wkhtmltopdf_uninstall() {
|
||||
variable_del('print_pdf_wkhtmltopdf_options');
|
||||
}
|
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Generate a PDF for the print_pdf module using the wkhtmltopdf library.
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
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',
|
||||
'min_version' => '0.9.6',
|
||||
'url' => 'http://code.google.com/p/wkhtmltopdf/downloads/list',
|
||||
'expand_css' => FALSE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function print_pdf_wkhtmltopdf_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['admin/config/user-interface/print/pdf/wkhtmltopdf'] = array(
|
||||
'title' => 'wkhtmltopdf',
|
||||
'description' => 'Configure the wkhtmltopdf options.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('print_pdf_wkhtmltopdf_settings'),
|
||||
'access arguments' => array('administer print'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'print_pdf_wkhtmltopdf.admin.inc',
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_requirements().
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'));
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
return ($matches[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_print_pdf_available_libs_alter().
|
||||
*/
|
||||
function print_pdf_wkhtmltopdf_print_pdf_available_libs_alter(&$pdf_tools) {
|
||||
module_load_include('inc', 'print', 'includes/print');
|
||||
$tools = _print_scan_libs('wkhtmltopdf', '!^wkhtmltopdf!');
|
||||
|
||||
foreach ($tools as $tool) {
|
||||
$version = print_pdf_wkhtmltopdf_pdf_tool_version($tool);
|
||||
|
||||
$pdf_tools['print_pdf_wkhtmltopdf|' . $tool] = 'wkhtmltopdf ' . $version . ' (' . $tool . ')';
|
||||
}
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* 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
|
||||
*
|
||||
* @ingroup print
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_print_pdf_generate().
|
||||
*/
|
||||
function print_pdf_wkhtmltopdf_print_pdf_generate($html, $meta, $paper_size = NULL, $page_orientation = NULL) {
|
||||
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
|
||||
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);
|
||||
$wkhtmltopdf_options = variable_get('print_pdf_wkhtmltopdf_options', PRINT_PDF_WKHTMLTOPDF_OPTIONS);
|
||||
|
||||
$dpi = 96;
|
||||
|
||||
if (!empty($wkhtmltopdf_options) && isset($meta['node'])) {
|
||||
$wkhtmltopdf_options = token_replace($wkhtmltopdf_options, array('node' => $meta['node']), array('clear' => TRUE));
|
||||
}
|
||||
|
||||
$version = print_pdf_wkhtmltopdf_pdf_tool_version($pdf_tool[1]);
|
||||
|
||||
// 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;
|
||||
}
|
||||
elseif (version_compare($version, '0.9.6', '>=')) {
|
||||
$wkhtmltopdf_options = '--disallow-local-file-access ' . $wkhtmltopdf_options;
|
||||
}
|
||||
else {
|
||||
drupal_goto($meta['url']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 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']);
|
||||
}
|
||||
|
||||
$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 - -";
|
||||
|
||||
$process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
|
||||
|
||||
if (is_resource($process)) {
|
||||
fwrite($pipes[0], $html);
|
||||
fclose($pipes[0]);
|
||||
|
||||
$pdf = stream_get_contents($pipes[1]);
|
||||
fclose($pipes[1]);
|
||||
|
||||
stream_set_blocking($pipes[2], 0);
|
||||
$error = stream_get_contents($pipes[2]);
|
||||
fclose($pipes[2]);
|
||||
|
||||
$retval = proc_close($process);
|
||||
if (!empty($error) || ($retval != 0)) {
|
||||
if (empty($error)) {
|
||||
$error = 'No stderr output available.';
|
||||
}
|
||||
watchdog('print_pdf', 'wkhtmltopdf [%cmd] (returned %ret): %error', array('%cmd' => $cmd, '%ret' => $retval, '%error' => $error));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($pdf)) {
|
||||
return $pdf;
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('Unable to generate PDF file.'), 'error');
|
||||
drupal_goto($meta['url']);
|
||||
return NULL;
|
||||
}
|
||||
}
|
@@ -11,17 +11,20 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Menu callback for the PDF version module settings form.
|
||||
* Form constructor for the PDF version module settings form.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see _print_pdf_tools()
|
||||
*/
|
||||
function print_pdf_settings() {
|
||||
$pdf_tools = _print_pdf_tools();
|
||||
$current_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
$pdf_tool_default = (in_array($current_pdf_tool, $pdf_tools)) ? $current_pdf_tool : PRINT_PDF_PDF_TOOL_DEFAULT;
|
||||
$pdf_tools = array();
|
||||
drupal_alter('print_pdf_available_libs', $pdf_tools);
|
||||
|
||||
if (!empty($pdf_tools)) {
|
||||
$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;
|
||||
|
||||
if ($pdf_tools != -1) {
|
||||
$form['settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('PDF options'),
|
||||
@@ -35,113 +38,6 @@ function print_pdf_settings() {
|
||||
'#description' => t('This option selects the PDF generation tool being used by this module to create the PDF version.'),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_link_pos'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('PDF version link'),
|
||||
'#default_value' => variable_get('print_pdf_link_pos', drupal_json_decode(PRINT_PDF_LINK_POS_DEFAULT)),
|
||||
'#options' => array('link' => t('Links area'), 'corner' => t('Content corner'), 'block' => t('Block'), 'help' => t('Help area')),
|
||||
'#description' => t('Choose the location of the link(s) to the PDF version. The Links area is usually below the node content, whereas the Content corner is placed in the upper-right corner of the node content. Unselect all options to disable the link. Even if the link is disabled, you can still view the PDF version of a node by going to !path/nid where nid is the numeric id of the node.', array('!path' => PRINTPDF_PATH)),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_link_teaser'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display link to the PDF version in teaser'),
|
||||
'#default_value' => variable_get('print_pdf_link_teaser', PRINT_PDF_LINK_TEASER_DEFAULT),
|
||||
'#description' => t('Enabling this will display the link in teaser mode.'),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Advanced link options'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_show_link'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Link style'),
|
||||
'#default_value' => variable_get('print_pdf_show_link', PRINT_PDF_SHOW_LINK_DEFAULT),
|
||||
'#options' => array(1 => t('Text only'), 2 => t('Icon only'), 3 => t('Icon and Text')),
|
||||
'#description' => t('Select the visual style of the link.'),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_link_use_alias'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use URL alias instead of node ID'),
|
||||
'#default_value' => variable_get('print_pdf_link_use_alias', PRINT_PDF_LINK_USE_ALIAS_DEFAULT),
|
||||
'#description' => t('Enabling this will create the link using the URL alias instead of the node ID.'),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_link_class'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link class'),
|
||||
'#default_value' => variable_get('print_pdf_link_class', PRINT_PDF_LINK_CLASS_DEFAULT),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 250,
|
||||
'#description' => t('This can be used by themers to change the link style or by jQuery modules to open in a new window (e.g. greybox or thickbox). Multiple classes can be specified, separated by spaces.'),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_node_link_visibility'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Link visibility'),
|
||||
'#default_value' => variable_get('print_pdf_node_link_visibility', PRINT_PDF_NODE_LINK_VISIBILITY_DEFAULT),
|
||||
'#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_node_link_pages'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => variable_get('print_pdf_node_link_pages', PRINT_PDF_NODE_LINK_PAGES_DEFAULT),
|
||||
'#rows' => 3,
|
||||
'#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
|
||||
);
|
||||
|
||||
if (module_exists('php')) {
|
||||
$access = user_access('use PHP for settings');
|
||||
|
||||
if ($form['settings']['adv_link']['print_pdf_node_link_visibility']['#default_value'] == 2 && !$access) {
|
||||
$form['settings']['adv_link']['print_pdf_node_link_visibility'] = array('#type' => 'value', '#value' => 2);
|
||||
$form['settings']['adv_link']['print_pdf_node_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_pdf_node_link_pages']['#default_value']);
|
||||
}
|
||||
elseif ($access) {
|
||||
$form['settings']['adv_link']['print_pdf_node_link_visibility']['#options'][] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
|
||||
$form['settings']['adv_link']['print_pdf_node_link_pages']['#description'] .= ' ' . t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
|
||||
}
|
||||
}
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_visibility'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Show link in system (non-content) pages'),
|
||||
'#description' => 'Any page that is not a Drupal node. Usually pages generated by Drupal or a module such as Views or Panels.',
|
||||
'#default_value' => variable_get('print_pdf_sys_link_visibility', PRINT_PDF_SYS_LINK_VISIBILITY_DEFAULT),
|
||||
'#options' => array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')),
|
||||
);
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_pages'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => variable_get('print_pdf_sys_link_pages', PRINT_PDF_SYS_LINK_PAGES_DEFAULT),
|
||||
'#rows' => 3,
|
||||
'#description' => t('Setting this option will add a PDF version page link on pages created by Drupal or the enabled modules.') . '<br />' .
|
||||
t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
|
||||
);
|
||||
|
||||
if (module_exists('php')) {
|
||||
if ($form['settings']['adv_link']['print_pdf_sys_link_visibility']['#default_value'] == 2 && !$access) {
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_visibility'] = array('#type' => 'value', '#value' => 2);
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_pages'] = array('#type' => 'value', '#value' => $form['settings']['adv_link']['print_pdf_sys_link_pages']['#default_value']);
|
||||
}
|
||||
elseif ($access) {
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_visibility']['#options'][] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
|
||||
$form['settings']['adv_link']['print_pdf_sys_link_pages']['#description'] .= ' ' . t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
|
||||
}
|
||||
}
|
||||
|
||||
$form['settings']['adv_link']['print_pdf_book_link'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Link in book hierarchy nodes'),
|
||||
'#default_value' => variable_get('print_pdf_book_link', PRINT_PDF_BOOK_LINK_DEFAULT),
|
||||
'#options' => array(t('No link'), t('Current page and sub-pages'), t('Current page only')),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_content_disposition'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Open PDF in'),
|
||||
@@ -153,21 +49,7 @@ function print_pdf_settings() {
|
||||
$form['settings']['print_pdf_paper_size'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Paper size'),
|
||||
'#options' => 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',
|
||||
),
|
||||
'#options' => _print_pdf_paper_sizes(),
|
||||
'#default_value' => variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT),
|
||||
'#description' => t('Choose the paper size of the generated PDF.'),
|
||||
);
|
||||
@@ -179,6 +61,35 @@ function print_pdf_settings() {
|
||||
'#default_value' => variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT),
|
||||
'#description' => t('Choose the page orientation of the generated PDF.'),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_cache_enabled'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable caching of generated PDFs'),
|
||||
'#default_value' => variable_get('print_pdf_cache_enabled', PRINT_PDF_CACHE_ENABLED_DEFAULT),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_cache_lifetime'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Cache Lifetime'),
|
||||
'#options' => array(
|
||||
'0' => 'None',
|
||||
'10800' => '3 hours',
|
||||
'21600' => '6 hours',
|
||||
'43200' => '12 hours',
|
||||
'64800' => '18 hours',
|
||||
'86400' => '24 hours',
|
||||
'129600' => '36 hours',
|
||||
'172800' => '2 days',
|
||||
'259200' => '3 days',
|
||||
'345600' => '4 days',
|
||||
'432000' => '5 days',
|
||||
'518400' => '6 days',
|
||||
'604800' => '7 days',
|
||||
),
|
||||
'#default_value' => variable_get('print_pdf_cache_lifetime', PRINT_PDF_CACHE_LIFETIME_DEFAULT),
|
||||
'#description' => t('The lifetime of cached PDFs. A cached PDF is only removed when a node is updated, deleted, or cron is run and the last access is older than this value.'),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_images_via_file'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Access images via local file access'),
|
||||
@@ -191,50 +102,13 @@ function print_pdf_settings() {
|
||||
'#default_value' => variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT),
|
||||
'#description' => t('If you disable this option, the pdf tool settings must be configured manually. For TCDPF, edit the tcpdf/config/tcpdf_config.php file. For dompdf, edit the dompdf/dompdf_config.inc.php file.'),
|
||||
);
|
||||
$form['settings']['print_pdf_font_family'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Font family'),
|
||||
'#default_value' => variable_get('print_pdf_font_family', PRINT_PDF_FONT_FAMILY_DEFAULT),
|
||||
'#size' => 60,
|
||||
'#maxlength' => 250,
|
||||
'#description' => t('(TCPDF only) 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."),
|
||||
);
|
||||
$form['settings']['print_pdf_font_size'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Font size'),
|
||||
'#default_value' => variable_get('print_pdf_font_size', PRINT_PDF_FONT_SIZE_DEFAULT),
|
||||
'#size' => 2,
|
||||
'#maxlength' => 3,
|
||||
'#description' => t('(TCPDF only) Set the font size to be used for normal text. This is the base value for the scaling applied to other text styles.'),
|
||||
);
|
||||
$form['settings']['print_pdf_font_subsetting'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable font subsetting'),
|
||||
'#default_value' => variable_get('print_pdf_font_subsetting', PRINT_PDF_FONT_SUBSETTING_DEFAULT),
|
||||
'#description' => t('(TCPDF only) Only embed those font characters that are actually used. This can generates smaller PDF files but may significantly slow down processing.'),
|
||||
);
|
||||
$form['settings']['print_pdf_dompdf_unicode'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t("Use dompdf's Unicode Mode"),
|
||||
'#default_value' => variable_get('print_pdf_dompdf_unicode', PRINT_PDF_DOMPDF_UNICODE_DEFAULT),
|
||||
'#description' => t("If enabled, dompdf's Unicode mode is used. If not, the module will attempt to convert some non-ASCII chars to ISO-8859-1."),
|
||||
);
|
||||
$form['settings']['print_pdf_wkhtmltopdf_options'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('wkhtmltopdf options'),
|
||||
'#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).'),
|
||||
);
|
||||
|
||||
$form['settings']['print_pdf_filename'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('PDF filename'),
|
||||
'#default_value' => variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT),
|
||||
'#description' => t("If left empty the generated filename defaults to the node's path. Tokens may be used to build the filename (see following list). The .pdf extension will be appended automatically."),
|
||||
);
|
||||
$form['settings']['print_pdf_filename'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('PDF filename'),
|
||||
'#default_value' => variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT),
|
||||
'#description' => t("If left empty the generated filename defaults to the node's path. Tokens may be used to build the filename (see following list). The .pdf extension will be appended automatically."),
|
||||
);
|
||||
if (module_exists('token')) {
|
||||
$form['settings']['print_pdf_filename_patterns'] = array(
|
||||
'#type' => 'fieldset',
|
||||
@@ -255,12 +129,31 @@ function print_pdf_settings() {
|
||||
'#description' => t('Enabling this option will display a list of printer-friendly destination URLs at the bottom of the page.'),
|
||||
);
|
||||
|
||||
$form['settings']['link_text'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Custom link text'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['settings']['link_text']['print_pdf_link_text_enabled'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable custom link text'),
|
||||
'#default_value' => variable_get('print_pdf_link_text_enabled', PRINT_TYPE_LINK_TEXT_ENABLED_DEFAULT),
|
||||
);
|
||||
$form['settings']['link_text']['print_pdf_link_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => variable_get('print_pdf_link_text', $link['text']),
|
||||
'#description' => t('Text used in the link to the PDF version.'),
|
||||
);
|
||||
|
||||
$form['#validate'][] = '_print_pdf_settings_validate';
|
||||
}
|
||||
else {
|
||||
variable_set('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
|
||||
$form['settings'] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => '<p>' . t("No PDF generation tool found! Please dowload a supported PHP PDF generation tool. Check this module's INSTALL.txt for more details.") . '</p>',
|
||||
'#markup' => '<p>' . t("No PDF generation tool found! Please download a supported PHP PDF generation tool. Check this module's INSTALL.txt for more details.") . '</p>',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -268,78 +161,13 @@ function print_pdf_settings() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate print_pdf_settings form.
|
||||
* Form validation handler for print_pdf_settings().
|
||||
*
|
||||
* @see print_pdf_settings()
|
||||
* @ingroup forms
|
||||
*/
|
||||
function _print_pdf_settings_validate($form, &$form_state) {
|
||||
if (empty($form_state['values']['print_pdf_pdf_tool'])) {
|
||||
form_set_error('print_pdf_pdf_tool', t("No PDF tool selected"));
|
||||
}
|
||||
if ($form_state['values']['print_pdf_font_size'] < 1) {
|
||||
form_set_error('print_pdf_font_size', t("Font size must be at least 1."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function to locate suitable PDF generation tools
|
||||
*
|
||||
* @return
|
||||
* array of filenames with the include-able PHP file of the located tools
|
||||
*/
|
||||
function _print_pdf_tools() {
|
||||
$pattern = '!^(?:dompdf_config.inc.php|tcpdf.php|wkhtmltopdf.*)$!';
|
||||
$tools = array_keys(file_scan_directory(drupal_get_path('module', 'print'), $pattern));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(PRINT_PDF_LIB_PATH, $pattern)));
|
||||
if (module_exists('libraries')) {
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(libraries_get_path('dompdf'), '/^dompdf_config.inc.php$/')));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(libraries_get_path('tcpdf'), '/^tcpdf.php$/')));
|
||||
$tools = array_merge($tools, array_keys(file_scan_directory(libraries_get_path('wkhtmltopdf'), '/^wkhtmltopdf/')));
|
||||
}
|
||||
|
||||
|
||||
$num_tools = count($tools);
|
||||
|
||||
if ($num_tools == 0) {
|
||||
variable_set('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return array_combine($tools, $tools);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback for the PDF version module text strings settings form.
|
||||
*
|
||||
* @ingroup forms
|
||||
*/
|
||||
function print_pdf_strings_settings() {
|
||||
drupal_set_message(t("Saving these strings will disable their translation via Drupal's language system. Use the reset button to return them to the original state."), 'warning');
|
||||
|
||||
$form['print_pdf_text'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Text strings'),
|
||||
);
|
||||
|
||||
$form['print_pdf_text']['print_pdf_link_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link text'),
|
||||
'#default_value' => variable_get('print_pdf_link_text', t('PDF version')),
|
||||
'#description' => t('Text used in the link to the PDF version.'),
|
||||
);
|
||||
$form['print_pdf_text']['reset'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Reset to defaults'),
|
||||
'#submit' => array('print_pdf_strings_settings_delete'),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset button callback for text strings settings form
|
||||
*
|
||||
* @ingroup forms
|
||||
*/
|
||||
function print_pdf_strings_settings_delete() {
|
||||
variable_del('print_pdf_link_text');
|
||||
}
|
||||
|
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks provided by the PDF version module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup hooks
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provide some information on the needs of the PDF library.
|
||||
*
|
||||
* @return
|
||||
* Associative array with the following data:
|
||||
* - name: name of the PDF library.
|
||||
* - min_version: minimum version of the PDF library supported by the
|
||||
* module.
|
||||
* - url: URL where the PDF library can be downloaded from.
|
||||
* - 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.
|
||||
* - public_dirs: directories to which the tool requires write-access,
|
||||
* with configurable locations.
|
||||
* - tool_dirs: directories to which the tool requires write-access, but
|
||||
* can't be configured, and are relative to the tool's root path.
|
||||
*
|
||||
* @ingroup print_hooks
|
||||
*/
|
||||
function hook_pdf_tool_info() {
|
||||
return array(
|
||||
'name' => 'foopdf',
|
||||
'min_version' => '1.0',
|
||||
'url' => 'http://www.pdf.tool/download',
|
||||
'expand_css' => FALSE,
|
||||
'public_dirs' => array(
|
||||
'fonts',
|
||||
'cache',
|
||||
'tmp',
|
||||
),
|
||||
'tool_dirs' => array(
|
||||
'xyz',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out the version of the PDF library
|
||||
*
|
||||
* @param string $pdf_tool
|
||||
* Filename of the tool to be analysed.
|
||||
*
|
||||
* @return string
|
||||
* version number of the library
|
||||
*/
|
||||
function hook_pdf_tool_version() {
|
||||
require_once(DRUPAL_ROOT . '/' . $pdf_tool);
|
||||
|
||||
return '1.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a PDF version of the provided HTML.
|
||||
*
|
||||
* @param string $html
|
||||
* 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
|
||||
* @param string $paper_size
|
||||
* (optional) Paper size of the generated PDF
|
||||
* @param string $page_orientation
|
||||
* (optional) Page orientation of the generated PDF
|
||||
*
|
||||
* @return
|
||||
* 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->writeHTML($html);
|
||||
|
||||
return $pdf->Output();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alters the list of available PDF libraries.
|
||||
*
|
||||
* During the configuration of the PDF library to be used, the module needs
|
||||
* to discover and display the available libraries. This function should use
|
||||
* the internal _print_scan_libs() function which will scan both the module
|
||||
* and the libraries directory in search of the unique file pattern that can
|
||||
* be used to identify the library location.
|
||||
*
|
||||
* @param array $pdf_tools
|
||||
* An associative array using as key the format 'module|path', and as value
|
||||
* a string describing the discovered library, where:
|
||||
* - module: the machine name of the module that handles this library.
|
||||
* - path: the path where the library is installed, relative to DRUPAL_ROOT.
|
||||
* If the recommended path is used, it begins with sites/all/libraries.
|
||||
* As a recommendation, the value should contain in parantheses the path
|
||||
* where the library was found, to allow the user to distinguish between
|
||||
* multiple install paths of the same library version.
|
||||
*
|
||||
* @ingroup print_hooks
|
||||
*/
|
||||
function hook_print_pdf_available_libs_alter(&$pdf_tools) {
|
||||
module_load_include('inc', 'print', 'includes/print');
|
||||
$tools = _print_scan_libs('foo', '!^foo.php$!');
|
||||
|
||||
foreach ($tools as $tool) {
|
||||
$pdf_tools['print_pdf_foo|' . $tool] = 'foo (' . dirname($tool) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alters the PDF filename.
|
||||
*
|
||||
* Changes the value of the PDF filename variable, just before it is used to
|
||||
* create the file. When altering the variable, do not suffix it with the
|
||||
* '.pdf' extension, as the module will do that automatically.
|
||||
*
|
||||
* @param string $pdf_filename
|
||||
* 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.
|
||||
*
|
||||
* @ingroup print_hooks
|
||||
*/
|
||||
function hook_print_pdf_filename_alter(&$pdf_filename, &$path) {
|
||||
$pdf_filename = 'foo';
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
@@ -5,32 +5,19 @@
|
||||
* drush integration for print_pdf module PDF libraries download.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The PDF project download URL
|
||||
*/
|
||||
|
||||
// TCPDF is in sourceforge, and nicely provides a link to the latest version
|
||||
define('TCPDF_DOWNLOAD_URI', 'http://sourceforge.net/projects/tcpdf/files/latest');
|
||||
|
||||
// URI to the the latest dompdf version.. Hardcoded version unfortunately
|
||||
define('DOMPDF_DOWNLOAD_URI', 'http://dompdf.googlecode.com/files/dompdf_0-6-0_beta3.tar.gz');
|
||||
|
||||
// wkhtmltopdf is a binary, requiring a different download for each platform
|
||||
define('WKHTMLTOPDF_AMD64_DOWNLOAD_URI', 'http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2');
|
||||
define('WKHTMLTOPDF_I386_DOWNLOAD_URI', 'http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2');
|
||||
define('WKHTMLTOPDF_WIN_DOWNLOAD_URI', 'http://wkhtmltopdf.googlecode.com/files/wkhtmltox-0.11.0_rc1-installer.exe');
|
||||
define('WKHTMLTOPDF_OSX_DOWNLOAD_URI', 'http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-OSX-0.10.0_rc2-static.tar.bz2');
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function print_pdf_drush_command() {
|
||||
$items = array();
|
||||
|
||||
$pdf_libs = array();
|
||||
drush_command_invoke_all_ref('drush_pdf_libs_alter', $pdf_libs);
|
||||
|
||||
$items['print-pdf-download'] = array(
|
||||
'description' => 'Download a PDF library.',
|
||||
'description' => 'Download and extract a PDF library.',
|
||||
'arguments' => array(
|
||||
'library' => dt('The PDF library to download. Either tcpdf, dompdf or wkhtmltopdf.'),
|
||||
'library' => dt('The PDF library to download. Available choices: !libs.', array('!libs' => implode(', ', array_keys($pdf_libs)))),
|
||||
),
|
||||
'options' => array(
|
||||
'path' => dt('A path to the download folder. If omitted Drush will use the default location (@path).', array('@path' => 'sites/all/libraries')),
|
||||
@@ -42,177 +29,37 @@ function print_pdf_drush_command() {
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of 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)))));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download and extract PDF archive.
|
||||
*
|
||||
* @param string $library
|
||||
* library to download
|
||||
*/
|
||||
function drush_print_pdf_download($library) {
|
||||
if (isset($library)) {
|
||||
$download_url = _drush_print_pdf_download_url($library);
|
||||
$pdf_libs = array();
|
||||
drush_command_invoke_all_ref('drush_pdf_libs_alter', $pdf_libs);
|
||||
|
||||
if (isset($library) && isset($pdf_libs[drupal_strtolower($library)])) {
|
||||
$func = $pdf_libs[drupal_strtolower($library)]['callback'];
|
||||
|
||||
$download_url = $func();
|
||||
if ($download_url) {
|
||||
$path = drush_get_option('path');
|
||||
if (empty($path)) {
|
||||
$path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries';
|
||||
}
|
||||
|
||||
// Create the path if it does not exist.
|
||||
if (!is_dir($path)) {
|
||||
drush_op('mkdir', $path);
|
||||
drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
|
||||
}
|
||||
|
||||
// Chdir to the download location.
|
||||
$olddir = getcwd();
|
||||
drush_op('chdir', $path);
|
||||
|
||||
// Warn about an existing dir
|
||||
if (is_dir($library)) {
|
||||
// drush_op('rmdir', $library); // Directory must be empty for the php rmdir to work..
|
||||
drush_log(dt('An existing @library was overwritten at @path', array('@library' => $library, '@path' => $path . '/' . $library)), 'notice');
|
||||
}
|
||||
|
||||
// Download the archive
|
||||
$filename = _drush_print_pdf_download_file($download_url);
|
||||
if ($filename) {
|
||||
$extract_ret = _drush_print_pdf_download_extract($filename);
|
||||
if ($extract_ret) {
|
||||
// Remove the archive
|
||||
drush_op('unlink', $filename);
|
||||
drush_log(dt('@file has been downloaded and extracted in @path', array('@file' => $filename, '@path' => $path)), 'success');
|
||||
}
|
||||
else {
|
||||
drush_log(dt('@file has been downloaded to @path, but extract failed. Check that you have the necessary program installed, and if necessary extract it manually.',
|
||||
array('@file' => $filename, '@path' => $path)), 'warning');
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_log(dt('Drush was unable to download @library to @path', array('@library' => $library, '@path' => $path)), 'error');
|
||||
}
|
||||
|
||||
// Set working directory back to the previous working directory.
|
||||
drush_op('chdir', $olddir);
|
||||
_print_drush_download_lib($library, $download_url);
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_log(dt('Please specify a PDF library. Currently supported libraries are dompdf, tcpdf and wkhtmltopdf.'), 'error');
|
||||
drush_log(dt('Please specify a PDF library. Available choices: !libs.', array('!libs' => implode(', ', array_keys($pdf_libs)))), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover the correct URL of the package to download
|
||||
*/
|
||||
function _drush_print_pdf_download_url($library) {
|
||||
$ret = FALSE;
|
||||
|
||||
switch (drupal_strtolower($library)) {
|
||||
case 'dompdf':
|
||||
$ret = DOMPDF_DOWNLOAD_URI;
|
||||
break;
|
||||
case 'tcpdf':
|
||||
$ret = TCPDF_DOWNLOAD_URI;
|
||||
break;
|
||||
case 'wkhtmltopdf':
|
||||
switch (drupal_substr(php_uname('s'), 0, 3)) {
|
||||
case 'Lin':
|
||||
$ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_AMD64_DOWNLOAD_URI : WKHTMLTOPDF_I386_DOWNLOAD_URI;
|
||||
break;
|
||||
case 'Win':
|
||||
$ret = WKHTMLTOPDF_WIN_DOWNLOAD_URI;
|
||||
break;
|
||||
case 'Dar':
|
||||
$ret = WKHTMLTOPDF_OSX_DOWNLOAD_URI;
|
||||
break;
|
||||
default:
|
||||
drush_log(dt('wkhtmltopdf is not supported in this system, please choose another library.'), 'error');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
drush_log(dt('Unknown PDF library specified, please use one of the supported PDF libraries.'), 'error');
|
||||
break;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to download and extract the zip/tar archive.
|
||||
*/
|
||||
function _drush_print_pdf_download_extract($filename) {
|
||||
$arch_ret = FALSE;
|
||||
|
||||
if (drush_op('is_file', $filename)) {
|
||||
switch (drush_op('mime_content_type', $filename)) {
|
||||
case 1:
|
||||
$arch_ret = TRUE;
|
||||
break;
|
||||
case 'application/zip':
|
||||
// Decompress the zip archive
|
||||
$arch_ret = drush_shell_exec('unzip -qq -o ' . $filename);
|
||||
// ZIP archives usually get the access rights wrong
|
||||
drush_log(dt('@filename is a Zip file. Check the access permissions of the extracted files.', array('@filename' => $filename)), 'warning');
|
||||
break;
|
||||
case 'application/x-gzip':
|
||||
// Decompress the tar gz archive
|
||||
$arch_ret = drush_shell_exec('tar xzf ' . $filename);
|
||||
break;
|
||||
case 'application/x-bzip2':
|
||||
// Decompress the tar bz2 archive
|
||||
$arch_ret = drush_shell_exec('tar xjf ' . $filename);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
drush_log(dt('@filename not found.', array('@filename' => $filename)), 'error');
|
||||
}
|
||||
|
||||
return $arch_ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file using wget or curl
|
||||
*
|
||||
* Adapted from a function in drush/includes/drush.inc to support 302 redirects.
|
||||
*
|
||||
* @param string $download_url
|
||||
* The path to the file to download
|
||||
*
|
||||
* @return string
|
||||
* The filename that was downloaded, or NULL if the file could not be
|
||||
* downloaded.
|
||||
*/
|
||||
function _drush_print_pdf_download_file($download_url) {
|
||||
$wget_ret = drush_shell_exec("wget -nv --trust-server-names %s", $download_url);
|
||||
|
||||
if (!drush_get_context('DRUSH_SIMULATE')) {
|
||||
if ($wget_ret) {
|
||||
// Get the filename of the saved file from the output
|
||||
$wget_out = explode('"', array_shift(drush_shell_exec_output()));
|
||||
$filename = $wget_out[1];
|
||||
}
|
||||
else {
|
||||
$tempnam = uniqid('drush_print_pdf_');
|
||||
|
||||
$curl_ret = drush_shell_exec("curl -s -L -o %s %s -w '%%{url_effective}'", $tempnam, $download_url);
|
||||
if ($curl_ret) {
|
||||
// File was donwloaded with the tempname
|
||||
|
||||
// Find the effective name
|
||||
$filename = explode('/', array_shift(drush_shell_exec_output()));
|
||||
$filename = array_pop($filename);
|
||||
|
||||
// Rename file from tempname to effective name
|
||||
if (!drush_op('rename', $tempnam, './' . $filename)) {
|
||||
$filename = $tempnam;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$filename = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$filename = basename($download_url);
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
@@ -1,18 +1,13 @@
|
||||
name = "PDF version"
|
||||
description = "Adds the capability to export pages as PDF."
|
||||
core=7.x
|
||||
description = "Adds the capability to export pages as PDF. Requires a PDF library and the respective handler module."
|
||||
core = 7.x
|
||||
package = "Printer, email and PDF versions"
|
||||
dependencies[] = print
|
||||
files[] = print_pdf.module
|
||||
files[] = print_pdf.admin.inc
|
||||
files[] = print_pdf.pages.inc
|
||||
files[] = print_pdf.install
|
||||
files[] = print_pdf.views.inc
|
||||
configure = admin/config/user-interface/print/pdf
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-09-04
|
||||
version = "7.x-1.2"
|
||||
; Information added by Drupal.org packaging script on 2014-04-02
|
||||
version = "7.x-2.0"
|
||||
core = "7.x"
|
||||
project = "print"
|
||||
datestamp = "1346768900"
|
||||
datestamp = "1396426766"
|
||||
|
||||
|
@@ -27,30 +27,28 @@ function print_pdf_enable() {
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function print_pdf_uninstall() {
|
||||
variable_del('print_pdf_settings');
|
||||
variable_del('print_pdf_show_link');
|
||||
variable_del('print_pdf_autoconfig');
|
||||
variable_del('print_pdf_cache_enabled');
|
||||
variable_del('print_pdf_cache_lifetime');
|
||||
variable_del('print_pdf_content_disposition');
|
||||
variable_del('print_pdf_display_sys_urllist');
|
||||
variable_del('print_pdf_filename');
|
||||
variable_del('print_pdf_images_via_file');
|
||||
variable_del('print_pdf_link_text');
|
||||
variable_del('print_pdf_link_text_enabled');
|
||||
variable_del('print_pdf_page_orientation');
|
||||
variable_del('print_pdf_paper_size');
|
||||
variable_del('print_pdf_pdf_tool');
|
||||
|
||||
variable_del('print_pdf_book_link');
|
||||
variable_del('print_pdf_link_class');
|
||||
variable_del('print_pdf_link_pos');
|
||||
variable_del('print_pdf_link_teaser');
|
||||
variable_del('print_pdf_node_link_visibility');
|
||||
variable_del('print_pdf_node_link_pages');
|
||||
variable_del('print_pdf_link_class');
|
||||
variable_del('print_pdf_sys_link_visibility');
|
||||
variable_del('print_pdf_sys_link_pages');
|
||||
variable_del('print_pdf_book_link');
|
||||
variable_del('print_pdf_pdf_tool');
|
||||
variable_del('print_pdf_content_disposition');
|
||||
variable_del('print_pdf_paper_size');
|
||||
variable_del('print_pdf_page_orientation');
|
||||
variable_del('print_pdf_images_via_file');
|
||||
variable_del('print_pdf_font_family');
|
||||
variable_del('print_pdf_font_size');
|
||||
variable_del('print_pdf_link_text');
|
||||
variable_del('print_pdf_link_use_alias');
|
||||
variable_del('print_pdf_filename');
|
||||
variable_del('print_pdf_autoconfig');
|
||||
variable_del('print_pdf_dompdf_unicode');
|
||||
variable_del('print_pdf_wkhtmltopdf_options');
|
||||
variable_del('print_pdf_display_sys_urllist');
|
||||
variable_del('print_pdf_show_link');
|
||||
variable_del('print_pdf_sys_link_pages');
|
||||
variable_del('print_pdf_sys_link_visibility');
|
||||
|
||||
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_pdf\_display\_%'");
|
||||
foreach ($settings as $variable) {
|
||||
variable_del($variable->name);
|
||||
@@ -94,6 +92,17 @@ function print_pdf_schema() {
|
||||
'size' => 'tiny',
|
||||
'description' => 'Show Printer-friendly URLs list',
|
||||
),
|
||||
'size' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 9,
|
||||
'description' => 'Paper size',
|
||||
),
|
||||
'orientation' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 9,
|
||||
'description' => 'Page orientation',
|
||||
),
|
||||
|
||||
),
|
||||
'primary key' => array('nid'),
|
||||
);
|
||||
@@ -103,7 +112,7 @@ function print_pdf_schema() {
|
||||
'fields' => array(
|
||||
'path' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'description' => 'Page path',
|
||||
),
|
||||
@@ -146,12 +155,87 @@ function print_pdf_update_7000(&$sandbox) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete old variables
|
||||
*/
|
||||
function print_pdf_update_7200(&$sandbox) {
|
||||
variable_del('print_pdf_settings');
|
||||
|
||||
variable_del('print_pdf_node_link_pages');
|
||||
variable_del('print_pdf_node_link_visibility');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
|
||||
if (count($tool) == 1) {
|
||||
// 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];
|
||||
}
|
||||
elseif (preg_match('!tcpdf.php$!', $tool[0])) {
|
||||
$tool[0] = 'print_pdf_tcpdf|' . $tool[0];
|
||||
}
|
||||
elseif (preg_match('!wkhtmltopdf!', $tool[0])) {
|
||||
$tool[0] = 'print_pdf_wkhtmltopdf|' . $tool[0];
|
||||
}
|
||||
else {
|
||||
$tool[0] = PRINT_PDF_PDF_TOOL_DEFAULT;
|
||||
}
|
||||
|
||||
variable_set('print_pdf_pdf_tool', $tool[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable block and help area links
|
||||
*/
|
||||
function print_pdf_update_7101(&$sandbox) {
|
||||
function print_pdf_update_7202(&$sandbox) {
|
||||
$link_pos = variable_get('print_pdf_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
|
||||
$link_pos['block'] = 'block';
|
||||
$link_pos['help'] = 'help';
|
||||
variable_set('print_pdf_link_pos', $link_pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Size and Orientation fields for per content type Size and Orientation
|
||||
*/
|
||||
function print_pdf_update_7203(&$sandbox) {
|
||||
$spec = array(
|
||||
'type' => 'varchar',
|
||||
'length' => 9,
|
||||
'description' => 'Paper size',
|
||||
);
|
||||
db_add_field('print_pdf_node_conf', 'size', $spec);
|
||||
$spec = array(
|
||||
'type' => 'varchar',
|
||||
'length' => 9,
|
||||
'description' => 'Page orientation',
|
||||
);
|
||||
db_add_field('print_pdf_node_conf', 'orientation', $spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
|
||||
if (count($tool) == 2) {
|
||||
module_enable(array($tool[0]), FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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('primary key' => array('path')));
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -44,12 +44,12 @@ function print_pdf_controller() {
|
||||
|
||||
$pdf_filename = variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT);
|
||||
if (!empty($pdf_filename) && !empty($node)) {
|
||||
$pdf_filename = token_replace($pdf_filename, array('node' => $node));
|
||||
$pdf_filename = token_replace($pdf_filename, array('node' => $node), array('clear' => TRUE));
|
||||
}
|
||||
else {
|
||||
$pdf_filename = token_replace($pdf_filename, array('site'));
|
||||
if (empty($pdf_filename) || count(token_scan($pdf_filename))) {
|
||||
// If there are still tokens, use a fallback solution
|
||||
$pdf_filename = token_replace($pdf_filename, array('site'), array('clear' => TRUE));
|
||||
if (empty($pdf_filename)) {
|
||||
// If empty, use a fallback solution
|
||||
$pdf_filename = str_replace('/', '_', $path);
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ function print_pdf_controller() {
|
||||
exit;
|
||||
}
|
||||
|
||||
$nodepath = (isset($node->path) && is_string($node->path)) ? drupal_get_normal_path($node->path) : 'node/' . $path;
|
||||
$nodepath = (isset($node->nid)) ? 'node/' . $node->nid : drupal_get_normal_path($path);
|
||||
db_merge('print_pdf_page_counter')
|
||||
->key(array('path' => $nodepath))
|
||||
->fields(array(
|
||||
@@ -83,548 +83,98 @@ function print_pdf_controller() {
|
||||
drupal_exit();
|
||||
}
|
||||
|
||||
function print_pdf_generate_path($path, $query = NULL, $cid = NULL, $pdf_filename = NULL) {
|
||||
/**
|
||||
* Gennerate a PDF for a given Drupal path.
|
||||
*
|
||||
* @param string $path
|
||||
* 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
|
||||
* @param int $cid
|
||||
* (optional) comment ID of the comment to render.
|
||||
* @param string $pdf_filename
|
||||
* (optional) filename of the generated PDF
|
||||
* @param string $view_mode
|
||||
* (optional) view mode to be used when rendering the content
|
||||
*
|
||||
* @return
|
||||
* generated PDF page, or NULL in case of error
|
||||
*
|
||||
* @see print_pdf_controller()
|
||||
*/
|
||||
function print_pdf_generate_path($path, $query = NULL, $cid = NULL, $pdf_filename = NULL, $view_mode = PRINT_VIEW_MODE) {
|
||||
global $base_url;
|
||||
|
||||
$print = print_controller($path, $query, $cid, PRINT_PDF_FORMAT);
|
||||
if ($print === FALSE) {
|
||||
return;
|
||||
}
|
||||
$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
|
||||
$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);
|
||||
|
||||
// Img elements must be set to absolute
|
||||
$pattern = '!<(img\s[^>]*?)>!is';
|
||||
$print['content'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['content']);
|
||||
$print['logo'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['logo']);
|
||||
$print['footer_message'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['footer_message']);
|
||||
$function = $pdf_tool[0] . '_pdf_tool_info';
|
||||
if (function_exists($function)) {
|
||||
$info = $function();
|
||||
}
|
||||
$expand = isset($info['expand_css']) ? $info['expand_css'] : FALSE;
|
||||
|
||||
// Send to printer option causes problems with PDF
|
||||
$print['sendtoprinter'] = '';
|
||||
$html = theme('print', array('node' => $node, 'query' => $query, $expand, 'format' => $link['format']));
|
||||
|
||||
$node = $print['node'];
|
||||
$html = theme('print', array('print' => $print, 'type' => PRINT_PDF_FORMAT, 'node' => $node));
|
||||
// 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
|
||||
$pattern = '!<(a\s[^>]*?)>!is';
|
||||
$html = preg_replace_callback($pattern, '_print_rewrite_urls', $html);
|
||||
// And make anchor links relative again, to permit in-PDF navigation
|
||||
$html = preg_replace("!${base_url}/" . PRINTPDF_PATH . '/.*?#!', '#', $html);
|
||||
// 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
|
||||
$html = preg_replace("!${base_url}/" . $link['path'] . '/.*?#!', '#', $html);
|
||||
|
||||
return print_pdf_generate_html($print, $html, $pdf_filename);
|
||||
}
|
||||
$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;
|
||||
|
||||
function print_pdf_generate_html($print, $html, $filename = NULL) {
|
||||
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
|
||||
$paper_size = isset($node->print_pdf_size) ? $node->print_pdf_size : NULL;
|
||||
$page_orientation = isset($node->print_pdf_orientation) ? $node->print_pdf_orientation : NULL;
|
||||
|
||||
if (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
|
||||
return _print_pdf_dompdf($print, $html, $filename);
|
||||
}
|
||||
elseif (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
|
||||
return _print_pdf_tcpdf($print, $html, $filename);
|
||||
}
|
||||
elseif (drupal_substr(basename($print_pdf_pdf_tool, '.exe'), 0, 11) == 'wkhtmltopdf') {
|
||||
return _print_pdf_wkhtmltopdf($print, $html, $filename);
|
||||
}
|
||||
elseif ($filename) {
|
||||
return drupal_not_found();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert image paths to the file:// protocol
|
||||
*
|
||||
* In some Drupal setups, the use of the 'private' filesystem or Apache's
|
||||
* configuration prevent access to the images of the page. This function
|
||||
* tries to circumnvent those problems by accessing files in the local
|
||||
* filesystem.
|
||||
*
|
||||
* @param $html
|
||||
* contents of the post-processed template already with the node data
|
||||
* @see print_pdf_controller()
|
||||
*/
|
||||
function _print_pdf_file_access_images($html) {
|
||||
global $base_url, $language;
|
||||
$print_pdf_images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
|
||||
|
||||
$lang = (function_exists('language_negotiation_get_any') && language_negotiation_get_any('locale-url')) ? $language->language : '';
|
||||
|
||||
// Always convert private to local paths
|
||||
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?system/files/([^>]*?>)!is";
|
||||
$replacement = '$1file://' . realpath(variable_get('file_private_path', '')) . '/$2';
|
||||
$html = preg_replace($pattern, $replacement, $html);
|
||||
if ($print_pdf_images_via_file) {
|
||||
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?([^>]*?>)!is";
|
||||
$replacement = '$1file://' . dirname($_SERVER['SCRIPT_FILENAME']) . '/$2';
|
||||
$html = preg_replace($pattern, $replacement, $html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the PDF file using the dompdf library
|
||||
*
|
||||
* @param $print
|
||||
* array containing the configured data
|
||||
* @param $html
|
||||
* contents of the post-processed template already with the node data
|
||||
* @param $filename
|
||||
* name of the PDF file to be generated
|
||||
* @see print_pdf_controller()
|
||||
*/
|
||||
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));
|
||||
define("DOMPDF_FONT_CACHE", drupal_realpath('public://' . PRINT_PDF_DOMPDF_CACHE_DIR_DEFAULT . '/fonts/'));
|
||||
}
|
||||
|
||||
require_once(DRUPAL_ROOT . '/' . $print_pdf_pdf_tool);
|
||||
spl_autoload_register('DOMPDF_autoload');
|
||||
|
||||
// Try to use local file access for image files
|
||||
$html = _print_pdf_file_access_images($html);
|
||||
|
||||
// Spaces in img URLs must be replaced with %20
|
||||
$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
|
||||
$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', array('html' => $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);
|
||||
}
|
||||
// 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');
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the PDF file using the TCPDF library
|
||||
*
|
||||
* @param $print
|
||||
* array containing the configured data
|
||||
* @param $html
|
||||
* contents of the post-processed template already with the node data
|
||||
* @param $filename
|
||||
* name of the PDF file to be generated
|
||||
* @see print_pdf_controller()
|
||||
*/
|
||||
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', drupal_realpath('public://' . PRINT_PDF_TCPDF_CACHE_DIR_DEFAULT . '/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(DRUPAL_ROOT . '/' . $print_pdf_pdf_tool);
|
||||
module_load_include('inc', 'print_pdf', 'print_pdf.class');
|
||||
|
||||
$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
|
||||
if (property_exists($print['node'], 'name')) {
|
||||
$pdf->SetAuthor(strip_tags($print['node']->name));
|
||||
}
|
||||
$pdf->SetCreator(variable_get('site_name', 'Drupal'));
|
||||
$pdf->SetTitle(html_entity_decode($print['title'], ENT_QUOTES, 'UTF-8'));
|
||||
$pdf->setPDFVersion('1.6');
|
||||
$pdf->setFontSubsetting(variable_get('print_pdf_font_subsetting', PRINT_PDF_FONT_SUBSETTING_DEFAULT));
|
||||
|
||||
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_page', array('pdf' => $pdf));
|
||||
|
||||
// add a page
|
||||
$pdf->AddPage();
|
||||
|
||||
$pdf = theme('print_pdf_tcpdf_content', array('pdf' => $pdf, 'html' => $html, 'font' => $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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the PDF file using wkhtmltopdf
|
||||
*
|
||||
* @param $print
|
||||
* array containing the configured data
|
||||
* @param $html
|
||||
* contents of the post-processed template already with the node data
|
||||
* @param $filename
|
||||
* name of the PDF file to be generated
|
||||
* @see print_pdf_controller()
|
||||
*/
|
||||
function _print_pdf_wkhtmltopdf($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);
|
||||
$print_pdf_wkhtmltopdf_options = variable_get('print_pdf_wkhtmltopdf_options', PRINT_PDF_WKHTMLTOPDF_OPTIONS);
|
||||
|
||||
$dpi = 96;
|
||||
|
||||
if (!empty($print_pdf_wkhtmltopdf_options)) {
|
||||
$print_pdf_wkhtmltopdf_options = token_replace($print_pdf_wkhtmltopdf_options, array('node' => $print['node']));
|
||||
}
|
||||
|
||||
$version = _print_pdf_wkhtmltopdf_version();
|
||||
|
||||
// 0.10.0 beta2 identifies itself as 0.9.9
|
||||
if (version_compare($version, '0.9.9', '>=')) {
|
||||
$print_pdf_wkhtmltopdf_options = '--disable-local-file-access ' . $print_pdf_wkhtmltopdf_options;
|
||||
}
|
||||
elseif (version_compare($version, '0.9.6', '>=')) {
|
||||
$print_pdf_wkhtmltopdf_options = '--disallow-local-file-access ' . $print_pdf_wkhtmltopdf_options;
|
||||
}
|
||||
else {
|
||||
drupal_goto($print['url']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'a'));
|
||||
$cmd = '"' . realpath($print_pdf_pdf_tool) . "\" --page-size $print_pdf_paper_size --orientation $print_pdf_page_orientation --dpi $dpi $print_pdf_wkhtmltopdf_options - -";
|
||||
|
||||
$process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
|
||||
|
||||
if (is_resource($process)) {
|
||||
fwrite($pipes[0], $html);
|
||||
fclose($pipes[0]);
|
||||
|
||||
$pdf = stream_get_contents($pipes[1]);
|
||||
fclose($pipes[1]);
|
||||
|
||||
stream_set_blocking($pipes[2], 0);
|
||||
$error = stream_get_contents($pipes[2]);
|
||||
fclose($pipes[2]);
|
||||
|
||||
$retval = proc_close($process);
|
||||
if (!empty($error) || ($retval != 0)) {
|
||||
if (empty($error)) {
|
||||
$error = 'No stderr output available.';
|
||||
$pdf = '';
|
||||
$cachemiss = FALSE;
|
||||
if ($cache_enabled && isset($node->nid)) {
|
||||
// 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
|
||||
$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', "wkhtmltopdf (returned $retval): $error");
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($pdf)) {
|
||||
if ($filename) {
|
||||
if (headers_sent()) {
|
||||
exit("Unable to stream pdf: headers already sent");
|
||||
else {
|
||||
$cachemiss = TRUE;
|
||||
}
|
||||
header("Cache-Control: private");
|
||||
header("Content-Type: application/pdf");
|
||||
|
||||
$attachment = ($print_pdf_content_disposition == 2) ? "attachment" : "inline";
|
||||
|
||||
header("Content-Disposition: $attachment; filename=\"$filename\"");
|
||||
|
||||
echo $pdf;
|
||||
flush();
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
return $pdf;
|
||||
|
||||
// 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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return $pdf_filename ? print_pdf_dispose_content($pdf, $pdf_filename) : $pdf;
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('Unable to generate PDF file.'), 'error');
|
||||
drupal_goto($meta['url']);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the dompdf footer contents
|
||||
*
|
||||
* @param $html
|
||||
* contents of the body of the HTML from the original node
|
||||
* @see theme_print_pdf_tcpdf_footer()
|
||||
*/
|
||||
function theme_print_pdf_dompdf_footer($vars) {
|
||||
preg_match('!<div class="print-footer">(.*?)</div>!si', $vars['html'], $tpl_footer);
|
||||
$html = str_replace($tpl_footer[0], '', $vars['html']);
|
||||
|
||||
$text = '<script type="text/php">
|
||||
if (isset($pdf)) {
|
||||
$font = Font_Metrics::get_font("verdana");;
|
||||
$size = 10;
|
||||
$color = array(0,0,0);
|
||||
$text_height = Font_Metrics::get_font_height($font, $size);
|
||||
|
||||
$w = $pdf->get_width();
|
||||
$h = $pdf->get_height();
|
||||
|
||||
$footer = $pdf->open_object();
|
||||
|
||||
// Draw a line along the bottom
|
||||
$y = $h - 25;
|
||||
$pdf->line(15, $y, $w - 15, $y, $color, 1);
|
||||
|
||||
$y += $text_height / 2;
|
||||
$pdf->page_text(15, $y, \'' . addslashes(strip_tags($tpl_footer[1])) . '\', $font, $size, $color);
|
||||
|
||||
$pdf->close_object();
|
||||
$pdf->add_object($footer, "all");
|
||||
|
||||
// Center the text
|
||||
$width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size);
|
||||
$pagenumtxt = t("Page !n of !total", array("!n" => "{PAGE_NUM}", "!total" => "{PAGE_COUNT}"));
|
||||
$pdf->page_text($w - 15 - $width, $y, $pagenumtxt, $font, $size, $color);
|
||||
}
|
||||
</script>';
|
||||
|
||||
return str_replace("<body>", "<body>" . $text, $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF header
|
||||
*
|
||||
* @param $pdf
|
||||
* current TCPDF object
|
||||
* @param $html
|
||||
* contents of the body of the HTML from the original node
|
||||
* @param $font
|
||||
* array with the font definition (font name, styles and size)
|
||||
* @see theme_print_pdf_tcpdf_header()
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_header($vars) {
|
||||
$pdf = $vars['pdf'];
|
||||
preg_match('!<div class="print-logo">(.*?)</div>!si', $vars['html'], $tpl_logo);
|
||||
preg_match('!<title>(.*?)</title>!si', $vars['html'], $tpl_title);
|
||||
preg_match('!<div class="print-site_name">(.*?)</div>!si', $vars['html'], $tpl_site_name);
|
||||
|
||||
$ratio = 0;
|
||||
$logo = '';
|
||||
if (isset($tpl_logo[1]) && preg_match('!src\s*=\s*(?:"(.*?)"|\'(.*?)\'|([^\s]*))!i', $tpl_logo[1], $logo_url)) {
|
||||
$logo = $logo_url[1];
|
||||
if (!empty($logo)) {
|
||||
$size = getimagesize($logo);
|
||||
$ratio = $size ? ($size[0] / $size[1]) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
// set header font
|
||||
$pdf->setHeaderFont($vars['font']);
|
||||
// set header margin
|
||||
$pdf->setHeaderMargin(5);
|
||||
// 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)
|
||||
*
|
||||
* @param $pdf
|
||||
* current TCPDF object
|
||||
* @see theme_print_pdf_tcpdf_page()
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_page($vars) {
|
||||
$pdf = $vars['pdf'];
|
||||
// set margins
|
||||
$pdf->SetMargins(15, 20, 15);
|
||||
// set auto page breaks
|
||||
$pdf->SetAutoPageBreak(TRUE, 15);
|
||||
// set image scale factor
|
||||
$pdf->setImageScale(1);
|
||||
// set image compression quality
|
||||
$pdf->setJPEGQuality(100);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF page content
|
||||
*
|
||||
* @param $pdf
|
||||
* current TCPDF object
|
||||
* @param $html
|
||||
* contents of the body of the HTML from the original node
|
||||
* @param $font
|
||||
* array with the font definition (font name, styles and size)
|
||||
* @see theme_print_pdf_tcpdf_content()
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_content($vars) {
|
||||
$pdf = $vars['pdf'];
|
||||
// set content font
|
||||
$pdf->setFont($vars['font'][0], $vars['font'][1], $vars['font'][2]);
|
||||
|
||||
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
|
||||
$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
|
||||
$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 {
|
||||
$prev = $matches[1];
|
||||
$matches[1] = preg_replace('!(</span>)<br />(\s*?</span><br />)!s', '$1$2', $matches[1]);
|
||||
} while ($prev != $matches[1]);
|
||||
|
||||
@$pdf->writeHTML($matches[1]);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF footer contents
|
||||
*
|
||||
* @param $pdf
|
||||
* current TCPDF object
|
||||
* @param $html
|
||||
* contents of the body of the HTML from the original node
|
||||
* @param $font
|
||||
* array with the font definition (font name, styles and size)
|
||||
* @see theme_print_pdf_tcpdf_footer()
|
||||
*/
|
||||
function theme_print_pdf_tcpdf_footer($vars) {
|
||||
$pdf = $vars['pdf'];
|
||||
preg_match('!<div class="print-footer">(.*?)</div>!si', $vars['html'], $tpl_footer);
|
||||
$footer = trim(preg_replace('!</?div[^>]*?>!i', '', $tpl_footer[1]));
|
||||
|
||||
// set footer font
|
||||
$vars['font'][2] *= 0.8;
|
||||
$pdf->setFooterFont($vars['font']);
|
||||
// set footer margin
|
||||
$pdf->SetFooterMargin(10);
|
||||
// set footer data
|
||||
$pdf->SetFooterData($footer);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the TCPDF footer layout
|
||||
*
|
||||
* @param $pdf
|
||||
* current TCPDF object
|
||||
* @see theme_print_pdf_tcpdf_footer2()
|
||||
*/
|
||||
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);
|
||||
|
||||
$ormargins = $pdf->getOriginalMargins();
|
||||
$pagenumtxt = t('Page !n of !total', array('!n' => $pdf->PageNo(), '!total' => $pdf->getAliasNbPages()));
|
||||
// Print page number
|
||||
if ($pdf->getRTL()) {
|
||||
$pdf->SetX($ormargins['right']);
|
||||
$pdf->Cell(0, 10, $pagenumtxt, 'T', 0, 'L');
|
||||
}
|
||||
else {
|
||||
$pdf->SetX($ormargins['left']);
|
||||
$pdf->Cell(0, 10, $pagenumtxt, 'T', 0, 'R');
|
||||
}
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ function print_pdf_views_data() {
|
||||
'left_field' => 'nid',
|
||||
'field' => 'path',
|
||||
// 'type' => 'INNER',
|
||||
'handler' => 'print_pdf_join_page_counter',
|
||||
'handler' => 'print_join_page_counter',
|
||||
);
|
||||
|
||||
// print_pdf_node_conf fields
|
||||
@@ -85,6 +85,34 @@ function print_pdf_views_data() {
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
$data['print_pdf_node_conf']['size'] = array(
|
||||
'title' => t('PDF: Paper size'),
|
||||
'help' => t('Configured PDF paper size'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
$data['print_pdf_node_conf']['orientation'] = array(
|
||||
'title' => t('PDF: Page orientation'),
|
||||
'help' => t('Configured PDF page orientation.'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
// print_pdf_page_counter fields
|
||||
|
Reference in New Issue
Block a user