Paper size and layout · 7 min read

Page Formats

Choose a standard paper format, set custom dimensions, change orientation, control margins, and decide whether CSS @page size should win.

Standard formats

Use format() for common paper sizes.

A4 document
php
 1return BladePDF::fromView('pdf.invoice', $data)
 2    ->format('A4')
 3    ->render()
 4    ->download('invoice.pdf');
Supported values
Letter, Legal, Tabloid, Ledger
A0, A1, A2, A3, A4, A5, A6

Custom size

Use paperSize() when your document is not a standard page, such as labels or receipts.

Shipping label
php
 1BladePDF::fromView('pdf.label', $data)
 2    ->paperSize(4, 6, 'in')
 3    ->margins(0, 0, 0, 0, 'in')
 4    ->render()
 5    ->pdf();

Orientation

Use landscape() for wide reports and portrait() to explicitly switch back.

Landscape report
php
 1BladePDF::fromView('pdf.analytics', $data)
 2    ->format('A4')
 3    ->landscape()
 4    ->render()
 5    ->response('analytics.pdf');

Margins

Margins accept numbers plus a default unit, or strings with explicit CSS units. Numeric values default to pixels unless you pass a different unit.

Margins
php
 1BladePDF::fromView('pdf.invoice', $data)
 2    ->margins(20, 16, 24, 16, 'mm')
 3    ->render()
 4    ->pdf();
 5
 6BladePDF::fromView('pdf.invoice', $data)
 7    ->withOptions([
 8        'margin' => [
 9            'top' => '72px',
10            'right' => '24px',
11            'bottom' => '72px',
12            'left' => '24px',
13        ],
14    ])
15    ->render()
16    ->pdf();

Backgrounds

By default, print rendering may omit backgrounds depending on options. Use showBackground() when color blocks, borders, and background images are part of the document design.

Backgrounds
php
 1BladePDF::fromView('pdf.certificate', $data)
 2    ->showBackground()
 3    ->render()
 4    ->pdf();

CSS page size

Use preferCssPageSize() when your template declares size through CSS.

CSS @page
html
 1<style>
 2    @page {
 3        size: A4;
 4        margin: 18mm 14mm;
 5    }
 6</style>
Controller
php
 1BladePDF::fromView('pdf.invoice', $data)
 2    ->preferCssPageSize()
 3    ->render()
 4    ->pdf();

Scale

scale() accepts values from 0.1 to 2.0. Use it as a final adjustment, not as the main layout tool.

Was this page helpful?
Let us know if something's missing or unclear.