Skip to content

Commit af480fc

Browse files
committed
feat: comply with Gotenberg 8.29.0
1 parent d2e4ada commit af480fc

9 files changed

Lines changed: 391 additions & 19 deletions

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,17 @@ $request = Gotenberg::chromium($apiUrl)
229229

230230
Gotenberg will automatically add the correct file extension.
231231

232-
### Trace or request ID
232+
### Correlation ID
233233

234-
By default, Gotenberg creates a *UUID* trace that identifies a request in its logs. You may override its value thanks to:
234+
By default, Gotenberg creates a *UUID* correlation ID that identifies a request in its logs. You may override its value
235+
thanks to:
235236

236237
```php
237238
use Gotenberg\Gotenberg;
238239

239-
$request = Gotenberg::chromium('$apiUrl')
240+
$request = Gotenberg::chromium($apiUrl)
240241
->pdf()
241-
->trace('debug')
242+
->correlationId('debug')
242243
->url('https://my.url');
243244
```
244245

@@ -249,15 +250,15 @@ use Gotenberg\Gotenberg;
249250

250251
$request = Gotenberg::chromium($apiUrl)
251252
->pdf()
252-
->trace('debug', 'Request-Id')
253+
->correlationId('debug', 'Request-Id')
253254
->url('https://my.url');
254255
```
255256

256-
Please note that it should be the same value as defined by the `--api-trace-header` Gotenberg's property.
257+
Please note that it should be the same value as defined by the `--api-correlation-id-header` Gotenberg's property.
257258

258-
The response from Gotenberg will also contain the trace header. In case of error, both the `Gotenberg::send` and
259-
`Gotenberg::save` methods throw a `GotenbergApiErrored` exception that provides the following method for retrieving the
260-
trace:
259+
The response from Gotenberg will also contain the correlation ID header. In case of error, both the `Gotenberg::send`
260+
and `Gotenberg::save` methods throw a `GotenbergApiErrored` exception that provides the following method for retrieving
261+
it:
261262

262263
```php
263264
use Gotenberg\Exceptions\GotenbergApiErrored;
@@ -270,8 +271,11 @@ try {
270271
->url('https://my.url')
271272
);
272273
} catch (GotenbergApiErrored $e) {
273-
$trace = $e->getGotenbergTrace();
274+
$correlationId = $e->getCorrelationId();
274275
// Or if you override the header name:
275-
$trace = $e->getGotenbergTrace('Request-Id');
276+
$correlationId = $e->getCorrelationId('Request-Id');
276277
}
277278
```
279+
280+
> [!NOTE]
281+
> The `trace()` and `getGotenbergTrace()` methods are deprecated but still available for backward compatibility.

src/ApiModule.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,26 @@ public function __construct(string $baseUrl)
2929
$this->url = $baseUrl;
3030
}
3131

32+
/**
33+
* Overrides the default UUID correlation ID that identifies a request in
34+
* Gotenberg's logs.
35+
*/
36+
public function correlationId(string $correlationId, string $header = 'Gotenberg-Trace'): self
37+
{
38+
$this->headers[$header] = $correlationId;
39+
40+
return $this;
41+
}
42+
3243
/**
3344
* Overrides the default UUID trace, or request ID, that identifies a
3445
* request in Gotenberg's logs.
46+
*
47+
* @deprecated Use correlationId() instead.
3548
*/
3649
public function trace(string $trace, string $header = 'Gotenberg-Trace'): self
3750
{
38-
$this->headers[$header] = $trace;
39-
40-
return $this;
51+
return $this->correlationId($trace, $header);
4152
}
4253

4354
protected function request(string $method, StreamInterface|null $body = null): RequestInterface

src/Exceptions/GotenbergApiErrored.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ public static function createFromResponse(ResponseInterface $response): self
2020
return $exception;
2121
}
2222

23-
public function getGotenbergTrace(string $header = 'Gotenberg-Trace'): string
23+
public function getCorrelationId(string $header = 'Gotenberg-Trace'): string
2424
{
2525
return $this->response->getHeaderLine($header);
2626
}
2727

28+
/** @deprecated Use getCorrelationId() instead. */
29+
public function getGotenbergTrace(string $header = 'Gotenberg-Trace'): string
30+
{
31+
return $this->getCorrelationId($header);
32+
}
33+
2834
public function getResponse(): ResponseInterface
2935
{
3036
return $this->response;

src/Modules/LibreOffice.php

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,167 @@ public function addOriginalDocumentAsStream(): self
230230
}
231231

232232
/**
233-
* Ignores each sheet’s paper size, print ranges and shown/hidden status
233+
* Specifies how the document shall be displayed when opened. Possible
234+
* values are: "document", "outline", "thumbnails".
235+
*/
236+
public function initialView(string $view): self
237+
{
238+
$this->formValue('initialView', $view);
239+
240+
return $this;
241+
}
242+
243+
/**
244+
* Specifies the page on which a PDF document should be opened in the
245+
* viewer.
246+
*/
247+
public function initialPage(int $page): self
248+
{
249+
$this->formValue('initialPage', $page);
250+
251+
return $this;
252+
}
253+
254+
/**
255+
* Specifies the magnification to use when the document is opened.
256+
* Possible values are: "default", "fitVisible", "fitWidth", "fitPage",
257+
* "fitActualSize".
258+
*/
259+
public function magnification(string $magnification): self
260+
{
261+
$this->formValue('magnification', $magnification);
262+
263+
return $this;
264+
}
265+
266+
/**
267+
* Specifies the zoom value to use when the document is opened.
268+
*/
269+
public function zoom(int $zoom): self
270+
{
271+
$this->formValue('zoom', $zoom);
272+
273+
return $this;
274+
}
275+
276+
/**
277+
* Specifies the page layout to use when the document is opened. Possible
278+
* values are: "default", "singlePage", "continuous", "continuousFacing".
279+
*/
280+
public function pageLayout(string $layout): self
281+
{
282+
$this->formValue('pageLayout', $layout);
283+
284+
return $this;
285+
}
286+
287+
/**
288+
* Specifies that the first page on the left side of the viewer should be
289+
* displayed in a two-column layout.
290+
*/
291+
public function firstPageOnLeft(): self
292+
{
293+
$this->formValue('firstPageOnLeft', true);
294+
295+
return $this;
296+
}
297+
298+
/**
299+
* Specifies that the PDF viewer window should be resized to fit the size
300+
* of the first page of the document.
301+
*/
302+
public function resizeWindowToInitialPage(): self
303+
{
304+
$this->formValue('resizeWindowToInitialPage', true);
305+
306+
return $this;
307+
}
308+
309+
/**
310+
* Specifies that the PDF viewer window should be centered on the screen.
311+
*/
312+
public function centerWindow(): self
313+
{
314+
$this->formValue('centerWindow', true);
315+
316+
return $this;
317+
}
318+
319+
/**
320+
* Specifies that the PDF document should be displayed in full-screen mode.
321+
*/
322+
public function openInFullScreenMode(): self
323+
{
324+
$this->formValue('openInFullScreenMode', true);
325+
326+
return $this;
327+
}
328+
329+
/**
330+
* Specifies that the title of the document should be displayed in the
331+
* title bar of the viewer.
332+
*/
333+
public function displayPDFDocumentTitle(): self
334+
{
335+
$this->formValue('displayPDFDocumentTitle', true);
336+
337+
return $this;
338+
}
339+
340+
/**
341+
* Specifies that the viewer's menu bar should be hidden.
342+
*/
343+
public function hideViewerMenubar(): self
344+
{
345+
$this->formValue('hideViewerMenubar', true);
346+
347+
return $this;
348+
}
349+
350+
/**
351+
* Specifies that the viewer's toolbar should be hidden.
352+
*/
353+
public function hideViewerToolbar(): self
354+
{
355+
$this->formValue('hideViewerToolbar', true);
356+
357+
return $this;
358+
}
359+
360+
/**
361+
* Specifies that the viewer's window controls should be hidden.
362+
*/
363+
public function hideViewerWindowControls(): self
364+
{
365+
$this->formValue('hideViewerWindowControls', true);
366+
367+
return $this;
368+
}
369+
370+
/**
371+
* Specifies whether to use transition effects when displaying the
372+
* document.
373+
*/
374+
public function useTransitionEffects(): self
375+
{
376+
$this->formValue('useTransitionEffects', true);
377+
378+
return $this;
379+
}
380+
381+
/**
382+
* Specifies the number of bookmark levels to display in the viewer when
383+
* the document is opened.
384+
*/
385+
public function openBookmarkLevels(int $levels): self
386+
{
387+
$this->formValue('openBookmarkLevels', $levels);
388+
389+
return $this;
390+
}
391+
392+
/**
393+
* Ignores each sheet's paper size, print ranges and shown/hidden status
234394
* and puts every sheet (even hidden sheets) on exactly one page.
235395
*/
236396
public function singlePageSheets(): self

src/MultipartFormDataModule.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ public function webhookExtraHttpHeaders(array $headers): self
109109
return $this;
110110
}
111111

112+
/**
113+
* Sets the URL that Gotenberg will use to send webhook event
114+
* notifications (e.g., success/error events after webhook delivery).
115+
*/
116+
public function webhookEventsUrl(string $url): self
117+
{
118+
$this->headers['Gotenberg-Webhook-Events-Url'] = $url;
119+
120+
return $this;
121+
}
122+
112123
/**
113124
* Configures watermarking on the resulting PDF(s).
114125
* Only non-empty values are set.

tests/ApiModuleTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,25 @@
1010
final class ApiModuleTest extends TestCase
1111
{
1212
#[Test]
13-
public function it_creates_a_valid_request_with_a_trace_header(): void
13+
public function it_creates_a_valid_request_with_a_correlation_id_header(): void
1414
{
1515
$dummy = new DummyApiModule('https://my.url/');
1616
$request = $dummy
17-
->trace('debug')
17+
->correlationId('debug')
1818
->build();
1919

2020
$this->assertSame('https://my.url', $dummy->getUrl());
2121
$this->assertSame(['debug'], $request->getHeader('Gotenberg-Trace'));
2222
}
23+
24+
#[Test]
25+
public function it_creates_a_valid_request_with_a_deprecated_trace_header(): void
26+
{
27+
$dummy = new DummyApiModule('https://my.url/');
28+
$request = $dummy
29+
->trace('debug')
30+
->build();
31+
32+
$this->assertSame(['debug'], $request->getHeader('Gotenberg-Trace'));
33+
}
2334
}

tests/GotenbergTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function it_sends_a_request_and_throws_an_exception_if_response_is_not_2x
4444
} catch (GotenbergApiErrored $e) {
4545
$this->assertSame(400, $e->getCode());
4646
$this->assertSame('Bad Request', $e->getMessage());
47-
$this->assertSame($withTrace ? 'debug' : '', $e->getGotenbergTrace());
47+
$this->assertSame($withTrace ? 'debug' : '', $e->getCorrelationId());
4848
$this->assertSame($response, $e->getResponse());
4949
}
5050
}

0 commit comments

Comments
 (0)