Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RELEASE_8.15.0] Add split feature #132

Merged
merged 7 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ class YourController
`xltx`, `xlw`, `xml`, `xpm`, `zabw`
6. [Merge Builder](./docs/pdf/merge-builder.md)
7. [Convert Builder](./docs/pdf/convert-builder.md)
8. [PDF customization](./docs/pdf/customization.md) (available for every builder except LibreOffice and Merge)
8. [Split Builder](./docs/pdf/split-builder.md)
9. [PDF customization](./docs/pdf/customization.md) (available for every builder except LibreOffice, Merge and Split)

#### Screenshot

Expand Down
12 changes: 12 additions & 0 deletions config/builder_pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\SplitPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
Expand Down Expand Up @@ -89,4 +90,15 @@
->call('setLogger', [service('logger')->nullOnInvalid()])
->tag('sensiolabs_gotenberg.pdf_builder')
;

$services->set('.sensiolabs_gotenberg.pdf_builder.split', SplitPdfBuilder::class)
->share(false)
->args([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
service('.sensiolabs_gotenberg.webhook_configuration_registry'),
])
->call('setLogger', [service('logger')->nullOnInvalid()])
->tag('sensiolabs_gotenberg.pdf_builder')
;
};
1 change: 1 addition & 0 deletions docs/builders_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [LibreOfficePdfBuilder](./pdf/builders_api/LibreOfficePdfBuilder.md)
* [MergePdfBuilder](./pdf/builders_api/MergePdfBuilder.md)
* [ConvertPdfBuilder](./pdf/builders_api/ConvertPdfBuilder.md)
* [SplitPdfBuilder](./pdf/builders_api/SplitPdfBuilder.md)

## Screenshot

Expand Down
45 changes: 45 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ sensiolabs_gotenberg:
# Enable PDF for Universal Access for optimal accessibility - default false.
pdf_universal_access: null

# Either intervals or pages. - default None. https://gotenberg.dev/docs/routes#split-chromium
split_mode: null
StevenRenaux marked this conversation as resolved.
Show resolved Hide resolved

# Either the intervals or the page ranges to extract, depending on the selected mode. - default None. https://gotenberg.dev/docs/routes#split-chromium
split_span: null

# 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. https://gotenberg.dev/docs/routes#split-chromium
split_unify: null

# Webhook configuration name or definition.
webhook:

Expand Down Expand Up @@ -419,6 +428,15 @@ sensiolabs_gotenberg:
# Enable PDF for Universal Access for optimal accessibility - default false.
pdf_universal_access: null

# Either intervals or pages. - default None. https://gotenberg.dev/docs/routes#split-chromium
split_mode: null

# Either the intervals or the page ranges to extract, depending on the selected mode. - default None. https://gotenberg.dev/docs/routes#split-chromium
split_span: null

# 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. https://gotenberg.dev/docs/routes#split-chromium
split_unify: null

# Webhook configuration name or definition.
webhook:

Expand Down Expand Up @@ -607,6 +625,15 @@ sensiolabs_gotenberg:
# Enable PDF for Universal Access for optimal accessibility - default false.
pdf_universal_access: null

# Either intervals or pages. - default None. https://gotenberg.dev/docs/routes#split-chromium
split_mode: null

# Either the intervals or the page ranges to extract, depending on the selected mode. - default None. https://gotenberg.dev/docs/routes#split-chromium
split_span: null

# 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. https://gotenberg.dev/docs/routes#split-chromium
split_unify: null

# Webhook configuration name or definition.
webhook:

Expand Down Expand Up @@ -755,6 +782,15 @@ sensiolabs_gotenberg:

# Enable PDF for Universal Access for optimal accessibility - default false.
pdf_universal_access: null

# Either intervals or pages. - default None. https://gotenberg.dev/docs/routes#split-libreoffice
split_mode: null

# Either the intervals or the page ranges to extract, depending on the selected mode. - default None. https://gotenberg.dev/docs/routes#split-libreoffice
split_span: null

# 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. https://gotenberg.dev/docs/routes#split-libreoffice
split_unify: null
merge:

# Convert PDF into the given PDF/A format - default None.
Expand Down Expand Up @@ -810,6 +846,15 @@ sensiolabs_gotenberg:
name:
name: ~
value: ~
split:
# Either intervals or pages. - default None. https://gotenberg.dev/docs/routes#split-libreoffice
split_mode: null

# Either the intervals or the page ranges to extract, depending on the selected mode. - default None. https://gotenberg.dev/docs/routes#split-libreoffice
split_span: null

# 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. https://gotenberg.dev/docs/routes#split-libreoffice
split_unify: null
screenshot:
html:

Expand Down
2 changes: 2 additions & 0 deletions docs/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\SplitPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder;
use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder;
Expand All @@ -27,6 +28,7 @@
LibreOfficePdfBuilder::class,
MergePdfBuilder::class,
ConvertPdfBuilder::class,
SplitPdfBuilder::class,
],
'screenshot' => [
HtmlScreenshotBuilder::class,
Expand Down
9 changes: 9 additions & 0 deletions docs/pdf/builders_api/HtmlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ Resets the metadata.
* `addMetadata(string $key, string $value)`:
The metadata to write.

* `splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode)`:
Either intervals or pages. (default None).

* `splitSpan(string $splitSpan)`:
Either the intervals or the page ranges to extract, depending on the selected mode. (default None).

* `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).

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $name)`:
Expand Down
9 changes: 9 additions & 0 deletions docs/pdf/builders_api/LibreOfficePdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ Specify if the resolution of each image is reduced to the resolution specified b
* `maxImageResolution(Sensiolabs\GotenbergBundle\Enumeration\ImageResolutionDPI $resolution)`:
If the form field reduceImageResolution is set to true, tell if all images will be reduced to the given value in DPI. Possible values are: 75, 150, 300, 600 and 1200.

* `splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode)`:
Either intervals or pages. (default None).

* `splitSpan(string $splitSpan)`:
Either the intervals or the page ranges to extract, depending on the selected mode. (default None).

* `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).

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $name)`:
Expand Down
9 changes: 9 additions & 0 deletions docs/pdf/builders_api/MarkdownPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ Resets the metadata.
* `addMetadata(string $key, string $value)`:
The metadata to write.

* `splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode)`:
Either intervals or pages. (default None).

* `splitSpan(string $splitSpan)`:
Either the intervals or the page ranges to extract, depending on the selected mode. (default None).

* `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).

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $name)`:
Expand Down
31 changes: 31 additions & 0 deletions docs/pdf/builders_api/SplitPdfBuilder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SplitPdfBuilder

Split `n` pdf files.

* `splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode)`:
Either intervals or pages. (default None).

* `splitSpan(string $splitSpan)`:
Either the intervals or the page ranges to extract, depending on the selected mode. (default None).

* `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).

* `files(string $paths)`:

* `downloadFrom(array $downloadFrom)`:

* `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.

* `webhookUrl(string $url, ?string $method)`:
Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.

* `errorWebhookUrl(?string $url, ?string $method)`:
Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.

* `webhookExtraHeaders(array $extraHeaders)`:
Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

9 changes: 9 additions & 0 deletions docs/pdf/builders_api/UrlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ Resets the metadata.
* `addMetadata(string $key, string $value)`:
The metadata to write.

* `splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode)`:
Either intervals or pages. (default None).

* `splitSpan(string $splitSpan)`:
Either the intervals or the page ranges to extract, depending on the selected mode. (default None).

* `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).

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $name)`:
Expand Down
93 changes: 93 additions & 0 deletions docs/pdf/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
[landscape](#landscape)
[scale](#scale)
[nativePageRanges](#nativePageRanges)
[splitMode](#splitMode)
[splitSpan](#splitSpan)
[splitUnify](#splitUnify)

### Additional content
[header and footer](#header-and-footer)
Expand Down Expand Up @@ -424,6 +427,96 @@ class YourController
}
}
```

## splitMode

default: `None`

Either `intervals` or `pages`.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\Enum\SplitMode;
use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg->html()
->content('content.html.twig', [
'my_var' => 'value'
])
->splitMode(SplitMode::Intervals)
->splitSpan('1')
->generate()
->stream()
;
}
}
```

## splitSpan

default: `None`

Either the intervals or the page ranges to extract, depending on the selected `splitMode`.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\Enumeration\SplitMode;
use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg->html()
->content('content.html.twig', [
'my_var' => 'value'
]))
->splitMode(SplitMode::Intervals)
->splitSpan('1')
->generate()
->stream()
;
}
}
```

## splitUnify

Default: `false`

Specify whether to put extracted pages into a single file or as many files as
there are page ranges. Only works with `pages` mode.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\Enum\SplitMode;
use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg->html()
->content('content.html.twig', [
'my_var' => 'value'
])
->splitMode(SplitMode::Pages)
->splitSpan('1-2')
->splitUnify() // is same as ->splitUnify(true)
->generate()
->stream()
;
}
}
```

## Additional content

> [!WARNING]
Expand Down
Loading
Loading