diff --git a/composer.json b/composer.json index 2b00a1d..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.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..d2dddea 100644 --- a/src/Processor/Gotenberg.php +++ b/src/Processor/Gotenberg.php @@ -106,6 +106,18 @@ 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']) && method_exists($chromium, 'userAgent')) { + $chromium->userAgent($params['userAgent']); + } + if (isset($params['pdfFormat'])&& method_exists($chromium, 'pdfFormat')) { + $chromium->pdfFormat($params['pdfFormat']); + } + } $options = [ 'printBackground', 'landscape', 'preferCssPageSize', 'omitBackground', 'emulatePrintMediaType', @@ -143,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'])) { - $chromium->userAgent($params['userAgent']); - } if (isset($params['extraHttpHeaders'])) { $chromium->extraHttpHeaders($params['extraHttpHeaders']); } - if (isset($params['pdfFormat'])) { - $chromium->pdfFormat($params['pdfFormat']); - } - $request = $chromium->outputFilename($tempFileName)->html(Stream::string('processor.html', $html)); if ($returnFilePath) {