Commit d9a43552 authored by jcnventura's avatar jcnventura

Improve wkhtmltopdf documentation, configuration and add a directory to place external libraries

parent f9fa2e53
......@@ -25,7 +25,7 @@ dompdf support:
1. Download dompdf from http://sourceforge.net/projects/dompdf/
2. Extract the contents of the downloaded package into the print module
directory (usually sites/all/modules/print)
directory (usually sites/all/modules/print/lib)
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.
......@@ -42,10 +42,25 @@ TCPDF support:
1. Download TCPDF from http://sourceforge.net/projects/tcpdf/
2. Extract the contents of the downloaded package into the print module
directory (usually sites/all/modules/print). There is no need to modify
the config/tcpdf_config.php file, as the module self-configures TCPDF.
directory (usually sites/all/modules/print/lib). There is no need to
modify the config/tcpdf_config.php file, as the module self-configures
TCPDF.
3. Check http://tcpdf.sourceforge.net/ for further information.
wkhtmltopdf support:
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 complile anything.
2. Place the wkhtmltopdf executable into the print module directory
(usually sites/all/modules/print/lib). You can also place a symbolic link
to the executable.
3. You will need a running X Server or the virtual (headless) X
framebuffer server: Xvfb. Place the Xvfb binary or a symbolic link to it
in the print module directory (usually sites/all/modules/print/lib).
4. Check http://code.google.com/p/wkhtmltopdf/ for further information.
UPDATE
------
......
// $Id$
This directory should be used to place the downloaded external libs used by
the print module (such as TCPDF, dompdf, etc.).
......@@ -181,6 +181,19 @@ function print_pdf_settings() {
'#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_wkhtmltopdf_options'] = array(
'#type' => 'textfield',
'#title' => t('wkhtmltopdf options'),
'#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.'),
);
$form['settings']['print_pdf_xvfb_options'] = array(
'#type' => 'textfield',
'#title' => t('Xvfb options'),
'#default_value' => variable_get('print_pdf_xvfb_options', PRINT_PDF_XVFB_OPTIONS),
'#description' => t('(wkhtmltopdf only) Set any additional options to be passed to the Xvfb executable.'),
);
if (module_exists('token')) {
$form['settings']['print_pdf_filename'] = array(
'#type' => 'textfield',
......
......@@ -38,6 +38,8 @@ function print_pdf_uninstall() {
variable_del('print_pdf_link_use_alias');
variable_del('print_pdf_filename');
variable_del('print_pdf_wkhtmltopdf_xdisplay');
variable_del('print_pdf_wkhtmltopdf_options');
variable_del('print_pdf_xvfb_options');
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_pdf\_display\_%'");
foreach ($settings as $variable) {
variable_del($variable->name);
......
......@@ -26,6 +26,9 @@ define('PRINT_PDF_PAGE_ORIENTATION_DEFAULT', 'portrait');
define('PRINT_PDF_FONT_FAMILY_DEFAULT', 'dejavusans');
define('PRINT_PDF_FONT_SIZE_DEFAULT', 10);
define('PRINT_PDF_FILENAME_DEFAULT', '[site-name] - [title] - [mod-yyyy]-[mod-mm]-[mod-dd]');
define('PRINT_PDF_WKHTMLTOPDF_OPTIONS', "--footer-font-size 7 --footer-right '[page]'");
define('PRINT_PDF_XVFB_OPTIONS', '');
// define('PRINT_PDF_XVFB_OPTIONS', ' -fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/');
/**
* Implementation of hook_theme().
......
......@@ -267,12 +267,11 @@ function _print_pdf_wkhtmltopdf($print, $html, $filename) {
$print_pdf_paper_size = drupal_strtolower(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);
$print_pdf_xvfb_options = variable_get('print_pdf_xvfb_options', PRINT_PDF_XVFB_OPTIONS);
$xvfb_binary = key(file_scan_directory(drupal_get_path('module', 'print'), '!^Xvfb$!'));
define('WKHTMLTOPDF_DPI', '96');
define('WKHTMLTOPDF_OPTIONS', " --footer-font-size 7 --footer-right '[page]'");
// define('WKHTMLTOPDF_XVFB_OPTIONS', ' -fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/');
$dpi = 96;
// If available, launch a temporary X server
if (isset($xvfb_binary)) {
......@@ -280,16 +279,14 @@ function _print_pdf_wkhtmltopdf($print, $html, $filename) {
variable_set('print_pdf_wkhtmltopdf_xdisplay', ($xdisplay == 4990) ? 10 : $xdisplay + 10);
$xdisplay += mt_rand(0, 9);
$xcmd = realpath($xvfb_binary) . " :$xdisplay -screen 0 320x200x24 -dpi " . WKHTMLTOPDF_DPI .
' -terminate -nolisten tcp -tst' . (defined('WKHTMLTOPDF_XVFB_OPTIONS') ? WKHTMLTOPDF_XVFB_OPTIONS : '');
$xcmd = realpath($xvfb_binary) . " :$xdisplay -screen 0 320x200x24 -dpi $dpi -terminate -nolisten tcp -tst $print_pdf_xvfb_options";
$xdescriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
$xprocess = proc_open($xcmd, $xdescriptor, $xpipes, NULL, NULL);
}
$descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
$cmd = realpath($print_pdf_pdf_tool) . " --page-size $print_pdf_paper_size --orientation $print_pdf_page_orientation" .
' --dpi ' . WKHTMLTOPDF_DPI . (defined('WKHTMLTOPDF_OPTIONS') ? WKHTMLTOPDF_OPTIONS : '') . ' - -';
$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, isset($xvfb_binary) ? array('DISPLAY' => ':' . $xdisplay) : NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment