Pass RenderOptions to renderPdf or renderer.render.
import { renderPdf, type RenderOptions } from "@imggion/html2realpdf";
const options: RenderOptions = {
page: { format: "a4", unit: "mm", margin: [12, 13, 12, 13] },
cssProfile: "web",
mediaType: "print",
layoutContext: "page",
viewport: { width: 1200, height: 1600 },
fallback: "error",
};
const pdf = await renderPdf(document.querySelector("#report")!, options);Main render options
This table is generated from the public RenderOptions interface.
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
page | PageOptions | No | None | Explicit page geometry; captured `@page` rules are used when omitted. |
cssProfile | CssProfile | No | document | Layout profile. Defaults to `document`. |
mediaType | MediaType | No | screen | Media environment used for style resolution. Defaults to `screen`. |
layoutContext | LayoutContext | No | source | Root layout context. `source` preserves the mounted browser width; `page` resolves an implicit root width and auto inline margins against the PDF content box. Defaults to `source`. |
viewport | ViewportOptions | No | None | Isolated viewport used for media queries and responsive layout. |
unsupportedCss | UnsupportedCssPolicy | No | error for strict mode and warn otherwise | Unsupported-CSS policy; defaults to `error` for strict mode and `warn` otherwise. |
fallback | FallbackPolicy | No | error | Unsupported SVG policy. Defaults to `error`. |
resourcePolicy | "error" | "omit" | No | error | Failed-resource policy. Defaults to `error`. |
pageBreak | PageBreakRules | No | None | Selector-driven page-break overrides. |
metadata | PdfMetadata | No | None | PDF information dictionary fields. |
enableLinks | boolean | No | None | Preserves HTTP(S), mail, telephone, and FTP annotations unless explicitly set to `false`. |
The complete generated interface includes callbacks, Shadow DOM, canvas, and cancellation options.
Page geometry
Use page to override captured @page geometry.
const options: RenderOptions = {
page: {
format: "letter",
orientation: "landscape",
unit: "in",
margin: [0.5, 0.6],
},
};Named a4 and letter formats keep their physical dimensions. Custom [width, height] values use the selected unit.
Four margin values use [top, left, bottom, right]. This follows the compatibility API, not CSS shorthand order.
CSS profiles
document is the default. It targets stable paged document layout.
web enables the broader browser layout profile.
strict uses the broader profile and rejects unsupported snapshot CSS by default.
The versioned CSS support matrix lists current property coverage.
Deterministic responsive layout
Set viewport when media queries or responsive styles affect the result. Set mediaType to print when the document uses print rules.
Use layoutContext: "page" when an implicit root width and auto inline margins should resolve against the PDF content box.
Metadata
Write PDF information fields with metadata.
const pdf = await renderPdf(source, {
metadata: {
title: "Quarterly report",
author: "Example Company",
keywords: ["report", "quarterly"],
creator: "Example dashboard",
},
});