API
Render options · 9 min read
Options
Options control paper size, margins, background rendering, page ranges, media mode, waiting behavior, accessibility metadata, and lower-level PDF settings.
Fluent methods
| Method | Underlying option |
|---|---|
format('A4') | pdf_options.format |
paperSize(4, 6, 'in') | pdf_options.width, height |
margins(10, 10, 10, 10, 'mm') | pdf_options.margin |
landscape() / portrait() | pdf_options.landscape |
showBackground() / hideBackground() | pdf_options.printBackground |
transparentBackground() | pdf_options.omitBackground |
scale(0.9) | pdf_options.scale |
pages('1-3') / pageRanges('1-3') | pdf_options.pageRanges |
taggedPdf() | pdf_options.tagged |
preferCssPageSize() | pdf_options.preferCSSPageSize |
waitForFonts() | pdf_options.waitForFonts |
outline() | pdf_options.outline |
Example
Controller
php
1return BladePDF::fromView('pdf.report', $data)
2 ->format('A4')
3 ->landscape()
4 ->margins(12, 12, 16, 12, 'mm')
5 ->showBackground()
6 ->preferCssPageSize()
7 ->waitForFonts()
8 ->render()
9 ->response('report.pdf');
Raw options
Use withOptions() for fields that do not have a fluent helper or when building options dynamically.
Raw options
php
1BladePDF::fromHtml($html)
2 ->withOptions([
3 'format' => 'A4',
4 'printBackground' => true,
5 'margin' => [
6 'top' => '20mm',
7 'right' => '12mm',
8 'bottom' => '24mm',
9 'left' => '12mm',
10 ],
11 ])
12 ->render()
13 ->pdf();
Accepted PDF options
| Field | Type | Notes |
|---|---|---|
format | string | Letter, Legal, Tabloid, Ledger, A0-A6. |
width, height | string or number | Custom dimensions. |
margin.top/right/bottom/left | string or number | Use strings for explicit CSS units. |
landscape | boolean | Switch orientation. |
printBackground | boolean | Print CSS backgrounds. |
omitBackground | boolean | Use a transparent background. |
scale | number | The Laravel helper validates 0.1 through 2.0. |
pageRanges | string | For example 1-3, 8. |
preferCSSPageSize | boolean | Prefer CSS @page size. |
tagged, outline, waitForFonts | boolean | PDF accessibility/outline/font readiness options. |
Wait options
Use waitUntil() to control when the page is considered ready. Accepted values are:
loaddomcontentloadednetworkidle0networkidle2function
When using waitUntil('function'), provide a browser-side JavaScript expression with waitFunction().
Wait function
php
1BladePDF::fromView('pdf.chart', $data)
2 ->waitUntil('function')
3 ->waitFunction('window.__chartReady === true')
4 ->render()
5 ->pdf();
Media mode
Use emulateMedia('print') or emulateMedia('screen') to choose which CSS media rules apply.