X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FPDF%2FUtils.php;h=526202cb7c1f907425d6e5f6d9bb8296d1222f99;hb=58bf7133b342d156ce9299232936b3edbeedb40c;hp=6fc9959b8605fce66fa9a7553c4f88c91508b0db;hpb=f71afe4a955d2848ccad348a1c74ee2ebf49b404;p=civicrm-core.git diff --git a/CRM/Utils/PDF/Utils.php b/CRM/Utils/PDF/Utils.php index 6fc9959b86..526202cb7c 100644 --- a/CRM/Utils/PDF/Utils.php +++ b/CRM/Utils/PDF/Utils.php @@ -191,11 +191,17 @@ class CRM_Utils_PDF_Utils { if ($output) { return $dompdf->output(); } - else { - // CRM-19183 remove .pdf extension from filename - $fileName = basename($fileName, ".pdf"); - $dompdf->stream($fileName); + // CRM-19183 remove .pdf extension from filename + $fileName = basename($fileName, ".pdf"); + if (CIVICRM_UF === 'UnitTests' && headers_sent()) { + // Streaming content will 'die' in unit tests unless ob_start() + // has been called. + throw new CRM_Core_Exception_PrematureExitException('_html2pdf_dompdf called', [ + 'html' => $html, + 'fileName' => $fileName, + ]); } + $dompdf->stream($fileName); } /** @@ -207,8 +213,12 @@ class CRM_Utils_PDF_Utils { * @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");