EncryptPdfBuilder.md

May 19, 2026 ยท View on GitHub

EncryptPdfBuilder

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] You must provide at least the User Password

namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
    public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
    {
        return $gotenberg->encrypt()
            ->files('document_1.pdf')
            ->userPassword('MyUserPassword')
            ->ownerPassword('MyOwnerPassword')
            ->generate()
         ;
    }
}

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)

Adds files (overrides any previous files).

return $gotenberg
    // Your builder call as ->html() and the rest of your configuration code
    ->files('document.pdf', '/absolute/path/document_2.pdf')
    ->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()
;

ownerPassword(?string $ownerPassword)

Set PDF owner password.

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

userPassword(?string $userPassword)

Set PDF user password.

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