ImagingPrintExtensions Class
Prints the documents of a browsing context into pages (https://drafts.csswg.org/css-page-3/): the document is laid out with the print media type and paginated (the page size, margins and page names of the @page rules, the page breaks), and each page is rendered into its own image.
public static class ImagingPrintExtensionsRemarks
The printing does not change the document: its styles and its layout are computed by other engines while it prints, so the screen is neither styled nor laid out again afterwards (no transition starts, no event is fired). As for the screenshots, call it from the thread of the DomEventLoop of the browsing context, after the resources are loaded. The images and the fonts that only the print styles use (e.g. in @media print) are fetched by the printing, but they are not drawn by it when they were not loaded before: print the document again once they are.
Methods
| Name | Description |
|---|---|
| RenderPages(BrowsingContext, PrintOptions?, ScreenshotOptions?) | Prints the active document of a browsing context and renders each page. |
| RenderPages(Document, PrintOptions?, ScreenshotOptions?) | Prints a document and renders each page. |
| RenderPagesAsPng(BrowsingContext, PrintOptions?, ScreenshotOptions?) | Prints the active document of a browsing context and renders each page, encoded as PNG. |
| RenderPagesAsPng(Document, PrintOptions?, ScreenshotOptions?) | Prints a document and renders each page, encoded as PNG. |
RenderPages overloads
RenderPages(BrowsingContext, PrintOptions?, ScreenshotOptions?)
ImagingPrintExtensions.csPrints the active document of a browsing context and renders each page.
public static IReadOnlyList<Image<Rgba32>> RenderPages(this BrowsingContext browsingContext, PrintOptions? printOptions = null, ScreenshotOptions? options = null)Parameters
browsingContextBrowsingContext- The browsing context.
printOptionsPrintOptions?- The page size and the default margins, or null for
PrintOptions.Default. optionsScreenshotOptions?- The options of the images (the device pixel ratio, the omission of the white paper), or null for the default options.
Returns
IReadOnlyList<Image<Rgba32>> One image per page, of the size of its page box in device pixels. The caller owns them.
Exceptions
InvalidOperationException- The document is not rendered.
RenderPages(Document, PrintOptions?, ScreenshotOptions?)
ImagingPrintExtensions.csPrints a document and renders each page.
public static IReadOnlyList<Image<Rgba32>> RenderPages(this Document document, PrintOptions? printOptions = null, ScreenshotOptions? options = null)Parameters
documentDocument- The document, which must be the active document of a browsing context.
printOptionsPrintOptions?- The page size and the default margins, or null for
PrintOptions.Default. optionsScreenshotOptions?- The options of the images (the device pixel ratio, the omission of the white paper), or null for the default options.
Returns
IReadOnlyList<Image<Rgba32>> One image per page, of the size of its page box in device pixels. The caller owns them.
Exceptions
InvalidOperationException- The document is not rendered (it has no browsing context), or it is already being printed.
RenderPagesAsPng overloads
RenderPagesAsPng(BrowsingContext, PrintOptions?, ScreenshotOptions?)
ImagingPrintExtensions.csPrints the active document of a browsing context and renders each page, encoded as PNG.
public static IReadOnlyList<byte[]> RenderPagesAsPng(this BrowsingContext browsingContext, PrintOptions? printOptions = null, ScreenshotOptions? options = null)Parameters
browsingContextBrowsingContextprintOptionsPrintOptions?optionsScreenshotOptions?
Returns
IReadOnlyList<byte[]> The bytes of the PNG image of each page.
Exceptions
InvalidOperationException- The document is not rendered.
RenderPagesAsPng(Document, PrintOptions?, ScreenshotOptions?)
ImagingPrintExtensions.csPrints a document and renders each page, encoded as PNG.
public static IReadOnlyList<byte[]> RenderPagesAsPng(this Document document, PrintOptions? printOptions = null, ScreenshotOptions? options = null)Parameters
documentDocumentprintOptionsPrintOptions?optionsScreenshotOptions?
Returns
IReadOnlyList<byte[]> The bytes of the PNG image of each page.
Exceptions
InvalidOperationException- The document is not rendered (it has no browsing context), or it is already being printed.