Screenshots, PDFs and Rendering

Screenshots, PDFs, rendered HTML, and the bx:playwrightRender component.

On this page

Screenshots, PDFs and Rendering

One-shot helpers

playwright().screenshot( "https://boxlang.io", "home.png", { fullPage : true } )
playwright().pdf( "https://boxlang.io", "home.pdf", { format : "A4" } )
html  = playwright().content( "https://boxlang.io" )            // HTML after JavaScript ran
bytes = playwright().render( "<h1>Hi</h1>", { type : "png" } )  // no path returns the bytes

From a page

page.screenshot( "page.png", { fullPage : true } )
page.locator( "@chart" ).screenshot( "chart.png" )
page.pdf( "page.pdf", { format : "Letter", landscape : true, margin : { top : "1cm" } } )

PDFs need Chromium (the print profile is a good fit).

bx:playwrightRender

Render the body with a real browser (modern CSS, web fonts, JavaScript):

<bx:playwrightRender type="pdf" path="invoice.pdf" format="A4" margin="1cm">
	<h1>Invoice #invoice.id#</h1>
</bx:playwrightRender>
bx:playwrightRender type="png" variable="card" viewport="1200x630" {
	writeOutput( socialCardHtml )
}
AttributeMeaning
typepdf (default), png, jpeg, webp
path / variableWrite a file and/or store the result (at least one)
baseURLResolves relative links and assets in the body (a <base href> is added unless the body has one)
waitFor, waitUntilWait for a selector, or load / networkidle
format, landscape, margin, printBackground, headerTemplate, footerTemplate, scale, pageRangesPDF options
viewport (WxH, or a { width, height } struct in render()), fullPage, omitBackground, quality, deviceImage options
profile, optionsA profile, and any extra render() option

Defaults come from the render setting.

Edit this page Download Markdown Last updated Sep 30, 2026, 7:24:11 PM