diff --git a/print_pdf/print_pdf.admin.inc b/print_pdf/print_pdf.admin.inc index 44e73606e204672ec47756ce52bb134b8a5d5ace..98101e91560f0c678e2a1d751b61efd92244f07c 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 d400fc380bc62f8f99ae31ec8efd4261f6fd0806..ca5c4769a71f27c1c58314b45175aae0ccca3940 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);