Weblitz Preview

API reference

Every public type and member of the WeblitzPdf namespace (assembly WeblitzPdf), as the engine documents them: each member's signature, its default, the values it takes, and where a page of this documentation shows it rendered. Puppeteer's name for an option is given as a note, for those who print with it today.

HtmlToPdf static class

HTML to PDF as Chrome prints it: the page's HTML and CSS laid out, its scripts run once before printing, its pages written as a PDF. Thread-safe: documents render at once on as many threads as the caller uses.

Render

static method
public static HtmlPdfResult Render(string html, HtmlPdfOptions? options = null)

The PDF of html. Relative addresses resolve against HtmlPdfOptions.BaseUrl: a folder's (file:) files are read from that folder only, a web address's through the network the options allow; without one, nothing is fetched.

Parameters
Throws
Puppeteer
page.setContent(html) then page.pdf()
Rendered
Your first PDF: HTML text, Into a stream

RenderFile

static method
public static HtmlPdfResult RenderFile(string path, HtmlPdfOptions? options = null)

The PDF of the HTML file at path: its CSS, pictures, fonts and scripts read from its folder (never outside it), web addresses through the network the options allow.

Throws
Puppeteer
page.goto('file://...') then page.pdf()
Rendered
A file and its folder

RenderUrl

static method
public static HtmlPdfResult RenderUrl(Uri url, HtmlPdfOptions? options = null)

The PDF of the page at url, fetched with its resources. The network is the options' (HtmlPdfOptions.Network); when they leave it off, the page's own host is allowed. A page the server answers with an error status (401, 403, 404...) and a page of its own is printed, as Chrome prints it: HtmlPdfResult.HttpStatus and a note with the code documentHttpError tell it apart.

Throws
  • System.ArgumentNullException: url is null.
  • System.ArgumentException: url is not an absolute http or https address (a file goes to HtmlToPdf.RenderFile), or the options contradict themselves (as for HtmlToPdf.Render).
  • System.ArgumentOutOfRangeException: The options' Scale or ScrollStepWait is out of its range.
  • HtmlRenderException: The page could not be loaded (no answer, refused, or an error status with no page), or no PDF could be made at all.
Puppeteer
page.goto(url) then page.pdf()
Rendered
A web address

Render

static method
public static HtmlPdfResult Render(string html, Stream output, HtmlPdfOptions? options = null)

The PDF of html written to output (the result's HtmlPdfResult.Pdf is then null).

Throws
Puppeteer
page.setContent(html) then page.pdf()
Rendered
Your first PDF: HTML text, Into a stream

RenderAsync

static method
public static Task<HtmlPdfResult> RenderAsync(string html, HtmlPdfOptions? options = null, CancellationToken cancellationToken = default)

HtmlToPdf.Render on the thread pool. A cancellation stops a render that has not started; one under way runs to its end or to its limits (HtmlScripts.Timeout). The task faults with the exceptions HtmlToPdf.Render throws.

RenderFileAsync

static method
public static Task<HtmlPdfResult> RenderFileAsync(string path, HtmlPdfOptions? options = null, CancellationToken cancellationToken = default)

HtmlToPdf.RenderFile on the thread pool (cancellation as HtmlToPdf.RenderAsync).

RenderUrlAsync

static method
public static Task<HtmlPdfResult> RenderUrlAsync(Uri url, HtmlPdfOptions? options = null, CancellationToken cancellationToken = default)

HtmlToPdf.RenderUrl on the thread pool (cancellation as HtmlToPdf.RenderAsync).

HtmlPdfOptions record

What HtmlToPdf prints and how: Puppeteer's page.pdf() options under their names (the reference tool's defaults: A4, backgrounds printed, the page's @page size preferred), and what a server needs beyond them. A record: with makes a variant.

Default

static property
public static HtmlPdfOptions Default { get; }

The defaults.

Format

property
public string Format { get; init; }

The paper: Letter, Legal, Tabloid, Ledger, A0 to A6 (A4 by default).

Default
"A4"
Throws
Puppeteer
page.pdf({ format })
Rendered
Paper size and orientation

Width

property
public string? Width { get; init; }

The paper's width as a CSS length ("210mm", "8.5in"); with HtmlPdfOptions.Height, wins over HtmlPdfOptions.Format.

Default
null
Puppeteer
page.pdf({ width })
Rendered
Paper size and orientation

Height

property
public string? Height { get; init; }

The paper's height as a CSS length.

Default
null
Puppeteer
page.pdf({ height })
Rendered
Paper size and orientation

Landscape

property
public bool Landscape { get; init; }

The paper turned on its side (its width and height swapped). False by default; the page's @page size wins when HtmlPdfOptions.PreferCssPageSize and it gives an orientation.

Default
false
Puppeteer
page.pdf({ landscape })
Rendered
Paper size and orientation

Margin

property
public HtmlMargins? Margin { get; init; }

The page's margins; null: the page's @page margins, else Chrome's.

Default
null
Puppeteer
page.pdf({ margin })
Rendered
Margins

PreferCssPageSize

property
public bool PreferCssPageSize { get; init; }

The page's @page size wins over HtmlPdfOptions.Format (Chrome's preferCSSPageSize).

Default
true
Puppeteer
page.pdf({ preferCSSPageSize })
Rendered
The page's own @page size

PrintBackground

property
public bool PrintBackground { get; init; }

Background colours and pictures printed.

Default
true
Puppeteer
page.pdf({ printBackground })
Rendered
Backgrounds

Scale

property
public double Scale { get; init; }

The page's content scaled when printed (Chrome's scale): 0.1 to 2, 1 by default; the paper keeps its size.

Default
1
Throws
  • System.ArgumentOutOfRangeException: At render: outside 0.1 to 2.
Puppeteer
page.pdf({ scale })
Rendered
Scale

PageRanges

property
public string? PageRanges { get; init; }

The pages printed: "1-5, 8, 11-13"; null: every page.

Default
null
Puppeteer
page.pdf({ pageRanges })
Rendered
Choosing pages

DisplayHeaderFooter

property
public bool DisplayHeaderFooter { get; init; }

Chrome's header and footer templates printed in the margins.

Default
false
Puppeteer
page.pdf({ displayHeaderFooter })
Rendered
Header and footer templates

HeaderTemplate

property
public string? HeaderTemplate { get; init; }

The header printed in each page's top margin when HtmlPdfOptions.DisplayHeaderFooter: HTML whose elements of the classes pageNumber, totalPages, title, url and date get those values. It is a document of its own, as in Chrome: its styles are the template's (a template without a font-size prints at 1px, as in Chrome), no scripts run, nothing is fetched, backgrounds need print-color-adjust: exact. Null or empty: Chrome's default header (the date and the title).

Default
null
Puppeteer
page.pdf({ headerTemplate })
Rendered
Header and footer templates

FooterTemplate

property
public string? FooterTemplate { get; init; }

The footer printed in each page's bottom margin when HtmlPdfOptions.DisplayHeaderFooter, as HtmlPdfOptions.HeaderTemplate. Null or empty: Chrome's default footer (the address and "page/pages").

Default
null
Puppeteer
page.pdf({ footerTemplate })
Rendered
Header and footer templates

BaseUrl

property
public Uri? BaseUrl { get; init; }

What relative addresses resolve against for HtmlToPdf.Render.

Default
null
Rendered
The network

Scripts

property
public HtmlScripts Scripts { get; init; }

The page's scripts and its frames': on, as in Chrome.

Default
HtmlScripts.Default
Rendered
Scripts and the virtual clock

Network

property
public HtmlNetwork Network { get; init; }

The network: off by default (nothing is fetched but a file's own folder).

Default
HtmlNetwork.Off
Rendered
A web address, The network

ScrollTo

property
public string? ScrollTo { get; init; }

Scroll the window before printing, as a user would before pressing Print (with Puppeteer, a window.scrollTo in page.evaluate before page.pdf): "top", "bottom", a CSS selector (its first match scrolled into view, its top at the window's top) or a length from the document's top in px ("1200px", "1200"). Null (the default): not scrolled. It happens once the page's scripts have settled, in screen media, before beforeprint: the page's scroll events, scroll positions and IntersectionObserver callbacks see it, and what scripts change is printed. Animations on the root scroll timeline print at their start, scrolled or not, as Chrome prints them. The PDF still holds the whole document from its top, as Chrome's print of a scrolled page does; HtmlPdfOptions.Region prints a part of it. Without scripts, nothing changes.

Default
null
Throws
  • System.ArgumentException: At render: empty or white space (null not to scroll).
Puppeteer
page.evaluate(() => window.scrollTo(...)) before page.pdf()
Rendered
Scrolling to a section first

ScrollThrough

property
public bool ScrollThrough { get; init; }

Scroll the window from the top to the document's end, one window height at a time, before printing: what a page loads as one scrolls (infinite lists, images and charts made when they come into view) is loaded and printed. Each step waits HtmlPdfOptions.ScrollStepWait of the page's virtual time; at most 200 steps. The window then goes to HtmlPdfOptions.ScrollTo, else back to the top.

IntersectionObserver without a scroll option (neither this nor HtmlPdfOptions.ScrollTo): every observed element is reported visible once, wherever it is, so content a page loads as it comes into view (lazy images, charts, list items made by scripts) is loaded and printed, the whole page in the PDF, which is what a PDF is for. Chrome reports only what is in the window, so with Puppeteer such a page prints its first screen unless it is scrolled first. With a scroll option, Weblitz reports real intersections with the window, as Chrome does.

Default
false
Rendered
Lists that load as you scroll

ScrollStepWait

property
public TimeSpan ScrollStepWait { get; init; }

The virtual time each scroll (HtmlPdfOptions.ScrollTo, each step of HtmlPdfOptions.ScrollThrough) gives the page to react: its timers, animation frames, observers and image loads. 0 to 60 seconds; 0.5 s by default.

Default
00:00:00.5000000
Throws
  • System.ArgumentOutOfRangeException: At render: outside 0 to 60 seconds.
Rendered
Lists that load as you scroll

Region

property
public HtmlPrintRegion? Region { get; init; }

Print only a part of the document (null, the default: all of it): from a start (the window's scroll position, a length or an element) to an optional height; what lies above and below is left out. The part is laid out on pages as a whole document is: @page sizes and margins, page breaks, headers and footers.

Default
null
Rendered
Printing a part of the page

UserAgent

property
public string? UserAgent { get; init; }

The browser the page sees and the network is told of (Puppeteer's page.setUserAgent(userAgent, userAgentMetadata)): navigator.userAgent, appVersion and the User-Agent header. Null: desktop Chrome 156's on the machine's OS (macOS, Windows or Linux).

Default
null
Puppeteer
page.setUserAgent(userAgent)
Rendered
The browser the page sees

UserAgentMetadata

property
public HtmlUserAgentMetadata? UserAgentMetadata { get; init; }

What navigator.userAgentData says and the Sec-CH-UA headers send. Null: the machine's Chrome's when HtmlPdfOptions.UserAgent is null, else none (as Chrome, given a User-Agent without metadata).

Default
null
Puppeteer
page.setUserAgent(userAgent, userAgentMetadata)
Rendered
The browser the page sees

Title

property
public string? Title { get; init; }

The PDF's title (the page's <title> when null) and author.

Default
null
Rendered
Title, author and PDF/A

Author

property
public string? Author { get; init; }

The PDF's author (the page's <meta name="author"> when null).

Default
null
Rendered
Title, author and PDF/A

PdfA

property
public bool PdfA { get; init; }

A PDF/A-2b document (archival: fonts embedded, an output intent, XMP metadata). False by default.

Default
false
Throws
Puppeteer
page.pdf({ tagged }) has no PDF/A
Rendered
Title, author and PDF/A

Security

property
public HtmlPdfSecurity? Security { get; init; }

Passwords and permissions (AES-256); not with HtmlPdfOptions.PdfA.

Default
null
Rendered
Passwords and permissions

Compression

property
public HtmlPdfCompression Compression { get; init; }

How hard the PDF's streams are deflated: HtmlPdfCompression.Fastest by default, smaller files at the cost of time with HtmlPdfCompression.Default or HtmlPdfCompression.Smallest.

Default
HtmlPdfCompression.Fastest
Values
None Fastest Default Smallest
Rendered
PDF compression

Locale

property
public string Locale { get; init; }

What the page's scripts and Intl see: its language, time zone and clock (fixed: the same PDF every time).

Default
"en-US"
Rendered
Locale, time zone and clock

TimeZone

property
public string TimeZone { get; init; }

The time zone the page's scripts see (an IANA name: "Europe/Paris", "America/New_York"; "UTC" by default): Date's local time and offset and Intl's formatting, as Chrome with an emulated time zone.

Default
"UTC"
Puppeteer
page.emulateTimezone(timezoneId)
Rendered
Locale, time zone and clock

Now

property
public DateTimeOffset? Now { get; init; }

The clock the page's scripts start at (Date.now(), new Date()), and the PDF's creation date; then virtual time runs from it. Null: a fixed date (2026-01-01 00:00 UTC), so the same input makes the same PDF.

Default
null
Rendered
Locale, time zone and clock

UseInstalledFonts

property
public bool UseInstalledFonts { get; init; }

The machine's fonts after the page's own @font-face fonts; false: the bundled faces only.

Default
true
Rendered
Installed fonts

Limits

property
public HtmlPdfLimits Limits { get; init; }

What a page may ask for: input size, pages, resources.

Default
HtmlPdfLimits.Default
Rendered
Limits

ExperimentalWebFeatures

property
public bool ExperimentalWebFeatures { get; init; }

Chrome's experimental web platform features that Weblitz has built, on, as Chrome 156 lays them out with its "Experimental Web Platform features" flag (default false: Weblitz prints as stable Chrome does, which ignores them). Among them: grid lanes (display: grid-lanes and inline-grid-lanes, the masonry layout, with grid-lanes-direction, grid-lanes-pack and flow-tolerance), their gap decorations and page and column breaks, text-decoration-inset, text-decoration-skip-spaces, text-transform's full-width and full-size-kana beside a case keyword, the flow-start and flow-end alignment keywords, image symbols in @counter-style. Scripts see them too (CSS.supports, the parsed styles).

Default
false
Rendered
Chrome's experimental features

HtmlMargins record

Page margins as CSS lengths ("18mm", "0.5in", "40px"; a bare number is px, as Puppeteer reads it).

HtmlMargins

constructor
public HtmlMargins(string? Top = null, string? Right = null, string? Bottom = null, string? Left = null)

Page margins as CSS lengths ("18mm", "0.5in", "40px"; a bare number is px, as Puppeteer reads it).

Parameters
  • Top: The top margin; null: the page's @page margin, else Chrome's (about 1 cm).
  • Right: The right margin; null as Top.
  • Bottom: The bottom margin; null as Top.
  • Left: The left margin; null as Top.

Top

property
public string? Top { get; init; }

The top margin; null: the page's @page margin, else Chrome's (about 1 cm).

Right

property
public string? Right { get; init; }

The right margin; null as Top.

Bottom

property
public string? Bottom { get; init; }

The bottom margin; null as Top.

Left

property
public string? Left { get; init; }

The left margin; null as Top.

All

static method
public static HtmlMargins All(string length)

The same margin on the four sides.

HtmlPrintRegion record

The part of the document HtmlPdfOptions.Region prints: from HtmlPrintRegion.From to HtmlPrintRegion.Height below it. What lies above the start and below the end is left out; the part is laid out on pages as the whole document is, so a tall part breaks into pages.

FromScroll

static property
public static HtmlPrintRegion FromScroll { get; }

From the window's scroll position (HtmlPdfOptions.ScrollTo, or where the page's scripts scrolled it) to the end.

From

property
public string From { get; init; }

Where the part starts: "scroll" (the default: the window's scroll position when printing starts), "top", a length from the document's top in px ("1200px", "1200"), or a CSS selector (its first match's top). The print's layout is measured, the page's print styles applied: a selector's top is where the element is on paper.

Default
"scroll"

Height

property
public string? Height { get; init; }

How much of the document is printed from HtmlPrintRegion.From, as a CSS length ("1200px", "20cm", "8in", "600pt"; a bare number is px). Null (the default): to the document's end.

Default
null
Throws
  • System.ArgumentException: At render: not a length greater than 0.

Of

static method
public static HtmlPrintRegion Of(string from, string? height = null)

From from (see HtmlPrintRegion.From), height tall (see HtmlPrintRegion.Height; null: to the end).

HtmlScripts record

The page's scripts: run once before printing (V8), timers and animations in virtual time. Its frames' documents run theirs with them, those of another origin too (as in Chrome, their windows out of the page's reach); HtmlScripts.Off runs none, a frame's neither.

Default

static property
public static HtmlScripts Default { get; }

Scripts on, with the default timeout (30 s of CPU time) and wait (5 s of virtual time).

Off

static property
public static HtmlScripts Off { get; }

No script runs, a frame's neither: the HTML and CSS as they are written.

Enabled

property
public bool Enabled { get; init; }

Whether the page's scripts run (true by default).

Default
true
Puppeteer
page.setJavaScriptEnabled(enabled)

Timeout

property
public TimeSpan Timeout { get; init; }

The CPU time the scripts may take before they are stopped (the pages printed as they are then).

Default
TimeSpan.FromSeconds(30)

WaitFor

property
public TimeSpan WaitFor { get; init; }

The virtual time timers and animations run for before printing.

Default
TimeSpan.FromSeconds(5)

HtmlNetwork record

What the render may fetch from the network: off, some hosts, or any public host (never the machine's own addresses unless named).

Off

static property
public static HtmlNetwork Off { get; }

Nothing is fetched from the network (the default): a file's own folder is still read.

Any

static property
public static HtmlNetwork Any { get; }

Any public host (never the machine's own or private addresses unless named in HtmlNetwork.AllowedHosts).

AllowedHosts

property
public IReadOnlyList<string> AllowedHosts { get; init; }

The hosts the render may fetch from: names ("example.com"), wildcards ("*.example.com"), "*" for any public host. Empty: the network is off.

Default
[]

ResourceTimeout

property
public TimeSpan ResourceTimeout { get; init; }

The time one resource may take (15 s by default); what has not arrived is left out, noted.

Default
TimeSpan.FromSeconds(15)

TotalTimeout

property
public TimeSpan TotalTimeout { get; init; }

The time the whole document's resources may take together (60 s by default).

Default
TimeSpan.FromSeconds(60)

CacheDirectory

property
public string? CacheDirectory { get; init; }

A folder where fetched resources are kept between renders (HTTP's caching rules), or none. A render with HtmlNetwork.Headers, HtmlNetwork.Cookies, HtmlNetwork.AcceptCookies or HtmlNetwork.Credentials neither reads nor writes it: what a signed-in render receives is never handed to another render.

Default
null

Headers

property
public IReadOnlyList<HtmlRequestHeader> Headers { get; init; }

Request headers added to the render's fetches (an Authorization: Bearer token, an API key), each sent only to the hosts it names, by default the document's own host: never to a CDN or another site's script unless named. A header is not sent on a redirect to a host it does not name. Host, Content-Length, Cookie (use HtmlNetwork.Cookies) and the other headers the fetcher writes itself are refused.

Default
[]
Puppeteer
page.setExtraHTTPHeaders(headers)
Rendered
Pages behind a login

Cookies

property
public IReadOnlyList<HtmlCookie> Cookies { get; init; }

Cookies the render starts with, as a browser signed in would have them (a session cookie): sent by the cookie rules (domain, path, Secure, SameSite, expiry) with the document, its frames, style sheets, pictures, fonts, scripts and the page's own fetch() and XMLHttpRequest calls to its origin; the page's scripts read them in document.cookie unless HttpOnly. Setting any keeps the cookies servers set during the render too (HtmlNetwork.AcceptCookies).

Default
[]
Puppeteer
page.setCookie(...cookies)
Rendered
Pages behind a login

AcceptCookies

property
public bool AcceptCookies { get; init; }

Whether the cookies servers set (Set-Cookie, redirects included) and the page's scripts set are kept for the rest of the render and sent back, as a browser does: a login redirect that sets a session cookie then works. Nothing is kept between renders. True whenever HtmlNetwork.Cookies holds any; false by default.

Default
false
Rendered
Pages behind a login

Credentials

property
public HtmlCredentials? Credentials { get; init; }

A user name and password answering a host's HTTP authentication challenge (Basic or Digest, after its 401), for the hosts they name, by default the document's own host; never sent unasked, nor to another host.

Default
null
Puppeteer
page.authenticate(credentials)
Rendered
Pages behind a login

Allow

static method
public static HtmlNetwork Allow(string[] hosts)

These hosts only ("example.com", "*.example.com").

WithHeader

method
public HtmlNetwork WithHeader(string name, string value, string[] hosts)

This network with a header added (HtmlNetwork.Headers): for hosts, else the document's own host.

WithBearerToken

method
public HtmlNetwork WithBearerToken(string token, string[] hosts)

This network with Authorization: Bearer added: for hosts, else the document's own host.

WithCookie

method
public HtmlNetwork WithCookie(HtmlCookie cookie)

This network with a cookie added (HtmlNetwork.Cookies).

HtmlRequestHeader record

A request header a render adds to its fetches (HtmlNetwork.Headers).

HtmlRequestHeader

constructor
public HtmlRequestHeader(string Name, string Value)

A request header a render adds to its fetches (HtmlNetwork.Headers).

Parameters
  • Name: The header's name ("Authorization", "X-Api-Key").
  • Value: Its value ("Bearer eyJ...").

Name

property
public string Name { get; init; }

The header's name ("Authorization", "X-Api-Key").

Value

property
public string Value { get; init; }

Its value ("Bearer eyJ...").

Hosts

property
public IReadOnlyList<string> Hosts { get; init; }

The hosts it is sent to ("api.example.com", "*.example.com"); empty: the document's own host only (a document read from a file has none: name the hosts).

HtmlCookie record

A cookie a render starts with (HtmlNetwork.Cookies), as a browser keeps it.

HtmlCookie

constructor
public HtmlCookie(string Name, string Value)

A cookie a render starts with (HtmlNetwork.Cookies), as a browser keeps it.

Parameters
  • Name: Its name.
  • Value: Its value.

Name

property
public string Name { get; init; }

Its name.

Value

property
public string Value { get; init; }

Its value.

Domain

property
public string? Domain { get; init; }

The domain it goes to with its subdomains ("example.com"); null: the document's own host alone.

Path

property
public string Path { get; init; }

The path it goes to with the paths under it ("/" by default).

Secure

property
public bool Secure { get; init; }

Sent over https: only (and to the machine's own addresses, as Chrome sends it there).

HttpOnly

property
public bool HttpOnly { get; init; }

Hidden from the page's scripts (document.cookie, cookieStore).

SameSite

property
public HtmlCookieSameSite SameSite { get; init; }

How it goes with requests from other sites (Lax by default).

Values
Lax Strict None

Expires

property
public DateTimeOffset? Expires { get; init; }

When it expires; null: it lasts the render.

HtmlCookieSameSite enum

How a cookie goes with requests from other sites (its SameSite attribute).

Lax

value
Lax = 0

With the site's own requests and the top-level document (browsers' default).

Strict

value
Strict = 1

With the site's own requests only.

None

value
None = 2

With every request, other sites' too; the cookie must be HtmlCookie.Secure.

HtmlCredentials record

A user name and password answering HTTP authentication (HtmlNetwork.Credentials).

HtmlCredentials

constructor
public HtmlCredentials(string UserName, string Password)

A user name and password answering HTTP authentication (HtmlNetwork.Credentials).

Parameters
  • UserName: The user name.
  • Password: The password.

UserName

property
public string UserName { get; init; }

The user name.

Password

property
public string Password { get; init; }

The password.

Hosts

property
public IReadOnlyList<string> Hosts { get; init; }

The hosts that may be answered ("intranet.example.com", "*.example.com"); empty: the document's own host.

HtmlPdfSecurity record

A PDF's passwords and what a reader may do without the owner's (AES-256).

UserPassword

property
public string? UserPassword { get; init; }

The password a reader needs to open the PDF; null: it opens without one.

Default
null

OwnerPassword

property
public string? OwnerPassword { get; init; }

The password that lifts the permissions below; null: none set.

Default
null

PermitPrinting

property
public bool PermitPrinting { get; init; }

Whether a reader may print without the owner's password (true by default).

Default
true

PermitCopying

property
public bool PermitCopying { get; init; }

Whether a reader may copy text and pictures without the owner's password (true by default).

Default
true

PermitModifying

property
public bool PermitModifying { get; init; }

Whether a reader may change the document without the owner's password (true by default).

Default
true

HtmlPdfCompression enum

How hard the PDF's streams are deflated: the fastest by default, smaller at the cost of speed.

None

value
None = 0

Streams stored without deflating: the largest files, the fastest writing.

Fastest

value
Fastest = 1

zlib's fastest level (1): the default, the fastest writing of a deflated PDF.

Default

value
Default = 6

zlib's default level (6): smaller files, slower writing.

Smallest

value
Smallest = 9

zlib's best level (9): the smallest files, the slowest writing.

HtmlPdfLimits record

What a page may ask for (an untrusted page is held to these).

Default

static property
public static HtmlPdfLimits Default { get; }

The default limits (each below).

MaxInputBytes

property
public long MaxInputBytes { get; init; }

The largest document read (50 MB by default): past it the rest is not parsed and the result is not HtmlPdfResult.Completed.

Default
52,428,800 (50 MB)

MaxPages

property
public int MaxPages { get; init; }

The most pages printed (10,000 by default): the document is cut there, not completed.

Default
10,000

MaxNodes

property
public int MaxNodes { get; init; }

The most DOM nodes, the parser's and the scripts' (1,000,000 by default): past it the parse or the scripts stop, not completed.

Default
1,000,000

MaxResourceBytes

property
public long MaxResourceBytes { get; init; }

The largest resource fetched or read (20 MB by default): a larger one is left out, noted.

Default
20,971,520 (20 MB)

MaxTotalResourceBytes

property
public long MaxTotalResourceBytes { get; init; }

The most bytes of resources a document fetches and reads in all (200 MB by default).

Default
209,715,200 (200 MB)

HtmlUserAgentMetadata record

What navigator.userAgentData says and the Sec-CH-UA headers send (CDP's Emulation.UserAgentMetadata, Puppeteer's userAgentMetadata).

Puppeteer: Protocol.Emulation.UserAgentMetadata

Brands

property
public IReadOnlyList<HtmlUserAgentBrand> Brands { get; init; }

The brands with their major versions.

Default
[]

FullVersionList

property
public IReadOnlyList<HtmlUserAgentBrand> FullVersionList { get; init; }

The brands with their full versions.

Default
[]

FullVersion

property
public string? FullVersion { get; init; }

uaFullVersion (deprecated in Chrome; Chrome's own when null).

Default
null

Platform

property
public string Platform { get; init; }

"macOS", "Windows", "Linux", "Android"...

Default
""

PlatformVersion

property
public string PlatformVersion { get; init; }

The platform's version ("15.0.0", "10.0.0"); empty: none said.

Default
""

Architecture

property
public string Architecture { get; init; }

"arm", "x86".

Default
""

Model

property
public string Model { get; init; }

The device model, for a mobile device ("Pixel 9"); empty on desktops.

Default
""

Mobile

property
public bool Mobile { get; init; }

Whether the browser says it is a mobile one (navigator.userAgentData.mobile, Sec-CH-UA-Mobile).

Default
false

Bitness

property
public string Bitness { get; init; }

"64", "32".

Default
""

Wow64

property
public bool Wow64 { get; init; }

Whether a 32-bit browser runs on 64-bit Windows (Sec-CH-UA-WoW64); false elsewhere.

Default
false

FormFactors

property
public IReadOnlyList<string>? FormFactors { get; init; }

"Desktop", "Mobile", "Tablet"...; Chrome's ["Desktop"] when null.

Default
null

ChromeOnThisMachine

static property
public static HtmlUserAgentMetadata ChromeOnThisMachine { get; }

Desktop Chrome 156's on the machine's OS, as the engine says by default.

HtmlUserAgentBrand record

A brand of HtmlUserAgentMetadata: navigator.userAgentData's brands and Sec-CH-UA's.

HtmlUserAgentBrand

constructor
public HtmlUserAgentBrand(string Brand, string Version)

A brand of HtmlUserAgentMetadata: navigator.userAgentData's brands and Sec-CH-UA's.

Parameters

Brand

property
public string Brand { get; init; }

The brand's name ("Google Chrome", "Chromium", "Not:A-Brand").

Version

property
public string Version { get; init; }

Its version: the major one in HtmlUserAgentMetadata.Brands ("156"), the full one in HtmlUserAgentMetadata.FullVersionList ("156.0.8078.47").

HtmlPdfResult class

A printed document: its PDF, its pages, and what the engine noted.

Pdf

property
public byte[]? Pdf { get; }

The document; null when it was written to a stream.

PageCount

property
public int PageCount { get; }

The pages printed (after page ranges chose some).

Notes

property
public IReadOnlyList<HtmlPdfNote> Notes { get; }

What was left out or could not be drawn: a font missing, a resource refused, a script that threw, content shrunk to fit. A page's own errors are notes, never exceptions, as a browser goes on.

Rendered
Notes: what could not be done

Completed

property
public bool Completed { get; }

False when a limit or the script timeout stopped the render (the pages printed so far are the PDF).

Rendered
Limits

Elapsed

property
public TimeSpan Elapsed { get; }

How long the render took, from the call to the PDF written.

HttpStatus

property
public int? HttpStatus { get; }

The HTTP status the server answered for the document, when it was fetched by its URL (HtmlToPdf.RenderUrl): a success (200), or an error (401, 403, 404...) whose page the server sent and which was printed, as Chrome prints it (a note with the code documentHttpError says so). Null for HTML given as text or read from a file.

HtmlPdfNote record

One thing the engine noted about the document.

HtmlPdfNote

constructor
public HtmlPdfNote(string Code, HtmlPdfNoteSeverity Severity, string Message, string? Element)

One thing the engine noted about the document.

Parameters
  • Code: What kind of note: a stable word ("missingGlyph", "resourceFailed", "limitReached", "scriptError", "notImplemented"...) to sort or filter by.
  • Severity: How much it matters to the PDF.
  • Message: What happened, in plain words.
  • Element: Where, when the note is about one element: its path from the root element, CSS-like (the tag, "#id", the first ".class", ":nth-of-type(n)" among siblings of its name, joined by ">": "html>body>div.card:nth-of-type(2)"); null for the document as a whole.

Code

property
public string Code { get; init; }

What kind of note: a stable word ("missingGlyph", "resourceFailed", "limitReached", "scriptError", "notImplemented"...) to sort or filter by.

Severity

property
public HtmlPdfNoteSeverity Severity { get; init; }

How much it matters to the PDF.

Values
Info Warning Error

Message

property
public string Message { get; init; }

What happened, in plain words.

Element

property
public string? Element { get; init; }

Where, when the note is about one element: its path from the root element, CSS-like (the tag, "#id", the first ".class", ":nth-of-type(n)" among siblings of its name, joined by ">": "html>body>div.card:nth-of-type(2)"); null for the document as a whole.

HtmlPdfNoteSeverity enum

How much a note matters to the PDF.

Info

value
Info = 0

For information: the PDF is as Chrome's would be (a setting ignored as Chrome ignores it, content shrunk to fit).

Warning

value
Warning = 1

Something is missing or differs (a resource not loaded, a glyph a font lacks, a limit reached).

Error

value
Error = 2

A part could not be made (a script that threw, a stage that failed).

HtmlRenderException class

No PDF could be made at all (the input over its limit, a stage that failed).

HtmlRenderException

constructor
public HtmlRenderException(string message)

The exception with what went wrong.

Parameters
  • message: Why no PDF could be made, with the engine's error notes.

License static class

Your SSRS2 licence key, which covers Weblitz: the same as Ssrs2.License, under Weblitz's name. Without a key, every page carries a trial watermark.

IsActive

static property
public static bool IsActive { get; }

Whether a valid licence is active.

LicensedTo

static property
public static string? LicensedTo { get; }

The licensed company, or null when not licensed.

ExpiryDate

static property
public static DateTime? ExpiryDate { get; }

The licence's expiry date, or null when not licensed.

UpdatesUntil

static property
public static DateTime? UpdatesUntil { get; }

The last release date a licence covers for good, or null (not licensed, or a key that simply expires).

Tier

static property
public static string? Tier { get; }

The licence's tier, or null when not licensed.

Features

static property
public static IReadOnlyList<string> Features { get; }

The features the active licence names.

Activate

static method
public static void Activate(string licenseKey)

Activates the licence key (an SSRS2-... key). Call it once at application startup.

Throws
  • SSRS2.Licensing.LicenseException: The key is invalid or has expired.

TryActivate

static method
public static bool TryActivate(string licenseKey, out string error)

Activates the licence key without throwing: false and the reason when it is refused.

TryRead

static method
public static bool TryRead(string licenseKey, out LicenseInfo? info, out string error)

Reads a licence key without activating it: whether it is genuine and has not expired, and what it says.

HasFeature

static method
public static bool HasFeature(string feature)

Whether the active licence names feature.