dev/core#2028 Add in a status check for checking if the wkhtmltopdf package is instal...
authorSeamus Lee <seamuslee001@gmail.com>
Sun, 3 Jan 2021 21:04:53 +0000 (08:04 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Tue, 5 Jan 2021 22:56:18 +0000 (09:56 +1100)
CRM/Utils/Check/Component/Env.php
CRM/Utils/PDF/Utils.php

index 6b5f4f1778c4d0b53e646b8f76b6e79c2fb9bbaa..8b94015ea928e2152cb9855a61adb4da2ae52d4a 100644 (file)
@@ -960,4 +960,19 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
     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;
+  }
+
 }
index 6fc9959b8605fce66fa9a7553c4f88c91508b0db..730bbc3d4448f726e2ca30f87f221c4d478cd932 100644 (file)
@@ -207,8 +207,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");