summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoao Ventura2009-10-13 22:00:03 (GMT)
committer Joao Ventura2009-10-13 22:00:03 (GMT)
commit40d65a37a216468b4d26291652e03fdfba0bafe4 (patch)
tree5d0eb12d2c3fe7cc26a8b53b9670b84b839f0610
parent5d9572d7e21287e1f0c6dcffb40044c3274c1093 (diff)
Fix #521776: support wkhtmltopdf in Windows
-rw-r--r--print_pdf/print_pdf.admin.inc2
-rw-r--r--print_pdf/print_pdf.pages.inc14
2 files changed, 12 insertions, 4 deletions
diff --git a/print_pdf/print_pdf.admin.inc b/print_pdf/print_pdf.admin.inc
index 44e7360..98101e9 100644
--- a/print_pdf/print_pdf.admin.inc
+++ b/print_pdf/print_pdf.admin.inc
@@ -258,7 +258,7 @@ function _print_pdf_settings_validate($form, &$form_state) {
* 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)$!';
+ $pattern = '!^(?:dompdf_config.inc.php|tcpdf.php|wkhtmltopdf(?:.exe)?)$!';
$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)));
diff --git a/print_pdf/print_pdf.pages.inc b/print_pdf/print_pdf.pages.inc
index d400fc3..ca5c476 100644
--- a/print_pdf/print_pdf.pages.inc
+++ b/print_pdf/print_pdf.pages.inc
@@ -87,7 +87,7 @@ function print_pdf_controller() {
elseif (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
_print_pdf_tcpdf($print, $html, $pdf_filename);
}
- elseif (basename($print_pdf_pdf_tool) == 'wkhtmltopdf') {
+ elseif (basename($print_pdf_pdf_tool, '.exe') == 'wkhtmltopdf') {
_print_pdf_wkhtmltopdf($print, $html, $pdf_filename);
}
else {
@@ -303,7 +303,8 @@ function _print_pdf_wkhtmltopdf($print, $html, $filename) {
}
$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 $dpi $print_pdf_wkhtmltopdf_options - -";
+ $pdf_output = (stristr(PHP_OS, 'Win')) ? tempnam(variable_get('file_temporary_path', conf_path() . '/private/temp'), 'pdf') : '-';
+ $cmd = realpath($print_pdf_pdf_tool) . " --page-size $print_pdf_paper_size --orientation $print_pdf_page_orientation --dpi $dpi $print_pdf_wkhtmltopdf_options - $pdf_output";
$process = proc_open($cmd, $descriptor, $pipes, NULL, isset($xvfb_binary) ? array('DISPLAY' => ':' . $xdisplay) : NULL);
@@ -311,7 +312,14 @@ function _print_pdf_wkhtmltopdf($print, $html, $filename) {
fwrite($pipes[0], $html);
fclose($pipes[0]);
- $pdf = stream_get_contents($pipes[1]);
+ if (stristr(PHP_OS, 'Win')) {
+ // It seems Windows can't use the pipe properly so get the contents from a file and then delete it.
+ $pdf = file_get_contents($pdf_outputg);
+ unlink($pdf_output);
+ }
+ else {
+ $pdf = stream_get_contents($pipes[1]);
+ }
fclose($pipes[1]);
stream_set_blocking($pipes[2], 0);