Skip to content

Commit

Permalink
Merge pull request #19311 from seamuslee001/dev_core_2028
Browse files Browse the repository at this point in the history
dev/core#2028 Add in a status check for checking if the wkhtmltopdf p…
  • Loading branch information
seamuslee001 committed Jan 6, 2021
2 parents 208ecdd + 6bbe0cf commit a1692bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions CRM/Utils/Check/Component/Env.php
Expand Up @@ -960,4 +960,19 @@ public function checkPHPIntlExists() {
return $messages;
}

public function checkWkHtmlToPDFPath() {
$messages = [];
$wkhtmltopdfPath = CRM_Core_Config::singleton()->wkhtmltopdfPath;
if (!empty($wkhtmltopdfPath) && !file_exists($wkhtmltopdfPath)) {
$messages[] = new CRM_Utils_Check_Message(
__FUNCTION__,
ts('CiviCRM is configured to use the wkhtmltopdf package to produce PDFs however it is missing, as such the system will fall back to using the DOMPDF package, this may mean that the output is different to what was expected. You should resolve this by either clearing the setting at Administer -> System Settings -> Miscellaneous or by getting your system administrator to install the wkhtmltopdf package'),
ts('Missing System Package: wkhtmltopdf'),
\Psr\Log\LogLevel::WARNING,
'fa-server'
);
}
return $messages;
}

}
6 changes: 5 additions & 1 deletion CRM/Utils/PDF/Utils.php
Expand Up @@ -207,8 +207,12 @@ public static function _html2pdf_dompdf($paper_size, $orientation, $html, $outpu
* @param string $fileName
*/
public static function _html2pdf_wkhtmltopdf($paper_size, $orientation, $margins, $html, $output, $fileName) {
require_once 'snappy/src/autoload.php';
$config = CRM_Core_Config::singleton();
// if the path doesn't exist fall back on the current backup which is DOMPDF.
if (!file_exists($config->wkhtmltopdfPath)) {
return self::_html2pdf_dompdf($paper_size, $orientation, $html, $output, $fileName);
}
require_once 'snappy/src/autoload.php';
$snappy = new Knp\Snappy\Pdf($config->wkhtmltopdfPath);
$snappy->setOption("page-width", $paper_size[2] . "pt");
$snappy->setOption("page-height", $paper_size[3] . "pt");
Expand Down

0 comments on commit a1692bf

Please sign in to comment.