ConvertPdfBuilder

May 19, 2026 ยท View on GitHub

You may have the possibility to convert several PDF document.

Basic usage

Warning

As assets files, by default the PDF files are fetch in the assets folder of your application. For more information about path resolution go to assets documentation.

Warning

If you provide multiple PDF files you will get ZIP folder containing all the converted PDF.

namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
    public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
    {
        return $gotenberg->convert()
            ->files(
                'document.pdf',
                'document_2.pdf',
            )
            ->generate()
            ->stream()
         ;
    }
}

Customization

Available methods

downloadFrom(array $downloadFrom)

Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->downloadFrom([['url' => 'http://example.com/url/to/file', 'extraHttpHeaders' => ['MyHeader' => 'MyValue']], ['url' => 'http://example.com/url/to/file', 'extraHttpHeaders' => ['MyHeaderOne' => 'MyValue', 'MyHeaderTwo' => 'MyValue']]])
    ->generate()
    ->stream()
;

files(Stringable|string ...$paths)

If you provide multiple PDF files you will get ZIP folder containing all the converted PDF.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->files('document.pdf', __DIR__'/../../public/document_2.pdf')
    ->generate()
    ->stream()
;

flatten(bool $bool)

Flattening a PDF combines all its contents into a single layer. (default false).

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->flatten() // is same as `->flatten(true)`
    ->generate()
    ->stream()
;

pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format)

Convert the resulting PDF into the given PDF/A format.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->pdfFormat(PdfFormat::Pdf1b)
    ->generate()
    ->stream()
;

pdfUniversalAccess(bool $bool)

Enable PDF for Universal Access for optimal accessibility.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->pdfUniversalAccess()  // is same as `->pdfUniversalAccess(true)`
    ->generate()
    ->stream()
;

addWebhookExtraHeaders(array $extraHttpHeaders)

Adds extra headers to the ones already provided to the webhook endpoint, preserving previously set values.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->addWebhookExtraHeaders(['X-Custom-Header' => 'CustomValue'])
    ->generate()
    ->stream()
;

webhook(array $webhook)

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->webhook(['config_name' => 'my_config', 'success' => ['url' => 'https://my.webhook.url/success', 'method' => 'POST'], 'error' => ['route' => 'my_route_error', 'method' => 'POST'], 'events' => ['url' => 'https://my.webhook.url/events']])
    ->generate()
    ->stream()
;

webhookConfiguration(string $name)

Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->webhookConfiguration('my_webhook_config')
    ->generate()
    ->stream()
;

webhookErrorRoute(string $route, array $parameters, ?string $method)

Sets the webhook route with params and method for cases of error.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->webhookErrorRoute('my_route_error', ['foo' => 'bar'], 'PUT')
    ->generate()
    ->stream()
;

webhookErrorUrl(string $url, ?string $method)

Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->webhookErrorUrl('https://my.webhook.url', 'PUT')
    ->generate()
    ->stream()
;

webhookEventsRoute(string $route, array $parameters)

Sets the webhook route with params for event callbacks.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->webhookEventsRoute('my_route_events', ['foo' => 'bar'])
    ->generate()
    ->stream()
;

webhookEventsUrl(string $url)

Sets the URL that will receive structured JSON event callbacks after each webhook operation.
When set, POST requests are sent with event type (webhook.success or webhook.error), correlationId, and timestamp.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->webhookEventsUrl('https://my.webhook.url/events')
    ->generate()
    ->stream()
;

webhookExtraHeaders(array $extraHttpHeaders)

Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->webhookExtraHeaders(['Authorization' => 'Bearer my-secret-token','X-Custom-Header' => 'CustomValue'])
    ->generate()
    ->stream()
;

webhookRoute(string $route, array $parameters, ?string $method)

Sets the webhook route with params and method for cases of success.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->webhookRoute('my_route_success', ['foo' => 'bar'], 'PUT')
    ->generate()
    ->stream()
;

webhookUrl(string $url, ?string $method)

Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->webhookUrl('https://my.webhook.url', 'PUT')
    ->generate()
    ->stream()
;