Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ $filename = Gotenberg::save($request, '/path/to/saving/directory');
```

It returns the filename of the resulting file. By default, Gotenberg creates a *UUID* filename (i.e.,
`95cd9945-484f-4f89-8bdb-23dbdd0bdea9`) with either a `.zip` or a `.pdf` file extension.
`95cd9945-484f-4f89-8bdb-23dbdd0bdea9`) with either a `.zip` or a `.pdf` file extension (or image formats for screenshots).

You may also explicitly set the HTTP client:

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
"psr/http-message": "^1.0|^2.0"
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
"pestphp/pest": "^2.28",
"doctrine/coding-standard": "^14.0",
"pestphp/pest": "^2.36",
"phpstan/phpstan": "^1.12",
"squizlabs/php_codesniffer": "^3.10"
"squizlabs/php_codesniffer": "^4.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 3 additions & 1 deletion src/DownloadFrom.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ class DownloadFrom implements JsonSerializable
public function __construct(
public readonly string $url,
public readonly array|null $extraHttpHeaders = null,
public readonly bool $embedded = false,
) {
}

/** @return array<string,string|array<string,string>> */
/** @return array<string, array<string,string>|bool|string> */
public function jsonSerialize(): array
{
$serialized = [
'url' => $this->url,
'embedded' => $this->embedded,
];

if (! empty($this->extraHttpHeaders)) {
Expand Down
33 changes: 33 additions & 0 deletions src/Modules/ChromiumPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,39 @@ public function metadata(array $metadata): self
return $this;
}

/**
* Defines whether the resulting PDF should be flattened.
*/
public function flatten(): self
{
$this->formValue('flatten', true);

return $this;
}

/**
* Defines whether the resulting PDF should be encrypted.
*/
public function encrypt(string $userPassword, string $ownerPassword = ''): self
{
$this->formValue('userPassword', $userPassword);
$this->formValue('ownerPassword', $ownerPassword);

return $this;
}

/**
* Sets the file to embed in the resulting PDF.
*/
public function embeds(Stream ...$embeds): self
{
foreach ($embeds as $embed) {
$this->formFile($embed->getFilename(), $embed->getStream(), 'embeds');
}

return $this;
}

/**
* Converts a target URL to PDF.
*
Expand Down
23 changes: 23 additions & 0 deletions src/Modules/LibreOffice.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,29 @@ public function flatten(): self
return $this;
}

/**
* Defines whether the resulting PDF should be encrypted.
*/
public function encrypt(string $userPassword, string $ownerPassword = ''): self
{
$this->formValue('userPassword', $userPassword);
$this->formValue('ownerPassword', $ownerPassword);

return $this;
}

/**
* Sets the file to embed in the resulting PDF.
*/
public function embeds(Stream ...$embeds): self
{
foreach ($embeds as $embed) {
$this->formFile($embed->getFilename(), $embed->getStream(), 'embeds');
}

return $this;
}

/**
* Converts the given document(s) to PDF(s). Gotenberg will return either
* a unique PDF if you request a merge or a ZIP archive with the PDFs.
Expand Down
62 changes: 62 additions & 0 deletions src/Modules/PdfEngines.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ public function flattening(): self
return $this;
}

/**
* Defines whether the resulting PDF should be encrypted.
* Prefer the encrypt method if you only want to encrypt one or more PDFs.
*/
public function encrypting(string $userPassword, string $ownerPassword = ''): self
{
$this->formValue('userPassword', $userPassword);
$this->formValue('ownerPassword', $ownerPassword);

return $this;
}

/**
* Sets the file to embed in the resulting PDF.
*/
public function embeds(Stream ...$embeds): self
{
foreach ($embeds as $embed) {
$this->formFile($embed->getFilename(), $embed->getStream(), 'embeds');
}

return $this;
}

/**
* Merges PDFs into a unique PDF.
*
Expand Down Expand Up @@ -186,4 +210,42 @@ public function writeMetadata(array $metadata, Stream ...$pdfs): RequestInterfac

return $this->request();
}

/**
* Allows encrypting one or more PDF.
*
* @throws NativeFunctionErrored
*/
public function encrypt(string $userPassword, string $ownerPassword = '', Stream ...$pdfs): RequestInterface
{
$this->encrypting($userPassword, $ownerPassword);

foreach ($pdfs as $pdf) {
$this->formFile($pdf->getFilename(), $pdf->getStream());
}

$this->endpoint = '/forms/pdfengines/encrypt';

return $this->request();
}

/**
* Allows embedding one or more files to one or more PDF.
*
* @param Stream[] $embeds
*
* @throws NativeFunctionErrored
*/
public function embed(array $embeds, Stream ...$pdfs): RequestInterface
{
foreach ($pdfs as $pdf) {
$this->formFile($pdf->getFilename(), $pdf->getStream());
}

$this->embeds(...$embeds);

$this->endpoint = '/forms/pdfengines/embed';

return $this->request();
}
}
4 changes: 2 additions & 2 deletions src/MultipartFormDataModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ protected function formValue(string $name, mixed $value): self
return $this;
}

protected function formFile(string $filename, StreamInterface $stream): void
protected function formFile(string $filename, StreamInterface $stream, string $name = 'files'): void
{
$this->multipartFormData[] = [
'name' => 'files',
'name' => $name,
'filename' => $filename,
'contents' => $stream,
];
Expand Down
Loading