Skip to content

Commit

Permalink
feat(libreoffice): add new method exportFormFields
Browse files Browse the repository at this point in the history
  • Loading branch information
gulien committed Mar 23, 2024
1 parent 0e2d48d commit 0309bfb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,19 @@ $request = Gotenberg::libreOffice($apiUrl)

⚠️ The page ranges are applied to all files independently.

#### Export form fields

You may set whether to export the form fields or to use the inputted/selected content of the fields:

```php
use Gotenberg\Gotenberg;
use Gotenberg\Stream;

$request = Gotenberg::libreOffice($apiUrl)
->exportFormFields(false)
->convert(Stream::path('/path/to/my.docx'));
```

#### PDF/A & PDF/UA

See https://gotenberg.dev/docs/routes#pdfa-libreoffice.
Expand Down
11 changes: 11 additions & 0 deletions src/Modules/LibreOffice.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ public function nativePageRanges(string $ranges): self
return $this;
}

/**
* Set whether to export the form fields or to use the inputted/selected
* content of the fields.
*/
public function exportFormFields(bool $export = true): self
{
$this->formValue('exportFormFields', $export ?: '0');

return $this;
}

/**
* Sets the PDF/A format of the resulting PDF.
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Modules/LibreOfficeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function (
array $files,
bool $landscape = false,
string|null $nativePageRanges = null,
bool|null $exportFormFields = null,
string|null $pdfa = null,
bool $pdfua = false,
bool $merge = false,
Expand All @@ -27,6 +28,10 @@ function (
$libreOffice->nativePageRanges($nativePageRanges);
}

if ($exportFormFields !== null) {
$libreOffice->exportFormFields($exportFormFields);
}

if ($pdfa !== null) {
$libreOffice->pdfa($pdfa);
}
Expand All @@ -47,6 +52,8 @@ function (
expect($request->getUri()->getPath())->toBe('/forms/libreoffice/convert');
expect($body)->unless($landscape === false, fn ($body) => $body->toContainFormValue('landscape', '1'));
expect($body)->unless($nativePageRanges === null, fn ($body) => $body->toContainFormValue('nativePageRanges', $nativePageRanges));
expect($body)->unless($exportFormFields === null, fn ($body) => $body->toContainFormValue('exportFormFields', $exportFormFields === true ? '1' : '0'));

expect($body)->unless($merge === false, fn ($body) => $body->toContainFormValue('merge', '1'));

foreach ($files as $file) {
Expand All @@ -69,6 +76,7 @@ function (
],
true,
'1-2',
false,
'PDF/A-1a',
true,
true,
Expand Down

0 comments on commit 0309bfb

Please sign in to comment.