SplitPdfBuilder
May 19, 2026 ยท View on GitHub
You may have the possibility to split several PDF pages.
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.
namespace App\Controller;
use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;
class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg->split()
->files(
'document_1.pdf',
'document_2.pdf',
)
->splitMode(SplitMode::Pages)
->splitSpan('1-2')
->splitUnify()
->generate()
->stream()
;
}
}
Customization
Available methods
- addMetadata
- downloadFrom
- embedFiles
- files
- flatten
- metadata
- pdfFormat
- pdfUniversalAccess
- splitMode
- splitSpan
- splitUnify
- stampExpression
- stampFile
- stampOptions
- stampPages
- stampSource
- watermarkExpression
- watermarkFile
- watermarkOptions
- watermarkPages
- watermarkSource
- addWebhookExtraHeaders
- webhook
- webhookConfiguration
- webhookErrorRoute
- webhookErrorUrl
- webhookEventsRoute
- webhookEventsUrl
- webhookExtraHeaders
- webhookRoute
- webhookUrl
- ownerPassword
- userPassword
addMetadata(string $key, string $value)
If you want to add metadata from the ones already loaded in the configuration.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->addMetadata('key', 'value')
->generate()
->stream()
;
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()
;
embedFiles(Stringable|Sensiolabs\GotenbergBundle\Builder\ValueObject\EmbeddedFile|string ...$paths)
Set files to embed.
As assets files, by default the files to embed are fetch in the assets folder
of your application. For more information about path resolution go to
assets documentation.
Tip
See: https://gotenberg.dev/docs/convert-with-chromium/convert-html-to-pdf#attachments-pdf-engines
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->embedFiles('document.xml','document_2.json')
->generate()
->stream()
;
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->embedFiles(new EmbeddedFile('factur-x.xml', 'Data'))
->generate()
->stream()
;
files(Stringable|string ...$paths)
Add PDF files to split.
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.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->files('document.pdf','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()
;
metadata(array $metadata)
Resets the metadata.
Tip
See: https://gotenberg.dev/docs/convert-with-chromium/convert-html-to-pdf#metadata-pdf-engines
See: [https://exiftool.org/TagNames/XMP.html#pdf Common PDF metadata keys: Author, Copyright, CreationDate, Creator, Keywords, Marked, ModDate, PDFVersion, Producer, Subject, Title, Trapped. Any ExifTool-compatible key is accepted, including custom XMP namespaces (e.g., 'XMP-fx:DocumentType' for Factur-X).](https://exiftool.org/TagNames/XMP.html#pdf Common PDF metadata keys: Author, Copyright, CreationDate, Creator, Keywords, Marked, ModDate, PDFVersion, Producer, Subject, Title, Trapped. Any ExifTool-compatible key is accepted, including custom XMP namespaces (e.g., 'XMP-fx:DocumentType' for Factur-X).)
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->metadata(['Author' => 'SensioLabs', 'Subject' => 'Gotenberg', 'XMP-fx:DocumentType' => 'INVOICE', 'XMP-fx:DocumentFileName' => 'factur-x.xml'])
->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()
;
splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode)
Either intervals or pages.
Tip
See: https://gotenberg.dev/docs/manipulate-pdfs/split-pdfs
See: https://gotenberg.dev/docs/convert-with-chromium/convert-html-to-pdf#split--page-ranges
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->splitMode(SplitMode::Intervals)
->generate()
->stream()
;
splitSpan(string $splitSpan)
Either the intervals or the page ranges to extract, depending on the selected mode.
Tip
See: https://gotenberg.dev/docs/manipulate-pdfs/split-pdfs
See: https://gotenberg.dev/docs/convert-with-chromium/convert-html-to-pdf#split--page-ranges
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->splitSpan('1')
->generate()
->stream()
;
splitUnify(bool $bool)
Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
Tip
See: https://gotenberg.dev/docs/manipulate-pdfs/split-pdfs
See: https://gotenberg.dev/docs/convert-with-chromium/convert-html-to-pdf#split--page-ranges
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->splitUnify() // is same as `->splitUnify(true)`
->generate()
->stream()
;
stampExpression(string $stampExpression)
The stamp content. For 'text', the string to render.
For 'image' or 'pdf', the filename of the uploaded stamp file.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->stampExpression('APPROVED')
->generate()
->stream()
;
stampFile(Stringable|string $path)
An image or PDF file used as stamp source (required when stampSource is 'image' or 'pdf').
As asset files, by default the file is fetched in the assets folder
of your application. For more information about path resolution go to
assets documentation.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->stampFile('stamp.pdf')
->generate()
->stream()
;
stampOptions(array $stampOptions)
Advanced options in JSON format. Valid keys depend on the configured PDF engine (default: pdfcpu).
For pdfcpu: font, points, color, rotation, opacity, scale, offset.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->stampOptions(['opacity' => 0.5])
->generate()
->stream()
;
stampPages(?string $stampPages)
Page ranges to stamp (e.g., '1-3', '5'). Empty string means all pages.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->stampPages('1-3')
->generate()
->stream()
;
stampSource(Sensiolabs\GotenbergBundle\Enumeration\StampSource $stampSource)
The stamp source type. Options: 'text', 'image', 'pdf'.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->stampSource(StampSource::Text)
->generate()
->stream()
;
watermarkExpression(string $watermarkExpression)
The watermark content. For 'text', the string to render. For 'image' or 'pdf', the filename of the uploaded watermark file.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->watermarkExpression('CONFIDENTIAL')
->generate()
->stream()
;
watermarkFile(Stringable|string $path)
An image or PDF file used as watermark source (required when watermarkSource is 'image' or 'pdf').
As asset files, by default the file is fetched in the assets folder
of your application. For more information about path resolution go to
assets documentation.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->watermarkFile('watermark.pdf')
->generate()
->stream()
;
watermarkOptions(array $watermarkOptions)
Advanced options in JSON format (e.g., font, color, rotation, opacity, scaling).
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->watermarkOptions(['opacity' => 0.5])
->generate()
->stream()
;
watermarkPages(?string $watermarkPages)
Page ranges to watermark (e.g., '1-3', '5'). Empty means all pages.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->watermarkPages('1-3')
->generate()
->stream()
;
watermarkSource(Sensiolabs\GotenbergBundle\Enumeration\WatermarkSource $watermarkSource)
The watermark source type.
return $gotenberg
// Your builder call as ->html() and the rest of your configuration code
->watermarkSource(WatermarkSource::Text)
->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()
;