render_report_as_browser_pdf#

ADR.render_report_as_browser_pdf(*, context: dict | None = None, item_filter: str = '', dark_mode: bool = False, landscape: bool = False, margins: dict[str, str] | None = None, render_timeout: float = 30.0, **kwargs: Any) bytes#

Render a report as a browser-fidelity PDF byte stream via a headless browser.

Unlike render_report_as_pdf() which uses WeasyPrint (static CSS rendering), this method produces PDF output that matches the on-screen browser appearance by rendering in a headless browser.

Parameters:
contextdict, optional

Additional rendering context.

item_filterstr, optional

Filter expression for report items.

dark_modebool, optional

Whether to render using a dark theme. Default False.

landscapebool, optional

Whether to use landscape orientation. Default False.

marginsdict[str, str], optional

Page margins with top, right, bottom, and left values expressed as strings using unitless pixels or the px, in, cm, or mm units (for example "10mm" or "0.5in"). If omitted, 10 mm margins are used on every side.

render_timeoutfloat, optional

Maximum time, in seconds, for the browser render phase after the offline HTML bundle has been staged. This shared browser-side budget covers launch, navigation, readiness waits, and related browser preparation, but not server-side report rendering or offline asset export. Default 30.0.

**kwargsAny

Additional keyword arguments used to fetch the report template. At least one keyword argument must be provided.

Returns:
bytes

PDF content generated by the headless browser.

Raises:
ADRException

If no keyword arguments are provided or browser PDF rendering fails.

ImproperlyConfiguredError

If static_directory is not configured.

Notes

Browser-PDF readiness waits cover ADR-owned signals such as web-component initialization, fonts, MathJax, Plotly, images, and videos. HTML items and layout HTML fragments are rendered as raw macro-expanded HTML by the underlying template system, so custom asynchronous JavaScript inside those fragments does not get a separate readiness hook here. Static HTML content is supported, but arbitrary async HTML content can still be captured before it finishes updating unless it settles through the built-in browser-PDF signals.

Examples

>>> from ansys.dynamicreporting.core.serverless import ADR
>>> adr = ADR(
...     ansys_installation=r"C:\Program Files\ANSYS Inc\v252",
...     db_directory=r"C:\DBs\docex",
...     media_directory=r"C:\DBs\docex\media",
...     static_directory=r"C:\static",
... )
>>> adr.setup(collect_static=True)
>>> pdf_bytes = adr.render_report_as_browser_pdf(
...     name="Serverless Simulation Report",
...     landscape=True,
...     margins={"top": "12mm", "right": "12mm", "bottom": "12mm", "left": "12mm"},
... )
>>> with open("browser-report.pdf", "wb") as f:
...     f.write(pdf_bytes)