diff --git a/README.md b/README.md index 9138633f..33d7aa95 100644 --- a/README.md +++ b/README.md @@ -243,9 +243,45 @@ Comes with a built-in profiler panel to help you during your development. This bundle was inspired by [Gotenberg PHP](https://github.com/gotenberg/gotenberg-php). - [Steven RENAUX](https://github.com/StevenRenaux) - [Adrien ROCHES](https://github.com/Neirda24) +- [Hubert LENOIR](https://github.com/Jean-Beru) - [All Contributors](../../contributors) ## Licence MIT License (MIT): see the [License File](LICENSE) for more details. +## FAQ + +
+ My PDF / Screenshot is blank but I have no errors ! + It may be because Gotenberg is trying to access an invalid URL (when using the `->url()` or `->route()` modes). + For example if Gotenberg tries to access a page on `https://localhost:8001` but the SSL is a local provided one. Then Chromium won't be able to authorize access to the website. + To fix this you can update your Gotenberg docker service as followed : + + ```diff + --- a/compose.yaml + +++ b/compose.yaml + @@ -1,6 +1,9 @@ + services: + gotenberg: + image: 'gotenberg/gotenberg:8' + + command: + + - 'gotenberg' + + - '--chromium-ignore-certificate-errors' + ``` + + It can also be because from Gotenberg PoV the URL of your Symfony app is not reachable. + Let's say you are using [symfony CLI](https://symfony.com/download) to run your project locally with Gotenberg running in Docker. + You need to configure the request_context like so : + + ```diff + --- a/config/packages/gotenberg.yaml + +++ b/config/packages/gotenberg.yaml + @@ -6,5 +6,5 @@ framework: + + sensiolabs_gotenberg: + http_client: 'gotenberg.client' + + request_context: + + base_uri: 'http://host.docker.internal:8000' # 8000 is the port Symfony CLI is running my app on. + ``` +
diff --git a/docs/configuration.md b/docs/configuration.md index b1105ed5..98a2fd5f 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -225,6 +225,10 @@ sensiolabs_gotenberg: html: fail_on_http_status_codes: [401, 403] ``` +> [!TIP] +> A X99 entry means every HTTP status codes between X00 and X99 (e.g., 499 means every HTTP status codes between 400 and 499). +> `fail_on_http_status_codes: [499, 599]` would fail on any 4XX or 5XX code. + > [!TIP] > For more information about [Invalid HTTP Status Codes](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium). diff --git a/src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php b/src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php index bbe52a0d..ef464bc6 100644 --- a/src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php +++ b/src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php @@ -3,6 +3,7 @@ namespace Sensiolabs\GotenbergBundle\Builder\Screenshot; use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; +use Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType; use Sensiolabs\GotenbergBundle\Enumeration\Part; use Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; @@ -156,7 +157,7 @@ public function waitForExpression(string $expression): static * * @see https://gotenberg.dev/docs/routes#console-exceptions */ - public function emulatedMediaType(string $mediaType): static + public function emulatedMediaType(EmulatedMediaType $mediaType): static { $this->formFields['emulatedMediaType'] = $mediaType; diff --git a/src/Client/GotenbergClient.php b/src/Client/GotenbergClient.php index d9d6896c..6b36e845 100644 --- a/src/Client/GotenbergClient.php +++ b/src/Client/GotenbergClient.php @@ -28,7 +28,7 @@ public function call(string $endpoint, array $multipartFormData, array $headers ); if (200 !== $response->getStatusCode()) { - throw new HttpException($response->getStatusCode(), $response->getContent()); + throw new HttpException($response->getStatusCode(), $response->getContent(false)); } return new GotenbergResponse($response); diff --git a/tests/Builder/Screenshot/AbstractChromiumScreenshotBuilderTest.php b/tests/Builder/Screenshot/AbstractChromiumScreenshotBuilderTest.php index 126d8b0c..4469c8a6 100644 --- a/tests/Builder/Screenshot/AbstractChromiumScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/AbstractChromiumScreenshotBuilderTest.php @@ -10,6 +10,7 @@ use PHPUnit\Framework\Attributes\UsesClass; use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractChromiumScreenshotBuilder; use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType; use Sensiolabs\GotenbergBundle\Tests\Builder\AbstractBuilderTestCase; #[CoversClass(AbstractChromiumScreenshotBuilder::class)] @@ -45,7 +46,7 @@ public static function configurationIsCorrectlySetProvider(): \Generator yield 'wait_for_expression' => ['wait_for_expression', "window.status === 'ready'", [ 'waitForExpression' => "window.status === 'ready'", ]]; - yield 'emulated_media_type' => ['emulated_media_type', 'screen', [ + yield 'emulated_media_type' => ['emulated_media_type', EmulatedMediaType::Screen, [ 'emulatedMediaType' => 'screen', ]]; yield 'cookies' => ['cookies', [['name' => 'MyCookie', 'value' => 'raspberry']], [