From 801d4d27f63b30ca1ae2c4d64b41f82eab1f95c6 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 11 Feb 2025 18:49:57 +0100 Subject: [PATCH 1/2] feat: add possibility to add additional files like images, fonts, stylesheets, etc. --- src/Processor/Gotenberg.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Processor/Gotenberg.php b/src/Processor/Gotenberg.php index 70ccad5..ec80a8d 100644 --- a/src/Processor/Gotenberg.php +++ b/src/Processor/Gotenberg.php @@ -1,4 +1,5 @@ $html, 'params' => $params] = $event->getArguments(); - $tempFileName = uniqid('web2print_'); + $tempFileName = uniqid('web2print_', false); $chromium = GotenbergAPI::chromium(\Pimcore\Config::getSystemConfiguration('gotenberg')['base_url']); // To support gotenberg-php v2 and so on @@ -138,8 +143,11 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF } // generateDocumentOutline is only available for gotenberg >= 8.14.0 and gotenberg-php >= v2.10.0 - if (isset($params['generateDocumentOutline']) && $params['generateDocumentOutline'] - && method_exists($chromium, 'generateDocumentOutline')) { + if ( + isset($params['generateDocumentOutline']) && + $params['generateDocumentOutline'] + && method_exists($chromium, 'generateDocumentOutline') + ) { $chromium->generateDocumentOutline(); } @@ -177,6 +185,12 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF $chromium->metadata($params['metadata']); } + if (isset($params['assets'])) { + foreach ($params['assets'] as $asset) { + $chromium->assets($asset); + } + } + $request = $chromium->outputFilename($tempFileName)->html(Stream::string('processor.html', $html)); if ($returnFilePath) { @@ -184,6 +198,7 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF return PIMCORE_SYSTEM_TEMP_DIRECTORY . DIRECTORY_SEPARATOR . $filename; } + $response = GotenbergAPI::send($request); return $response->getBody()->getContents(); From f59293d6c82dc39d62036eb48aa1362748368fdf Mon Sep 17 00:00:00 2001 From: aarongerig <17384333+aarongerig@users.noreply.github.com> Date: Tue, 11 Feb 2025 17:56:19 +0000 Subject: [PATCH 2/2] Apply php-cs-fixer changes --- src/Processor/Gotenberg.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Processor/Gotenberg.php b/src/Processor/Gotenberg.php index ec80a8d..9251f8d 100644 --- a/src/Processor/Gotenberg.php +++ b/src/Processor/Gotenberg.php @@ -17,12 +17,12 @@ namespace Pimcore\Bundle\WebToPrintBundle\Processor; +use function array_key_exists; use function array_merge; use function file_exists; use Gotenberg\Gotenberg as GotenbergAPI; use Gotenberg\Stream; use function json_decode; -use function array_key_exists; use Pimcore\Bundle\WebToPrintBundle\Config; use Pimcore\Bundle\WebToPrintBundle\Event\DocumentEvents; use Pimcore\Bundle\WebToPrintBundle\Event\Model\PrintConfigEvent; @@ -198,7 +198,7 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF return PIMCORE_SYSTEM_TEMP_DIRECTORY . DIRECTORY_SEPARATOR . $filename; } - + $response = GotenbergAPI::send($request); return $response->getBody()->getContents();