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 headless Chromium.
Unlike
render_report_as_pdf()which uses WeasyPrint (static CSS rendering), this method produces PDF output that matches the on-screen browser appearance by using Playwright + headless Chromium.- Parameters:
- context
dict,optional Additional rendering context.
- item_filter
str,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.- margins
dict[str,str],optional Page margins with
top,right,bottom, andleftPlaywright PDF lengths. If omitted, 10 mm margins are used on every side.- render_timeout
float,optional Maximum time, in seconds, for the Chromium 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.- **kwargs
Any Additional keyword arguments used to fetch the report template. At least one keyword argument must be provided.
- context
- Returns:
bytesPDF content generated by headless Chromium.
- Raises:
ADRExceptionIf no keyword arguments are provided or browser PDF rendering fails.
ImproperlyConfiguredErrorIf
static_directoryis 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
HTMLfragments 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)