From fc31622692a2c10bec6d3d3f5e24b87ed99c5b7e Mon Sep 17 00:00:00 2001 From: Michael Frank Date: Wed, 17 Jan 2024 16:40:53 +0100 Subject: [PATCH 1/7] Gotenberg V8 Compatibility --- composer.json | 2 +- src/Processor/Gotenberg.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 2b00a1d..2048411 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require-dev": { "phpstan/phpstan": "^1.10.5", "phpstan/phpstan-symfony": "^1.2.20", - "gotenberg/gotenberg-php": "^1.0.0", + "gotenberg/gotenberg-php": "^1.0|^2.0", "chrome-php/chrome": "^1.8", "codeception/codeception": "^5.0.3", "codeception/module-symfony": "^3.1.0", diff --git a/src/Processor/Gotenberg.php b/src/Processor/Gotenberg.php index e73caea..38aa264 100644 --- a/src/Processor/Gotenberg.php +++ b/src/Processor/Gotenberg.php @@ -106,6 +106,9 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF $tempFileName = uniqid('web2print_'); $chromium = GotenbergAPI::chromium(\Pimcore\Config::getSystemConfiguration('gotenberg')['base_url']); + if (method_exists($chromium, 'pdf')) { + $chromium = $chromium->pdf(); + } $options = [ 'printBackground', 'landscape', 'preferCssPageSize', 'omitBackground', 'emulatePrintMediaType', @@ -134,7 +137,7 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF } foreach (['header', 'footer'] as $item) { - if (isset($params[$item . 'Template'])) { + if (isset($params[$item . 'Template']) && method_exists($chromium, $item)) { $chromium->$item(Stream::path($params[$item . 'Template'])); } } @@ -143,7 +146,7 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF $chromium->paperSize($params['paperWidth'] ?? 8.5, $params['paperHeight'] ?? 11); } - if (isset($params['userAgent'])) { + if (isset($params['userAgent']) && method_exists($chromium, 'userAgent')) { $chromium->userAgent($params['userAgent']); } @@ -151,7 +154,7 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF $chromium->extraHttpHeaders($params['extraHttpHeaders']); } - if (isset($params['pdfFormat'])) { + if (isset($params['pdfFormat']) && method_exists($chromium, 'pdfFormat')) { $chromium->pdfFormat($params['pdfFormat']); } From 20cc44c6041e5a174b45b8b9ee52350f3ce9cac4 Mon Sep 17 00:00:00 2001 From: Michael Frank Date: Wed, 7 Feb 2024 15:00:48 +0100 Subject: [PATCH 2/7] change composer Version range to double-pipe --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2048411..4d5a909 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require-dev": { "phpstan/phpstan": "^1.10.5", "phpstan/phpstan-symfony": "^1.2.20", - "gotenberg/gotenberg-php": "^1.0|^2.0", + "gotenberg/gotenberg-php": "^1.0||^2.0", "chrome-php/chrome": "^1.8", "codeception/codeception": "^5.0.3", "codeception/module-symfony": "^3.1.0", From 9d7f0c3d4f982b5025448f03a24d37831b9177aa Mon Sep 17 00:00:00 2001 From: Michael Frank Date: Fri, 9 Feb 2024 11:33:10 +0100 Subject: [PATCH 3/7] Update src/Processor/Gotenberg.php Co-authored-by: JiaJia Ji --- src/Processor/Gotenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Processor/Gotenberg.php b/src/Processor/Gotenberg.php index 38aa264..de73239 100644 --- a/src/Processor/Gotenberg.php +++ b/src/Processor/Gotenberg.php @@ -137,7 +137,7 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF } foreach (['header', 'footer'] as $item) { - if (isset($params[$item . 'Template']) && method_exists($chromium, $item)) { + if (isset($params[$item . 'Template'])) { $chromium->$item(Stream::path($params[$item . 'Template'])); } } From 1e4354d9c79221f9d533f25afd19a8c11b2bff50 Mon Sep 17 00:00:00 2001 From: Michael Frank Date: Fri, 9 Feb 2024 11:33:17 +0100 Subject: [PATCH 4/7] Update composer.json Co-authored-by: JiaJia Ji --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4d5a909..50b7d39 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require-dev": { "phpstan/phpstan": "^1.10.5", "phpstan/phpstan-symfony": "^1.2.20", - "gotenberg/gotenberg-php": "^1.0||^2.0", + "gotenberg/gotenberg-php": "^1.0 || ^2.0", "chrome-php/chrome": "^1.8", "codeception/codeception": "^5.0.3", "codeception/module-symfony": "^3.1.0", From b3401bbe040c9ef95cf58f6e57857e4090a0f15f Mon Sep 17 00:00:00 2001 From: Michael Frank Date: Fri, 9 Feb 2024 11:33:27 +0100 Subject: [PATCH 5/7] Update src/Processor/Gotenberg.php Co-authored-by: JiaJia Ji --- src/Processor/Gotenberg.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Processor/Gotenberg.php b/src/Processor/Gotenberg.php index de73239..e5506c5 100644 --- a/src/Processor/Gotenberg.php +++ b/src/Processor/Gotenberg.php @@ -106,8 +106,17 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF $tempFileName = uniqid('web2print_'); $chromium = GotenbergAPI::chromium(\Pimcore\Config::getSystemConfiguration('gotenberg')['base_url']); + // To support gotenberg-php v2 and so on if (method_exists($chromium, 'pdf')) { $chromium = $chromium->pdf(); + } else { + // gotenberg-php v1 BC Layer for unsupported methods in v2 + if (isset($params['userAgent'])) { + $chromium->userAgent($params['userAgent']); + } + if (isset($params['pdfFormat'])) { + $chromium->pdfFormat($params['pdfFormat']); + } } $options = [ From 4a3d424c4269943bca541a33df5d95efcbab9151 Mon Sep 17 00:00:00 2001 From: Michael Frank Date: Fri, 9 Feb 2024 11:39:08 +0100 Subject: [PATCH 6/7] review change --- src/Processor/Gotenberg.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Processor/Gotenberg.php b/src/Processor/Gotenberg.php index e5506c5..d0ebf8c 100644 --- a/src/Processor/Gotenberg.php +++ b/src/Processor/Gotenberg.php @@ -155,18 +155,11 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF $chromium->paperSize($params['paperWidth'] ?? 8.5, $params['paperHeight'] ?? 11); } - if (isset($params['userAgent']) && method_exists($chromium, 'userAgent')) { - $chromium->userAgent($params['userAgent']); - } if (isset($params['extraHttpHeaders'])) { $chromium->extraHttpHeaders($params['extraHttpHeaders']); } - if (isset($params['pdfFormat']) && method_exists($chromium, 'pdfFormat')) { - $chromium->pdfFormat($params['pdfFormat']); - } - $request = $chromium->outputFilename($tempFileName)->html(Stream::string('processor.html', $html)); if ($returnFilePath) { From 8186965fff866be4ab4e28963cf272c2d4dde747 Mon Sep 17 00:00:00 2001 From: Michael Frank Date: Mon, 12 Feb 2024 15:17:34 +0100 Subject: [PATCH 7/7] review change - reimplement method_exists --- 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 d0ebf8c..d2dddea 100644 --- a/src/Processor/Gotenberg.php +++ b/src/Processor/Gotenberg.php @@ -111,10 +111,10 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF $chromium = $chromium->pdf(); } else { // gotenberg-php v1 BC Layer for unsupported methods in v2 - if (isset($params['userAgent'])) { + if (isset($params['userAgent']) && method_exists($chromium, 'userAgent')) { $chromium->userAgent($params['userAgent']); } - if (isset($params['pdfFormat'])) { + if (isset($params['pdfFormat'])&& method_exists($chromium, 'pdfFormat')) { $chromium->pdfFormat($params['pdfFormat']); } }