from_html()
Take a screenshot or PDF from an HTML string.
Usage
from_html(
html, file="webshot.png", *, selector="html", encoding="utf-8", **kwargs
)This is the primary integration point for packages like great-tables that generate HTML and need to convert it to an image or PDF.
For PDF output with a selector (other than "html"), produces an element-bounded PDF sized to fit the selected element with selectable text preserved, and this is useful for embedding tables in presentations.
Parameters
html: str-
The HTML content to render.
file: str | Path = "webshot.png"-
Output file path. Format determined by extension (
.png,.jpg,.webpfor images;.pdffor PDF). selector: str = "html"-
CSS selector to capture (default:
"html"for full page). When a specific selector is used with PDF output, produces a tightly-bounded PDF. Wide elements (e.g., tables) are automatically detected and rendered at their natural width. encoding: str = "utf-8"-
Character encoding for the HTML file.
**kwargs: Any- Additional arguments passed to webshot() (e.g., zoom, expand, delay, vwidth, vheight).
Returns
Path- The absolute path to the output file.