From e64900cd265b3d1f04455c69c32a00c36ba6460e Mon Sep 17 00:00:00 2001 From: Adrian Wong Date: Wed, 8 Feb 2023 16:22:30 +1100 Subject: [PATCH] Add support for fail-safe options --- src/Prince.php | 152 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 1 deletion(-) diff --git a/src/Prince.php b/src/Prince.php index 9d4bab0..da6d807 100644 --- a/src/Prince.php +++ b/src/Prince.php @@ -136,6 +136,15 @@ class Prince private $licenseFile; private $licenseKey; + // Advanced options. + private $failDroppedContent; + private $failMissingResources; + private $failStrippedTransparency; + private $failMissingGlyphs; + private $failPdfProfileError; + private $failPdfTagError; + private $failInvalidLicense; + // Additional options. private $options; @@ -260,6 +269,15 @@ public function __construct($exePath) $this->licenseFile = ''; $this->licenseKey = ''; + // Advanced options. + $this->failDroppedContent = false; + $this->failMissingResources = false; + $this->failStrippedTransparency = false; + $this->failMissingGlyphs = false; + $this->failPdfProfileError = false; + $this->failPdfTagError = false; + $this->failInvalidLicense = false; + // Additional options. $this->options = ''; } @@ -1798,6 +1816,116 @@ public function setLicenseKey($key) $this->licenseKey = $key; } + /* ADVANCED OPTIONS *******************************************************/ + + /** + * Fail-safe option that aborts the creation of a PDF if any content is + * dropped. + * + * @param bool $failDroppedContent `true` to enable fail-safe option. + * Default value is `false. + * @return void + */ + public function setFailDroppedContent($failDroppedContent) + { + $this->failDroppedContent = $failDroppedContent; + } + + /** + * Fail-safe option that aborts the creation of a PDF if any resources + * cannot be loaded. + * + * @param bool $failMissingResources `true` to enable fail-safe option. + * Default value is `false. + * @return void + */ + public function setFailMissingResources($failMissingResources) + { + $this->failMissingResources = $failMissingResources; + } + + /** + * Fail-safe option that aborts the creation of a PDF if transparent + * images are used with a PDF profile that does not support opacity. + * + * @param bool $failStrippedTransparency `true` to enable fail-safe option. + * Default value is `false. + * @return void + */ + public function setFailStrippedTransparency($failStrippedTransparency) + { + $this->failStrippedTransparency = $failStrippedTransparency; + } + + /** + * Fail-safe option that aborts the creation of a PDF if glyphs cannot + * be found for any characters. + * + * @param bool $failMissingGlyphs `true` to enable fail-safe option. + * Default value is `false. + * @return void + */ + public function setFailMissingGlyphs($failMissingGlyphs) + { + $this->failMissingGlyphs = $failMissingGlyphs; + } + + /** + * Fail-safe option that aborts the creation of a PDF if there are + * problems complying with the specified PDF profile. + * + * @param bool $failPdfProfileError `true` to enable fail-safe option. + * Default value is `false. + * @return void + */ + public function setFailPdfProfileError($failPdfProfileError) + { + $this->failPdfProfileError = $failPdfProfileError; + } + + /** + * Fail-safe option that aborts the creation of a PDF if there are + * problems tagging the PDF for accessibility. + * + * @param bool $failPdfTagError `true` to enable fail-safe option. + * Default value is `false. + * @return void + */ + public function setFailPdfTagError($failPdfTagError) + { + $this->failPdfTagError = $failPdfTagError; + } + + /** + * Fail-safe option that aborts the creation of a PDF if the Prince + * license is invalid or not readable. + * + * @param bool $failInvalidLicense `true` to enable fail-safe option. + * Default value is `false. + * @return void + */ + public function setFailInvalidLicense($failInvalidLicense) + { + $this->failInvalidLicense = $failInvalidLicense; + } + + /** + * Enables/disables all fail-safe options. + * + * @param bool $failSafe `true` to enable all fail-safe options. + * @return void + */ + public function setFailSafe($failSafe) + { + $this->failDroppedContent = $failSafe; + $this->failMissingResources = $failSafe; + $this->failStrippedTransparency = $failSafe; + $this->failMissingGlyphs = $failSafe; + $this->failPdfProfileError = $failSafe; + $this->failPdfTagError = $failSafe; + $this->failInvalidLicense = $failSafe; + } + /* ADDITIONAL OPTIONS *****************************************************/ /** @@ -2064,11 +2192,33 @@ private function getCommandLine($logType = 'normal') if ($this->licenseFile != '') { $cmdline .= self::cmdArg('--license-file', $this->licenseFile); } - if ($this->licenseKey != '') { $cmdline .= self::cmdArg('--license-key', $this->licenseKey); } + // Advanced options. + if ($this->failDroppedContent) { + $cmdline .= self::cmdArg('--fail-dropped-content'); + } + if ($this->failMissingResources) { + $cmdline .= self::cmdArg('--fail-missing-resources'); + } + if ($this->failStrippedTransparency) { + $cmdline .= self::cmdArg('--fail-stripped-transparency'); + } + if ($this->failMissingGlyphs) { + $cmdline .= self::cmdArg('--fail-missing-glyphs'); + } + if ($this->failPdfProfileError) { + $cmdline .= self::cmdArg('--fail-pdf-profile-error'); + } + if ($this->failPdfTagError) { + $cmdline .= self::cmdArg('--fail-pdf-tag-error'); + } + if ($this->failInvalidLicense) { + $cmdline .= self::cmdArg('--fail-invalid-license'); + } + // Additional options. if ($this->options != '') { $cmdline .= self::cmdArg($this->options);