From 3e82ecf0404343a08511d6c7494531dc31e6d182 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Thu, 15 Oct 2026 10:02:56 -0400 Subject: [PATCH] Add additional PDF paper sizes --- README.md | 6 +++++- config/screenshot.php | 3 ++- src/Enums/PaperSize.php | 12 ++++++++++++ tests/Unit/PaperSizeTest.php | 6 ++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 085a870..105a2a9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/config/screenshot.php b/config/screenshot.php index 9360982..442a4a8 100644 --- a/config/screenshot.php +++ b/config/screenshot.php @@ -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. | diff --git a/src/Enums/PaperSize.php b/src/Enums/PaperSize.php index feeb9a3..52490b2 100644 --- a/src/Enums/PaperSize.php +++ b/src/Enums/PaperSize.php @@ -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. @@ -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], }; } } diff --git a/tests/Unit/PaperSizeTest.php b/tests/Unit/PaperSizeTest.php index 0a8cabf..9b4f4e3 100644 --- a/tests/Unit/PaperSizeTest.php +++ b/tests/Unit/PaperSizeTest.php @@ -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 () {