Merge pull request #22599 from civicrm/5.46
[civicrm-core.git] / CRM / Utils / PDF / Utils.php
index 2459ce3af24d252599e6b4f2de72e23519e4fd48..a751baa1e38b9b72825d80d38a2c2e270598eaa3 100644 (file)
@@ -28,7 +28,7 @@ class CRM_Utils_PDF_Utils {
    *   Ex: "HelloWorld.pdf".
    * @param bool $output
    *   FALSE to display PDF. TRUE to return as string.
-   * @param null $pdfFormat
+   * @param array|int|null $pdfFormat
    *   Unclear. Possibly PdfFormat or formValues.
    *
    * @return string|void
@@ -179,10 +179,7 @@ class CRM_Utils_PDF_Utils {
    * @return string
    */
   public static function _html2pdf_dompdf($paper_size, $orientation, $html, $output, $fileName) {
-    // CRM-12165 - Remote file support required for image handling.
-    $options = new Options();
-    $options->set('isRemoteEnabled', TRUE);
-
+    $options = self::getDompdfOptions();
     $dompdf = new DOMPDF($options);
     $dompdf->set_paper($paper_size, $orientation);
     $dompdf->load_html($html);
@@ -205,11 +202,11 @@ class CRM_Utils_PDF_Utils {
   }
 
   /**
-   * @param $paper_size
-   * @param $orientation
-   * @param $margins
-   * @param $html
-   * @param $output
+   * @param float|int[] $paper_size
+   * @param string $orientation
+   * @param array $margins
+   * @param string $html
+   * @param bool $output
    * @param string $fileName
    */
   public static function _html2pdf_wkhtmltopdf($paper_size, $orientation, $margins, $html, $output, $fileName) {
@@ -237,10 +234,10 @@ class CRM_Utils_PDF_Utils {
   /**
    * convert value from one metric to another.
    *
-   * @param $value
-   * @param $from
-   * @param $to
-   * @param null $precision
+   * @param int $value
+   * @param string $from
+   * @param string $to
+   * @param int|null $precision
    *
    * @return float|int
    */
@@ -300,4 +297,28 @@ class CRM_Utils_PDF_Utils {
     return $value;
   }
 
+  /**
+   * Allow setting some dompdf options.
+   *
+   * We don't support all the available dompdf options.
+   *
+   * @return \Dompdf\Options
+   */
+  private static function getDompdfOptions(): Options {
+    $options = new Options();
+    $settings = [
+      // CRM-12165 - Remote file support required for image handling so default to TRUE
+      'enable_remote' => \Civi::settings()->get('dompdf_enable_remote') ?? TRUE,
+    ];
+    // only set these ones if a setting exists for them
+    foreach (['font_dir', 'chroot', 'log_output_file'] as $setting) {
+      $value = \Civi::settings()->get("dompdf_$setting");
+      if (isset($value)) {
+        $settings[$setting] = $value;
+      }
+    }
+    $options->set($settings);
+    return $options;
+  }
+
 }