Skip to content

Commit

Permalink
feat(chromium): add generateDocumentOutline form field
Browse files Browse the repository at this point in the history
  • Loading branch information
gulien committed Nov 18, 2024
1 parent d99f5b5 commit df6af76
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Modules/ChromiumPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public function preferCssPageSize(): self
return $this;
}

/**
* Embeds the document outline into the PDF.
*/
public function generateDocumentOutline(): self
{
$this->formValue('generateDocumentOutline', true);

return $this;
}

/**
* Prints the background graphics.
*/
Expand Down
19 changes: 19 additions & 0 deletions tests/Modules/ChromiumPdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function (
float|string $marginLeft = 0,
float|string $marginRight = 0,
bool $preferCssPageSize = false,
bool $generateDocumentOutline = false,
bool $printBackground = false,
bool $omitBackground = false,
bool $landscape = false,
Expand Down Expand Up @@ -62,6 +63,7 @@ function (
$marginLeft,
$marginRight,
$preferCssPageSize,
$generateDocumentOutline,
$printBackground,
$omitBackground,
$landscape,
Expand Down Expand Up @@ -102,6 +104,7 @@ function (
$marginLeft,
$marginRight,
$preferCssPageSize,
$generateDocumentOutline,
$printBackground,
$omitBackground,
$landscape,
Expand Down Expand Up @@ -142,6 +145,7 @@ function (
true,
true,
true,
true,
1.0,
'1-2',
Stream::string('my_header.html', 'Header content'),
Expand Down Expand Up @@ -192,6 +196,7 @@ function (
float|string $marginLeft = 0,
float|string $marginRight = 0,
bool $preferCssPageSize = false,
bool $generateDocumentOutline = false,
bool $printBackground = false,
bool $omitBackground = false,
bool $landscape = false,
Expand Down Expand Up @@ -226,6 +231,7 @@ function (
$marginLeft,
$marginRight,
$preferCssPageSize,
$generateDocumentOutline,
$printBackground,
$omitBackground,
$landscape,
Expand Down Expand Up @@ -268,6 +274,7 @@ function (
$marginLeft,
$marginRight,
$preferCssPageSize,
$generateDocumentOutline,
$printBackground,
$omitBackground,
$landscape,
Expand Down Expand Up @@ -307,6 +314,7 @@ function (
true,
true,
true,
true,
1.0,
'1-2',
Stream::string('my_header.html', 'Header content'),
Expand Down Expand Up @@ -359,6 +367,7 @@ function (
float|string $marginLeft = 0,
float|string $marginRight = 0,
bool $preferCssPageSize = false,
bool $generateDocumentOutline = false,
bool $printBackground = false,
bool $omitBackground = false,
bool $landscape = false,
Expand Down Expand Up @@ -393,6 +402,7 @@ function (
$marginLeft,
$marginRight,
$preferCssPageSize,
$generateDocumentOutline,
$printBackground,
$omitBackground,
$landscape,
Expand Down Expand Up @@ -440,6 +450,7 @@ function (
$marginLeft,
$marginRight,
$preferCssPageSize,
$generateDocumentOutline,
$printBackground,
$omitBackground,
$landscape,
Expand Down Expand Up @@ -488,6 +499,7 @@ function (
true,
true,
true,
true,
1.0,
'1-2',
Stream::string('my_header.html', 'Header content'),
Expand Down Expand Up @@ -536,6 +548,7 @@ function hydrateChromiumPdfFormData(
float|string $marginLeft = 0,
float|string $marginRight = 0,
bool $preferCssPageSize = false,
bool $generateDocumentOutline = false,
bool $printBackground = false,
bool $omitBackground = false,
bool $landscape = false,
Expand Down Expand Up @@ -575,6 +588,10 @@ function hydrateChromiumPdfFormData(
$chromium->preferCssPageSize();
}

if ($generateDocumentOutline) {
$chromium->generateDocumentOutline();
}

if ($printBackground) {
$chromium->printBackground();
}
Expand Down Expand Up @@ -688,6 +705,7 @@ function expectChromiumPdfOptions(
float|string $marginLeft,
float|string $marginRight,
bool $preferCssPageSize,
bool $generateDocumentOutline,
bool $printBackground,
bool $omitBackground,
bool $landscape,
Expand Down Expand Up @@ -728,6 +746,7 @@ function expectChromiumPdfOptions(
}

expect($body)->unless($preferCssPageSize === false, fn ($body) => $body->toContainFormValue('preferCssPageSize', '1'));
expect($body)->unless($generateDocumentOutline === false, fn ($body) => $body->toContainFormValue('generateDocumentOutline', '1'));
expect($body)->unless($printBackground === false, fn ($body) => $body->toContainFormValue('printBackground', '1'));
expect($body)->unless($omitBackground === false, fn ($body) => $body->toContainFormValue('omitBackground', '1'));
expect($body)->unless($landscape === false, fn ($body) => $body->toContainFormValue('landscape', '1'));
Expand Down

0 comments on commit df6af76

Please sign in to comment.