function commerce_billy_pdf_wkhtmltopdf in Commerce Billy 7
WKHTMLTOPDF converter
1 call to commerce_billy_pdf_wkhtmltopdf()
- commerce_billy_pdf_output in modules/
commerce_billy_pdf/ commerce_billy_pdf.module - Transforms HTML to PDF and outputs it to the browser.
File
- modules/
commerce_billy_pdf/ commerce_billy_pdf.module, line 284 - Commerce Billy module file.
Code
function commerce_billy_pdf_wkhtmltopdf($html, $filename, $as_file = FALSE) {
$path = libraries_get_path('phpwkhtmltopdf');
if (!empty($path)) {
$wkhtmltopdf_path = variable_get('wkhtmltopdf_path', '/usr/bin/wkhtmltopdf');
require_once DRUPAL_ROOT . '/' . $path . '/WkHtmlToPdf.php';
$filename .= '.pdf';
$tmp = file_directory_temp();
$pdf = new WkHtmlToPdf(array(
'binPath' => $wkhtmltopdf_path,
'tmp' => $tmp,
'no-outline',
'margin-top' => 0,
'margin-right' => 0,
'margin-bottom' => 0,
'margin-left' => 0,
// Default page options
'disable-smart-shrinking',
));
$pdf
->addPage($html);
if ($as_file) {
$pdf
->saveAs($tmp . '/' . $filename);
$file_content = file_get_contents($tmp . '/' . $filename);
return $file_content;
}
else {
$output = $pdf
->send($filename);
$error = $pdf
->getError();
// Log any errors.
if (!empty($error)) {
watchdog('commerce_billy_pdf', 'WkHtmlToPdf exception while generating pdf resume: %message', array(
'%message' => $error,
), WATCHDOG_ERROR);
return t('Error generating PDF resume. Please contact the website administrator.');
}
else {
return $output;
}
}
}
return t('WkHtmlToPdf not found');
}