function print_pdf_wkhtmltopdf_pdf_tool_version in Printer, email and PDF versions 7.2
Implements hook_pdf_tool_version().
2 calls to print_pdf_wkhtmltopdf_pdf_tool_version()
- print_pdf_wkhtmltopdf_print_pdf_available_libs_alter in print_pdf/
lib_handlers/ print_pdf_wkhtmltopdf/ print_pdf_wkhtmltopdf.module - Implements hook_print_pdf_available_libs_alter().
- print_pdf_wkhtmltopdf_print_pdf_generate in print_pdf/
lib_handlers/ print_pdf_wkhtmltopdf/ print_pdf_wkhtmltopdf.pages.inc - Implements hook_print_pdf_generate().
File
- print_pdf/
lib_handlers/ print_pdf_wkhtmltopdf/ print_pdf_wkhtmltopdf.module, line 57 - Generate a PDF for the print_pdf module using the wkhtmltopdf library.
Code
function print_pdf_wkhtmltopdf_pdf_tool_version($pdf_tool, $reset = TRUE) {
$version = variable_get('print_pdf_wkhtmltopdf_version', PRINT_PDF_WKHTMLTOPDF_VERSION_DEFAULT);
if ($reset || empty($version)) {
// Ask the version information from the executable.
$descriptor = array(
0 => array(
'pipe',
'r',
),
1 => array(
'pipe',
'w',
),
2 => array(
'pipe',
'w',
),
);
$cmd = '"' . realpath($pdf_tool) . '" --version';
$process = proc_open($cmd, $descriptor, $pipes, NULL, NULL);
if (is_resource($process)) {
$content = stream_get_contents($pipes[1]);
$found = preg_match('!.*?(\\d+\\.\\d+\\.\\d+).*$!m', $content, $matches);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
if ($found) {
// Cache the results of this expensive operation.
variable_set('print_pdf_wkhtmltopdf_version', $matches[1]);
return $matches[1];
}
}
}
else {
// For performance sake, usually use the cached value.
return $version;
}
return 'unknown';
}