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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ Screenshot::view('invoices.preview', ['invoice' => $invoice])
->store(path: 'invoices/invoice.pdf', disk: 's3');
```

PDFs default to A4 portrait, 10 mm margins, and printed backgrounds. `paper()` accepts `PaperSize::A3`, `A4`, `A5`, `Letter`, or `Legal`. Use `paperSize(width: 100, height: 150)` for custom dimensions in millimeters, `margins(top: 5, right: 5, bottom: 5, left: 5)` to set margins, and `background(false)` to omit backgrounds. `preferCssPageSize()` gives CSS `@page` sizes precedence over the selected paper size.
PDFs default to A4 portrait, 10 mm margins, and printed backgrounds. `paper()` accepts `PaperSize::A0` through `A6`, `Letter`, `Legal`, `Tabloid`, or `Ledger`. The corresponding configuration values are `a0` through `a6`, `letter`, `legal`, `tabloid`, and `ledger`.

Tabloid is 279.4 × 431.8 mm (11 × 17 inches); Ledger is 431.8 × 279.4 mm (17 × 11 inches). Ledger already uses the wider layout without calling `landscape()`.

Use `paperSize(width: 100, height: 150)` for custom dimensions in millimeters, `margins(top: 5, right: 5, bottom: 5, left: 5)` to set margins, and `background(false)` to omit backgrounds. `preferCssPageSize()` gives CSS `@page` sizes precedence over the selected paper size.

PDFs use Chrome's print layout, including print styles and page breaks. Screenshot viewport settings do not set the paper size; image format, quality, full-page mode, and `maxSize()` do not apply to PDF output.

Expand Down
3 changes: 2 additions & 1 deletion config/screenshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
| PDF Defaults
|--------------------------------------------------------------------------
|
| Paper sizes are a3, a4, a5, letter, or legal. Margins are in millimeters.
| Paper sizes are a0 through a6, letter, legal, tabloid, or ledger.
| Margins are in millimeters.
| Selecting PDF output copies the source's current browser settings and
| these print defaults into an independent PDF builder.
|
Expand Down
12 changes: 12 additions & 0 deletions src/Enums/PaperSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

enum PaperSize: string
{
case A0 = 'a0';
case A1 = 'a1';
case A2 = 'a2';
case A3 = 'a3';
case A4 = 'a4';
case A5 = 'a5';
case A6 = 'a6';
case Letter = 'letter';
case Legal = 'legal';
case Tabloid = 'tabloid';
case Ledger = 'ledger';

/**
* Get the paper width and height in millimeters, before orientation.
Expand All @@ -18,11 +24,17 @@ enum PaperSize: string
public function dimensions(): array
{
return match ($this) {
self::A0 => [841.0, 1189.0],
self::A1 => [594.0, 841.0],
self::A2 => [420.0, 594.0],
self::A3 => [297.0, 420.0],
self::A4 => [210.0, 297.0],
self::A5 => [148.0, 210.0],
self::A6 => [105.0, 148.0],
self::Letter => [215.9, 279.4],
self::Legal => [215.9, 355.6],
self::Tabloid => [279.4, 431.8],
self::Ledger => [431.8, 279.4],
};
}
}
6 changes: 6 additions & 0 deletions tests/Unit/PaperSizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@
&& $options->output()->getPaperHeight() === $height,
);
})->with([
'A0' => [PaperSize::A0, 841.0, 1189.0],
'A1' => [PaperSize::A1, 594.0, 841.0],
'A2' => [PaperSize::A2, 420.0, 594.0],
'A3' => [PaperSize::A3, 297.0, 420.0],
'A4' => [PaperSize::A4, 210.0, 297.0],
'A5' => [PaperSize::A5, 148.0, 210.0],
'A6' => [PaperSize::A6, 105.0, 148.0],
'Letter' => [PaperSize::Letter, 215.9, 279.4],
'Legal' => [PaperSize::Legal, 215.9, 355.6],
'Tabloid' => [PaperSize::Tabloid, 279.4, 431.8],
'Ledger' => [PaperSize::Ledger, 431.8, 279.4],
]);

test('selecting a smaller paper cannot invalidate the printable area', function () {
Expand Down
Loading