Skip to content

Commit

Permalink
Gotenberg V8 Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ITspirit committed Jan 17, 2024
1 parent 4bcef82 commit fc31622
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions src/Processor/Gotenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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']));
}
}
Expand All @@ -143,15 +146,15 @@ 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']);
}

if (isset($params['extraHttpHeaders'])) {
$chromium->extraHttpHeaders($params['extraHttpHeaders']);
}

if (isset($params['pdfFormat'])) {
if (isset($params['pdfFormat']) && method_exists($chromium, 'pdfFormat')) {
$chromium->pdfFormat($params['pdfFormat']);
}

Expand Down

0 comments on commit fc31622

Please sign in to comment.