PdfRenderer Class

Renders the pages of a document to images (ISO 32000-2, 8 to 12).

public static class PdfRenderer

Remarks

The page is drawn with the canvas of Meziantou.Framework.Imaging, in sRGB: the paths with antialiasing, the text with the outlines of its embedded fonts (TrueType, CFF, Type 1) or of the fonts that replace the fonts it does not embed, the images of every filter and color space with their masks, the shadings and patterns, the transparency groups, soft masks and blend modes, the optional content of a configuration, and the appearances of the annotations (generated for the annotations that have none).

A damaged content is drawn up to the operator that is damaged, as viewers do: an operator whose operands or resources are invalid is skipped, and a font, image or shading that cannot be read is not drawn.

Each call reads the resources of the page again; PdfRenderSession renders the pages of a document with caches they share.

Methods

NameDescription
GetImageSize(PdfPage, PdfRenderOptions?)Gets the size of the image PdfRenderer.RenderPage renders a page to: the crop box (or the region of the options) at their resolution or size, rotated by the /Rotate of the page.
Render(PdfPage, PdfRenderOptions?)Renders a page to an image.
RenderPage(PdfPage, Image, PdfRenderOptions?, CancellationToken)Renders a page to an image of the application, whatever its pixel format (a Gray8 image gives a grayscale rendering, for instance): the page is drawn from the top left corner of the image, at the size PdfRenderer.GetImageSize gives. The background of the options is painted first, over the pixels of the image: set it to null to draw the page over what the image shows.
RenderPage(PdfPage, PdfRenderOptions?)Renders a page to an image.
RenderPage(PdfPage, PdfRenderOptions?, CancellationToken)Renders a page to an image.

GetImageSize(PdfPage, PdfRenderOptions?)

PdfRenderer.cs

Gets the size of the image PdfRenderer.RenderPage renders a page to: the crop box (or the region of the options) at their resolution or size, rotated by the /Rotate of the page.

public static Size GetImageSize(PdfPage page, PdfRenderOptions? options = null)

Parameters

page PdfPage
The page.
options PdfRenderOptions?
The options; null for PdfRenderOptions.Default.

Returns

Size The width and height of the image, in pixels.

Exceptions

PdfResourceLimitException
The page is too large at the resolution.

Render(PdfPage, PdfRenderOptions?)

PdfRenderer.cs

Renders a page to an image.

public static Image<Rgba32> Render(this PdfPage page, PdfRenderOptions? options = null)

Parameters

page PdfPage
The page.
options PdfRenderOptions?
The options; null for PdfRenderOptions.Default.

Returns

Image<Rgba32> The image.

Exceptions

PdfResourceLimitException
The page is too large at the resolution, or it does more work than PdfRenderOptions.MaxOperations.

RenderPage overloads

RenderPage(PdfPage, Image, PdfRenderOptions?, CancellationToken)

PdfRenderer.cs

Renders a page to an image of the application, whatever its pixel format (a Gray8 image gives a grayscale rendering, for instance): the page is drawn from the top left corner of the image, at the size PdfRenderer.GetImageSize gives. The background of the options is painted first, over the pixels of the image: set it to null to draw the page over what the image shows.

public static void RenderPage(PdfPage page, Image target, PdfRenderOptions? options = null, CancellationToken cancellationToken = default)
Parameters
page PdfPage
The page.
target Image
The image the page is drawn on: every frame of it. What exceeds it is not drawn.
options PdfRenderOptions?
The options; null for PdfRenderOptions.Default. Their PdfRenderOptions.Configuration is not used: the image has its own.
cancellationToken CancellationToken
The token to monitor for cancellation requests. The shapes already drawn stay on the image.
Exceptions
PdfResourceLimitException
The page is too large at the resolution, or it does more work than PdfRenderOptions.MaxOperations.
OperationCanceledException
The rendering was canceled.

RenderPage(PdfPage, PdfRenderOptions?)

PdfRenderer.cs

Renders a page to an image.

public static Image<Rgba32> RenderPage(PdfPage page, PdfRenderOptions? options = null)
Parameters
page PdfPage
The page.
options PdfRenderOptions?
The options; null for PdfRenderOptions.Default.
Returns

Image<Rgba32> The image: the crop box of the page (or the region of the options) at the resolution of the options, rotated by the /Rotate of the page.

Exceptions
PdfResourceLimitException
The page is too large at the resolution, or it does more work than PdfRenderOptions.MaxOperations.

RenderPage(PdfPage, PdfRenderOptions?, CancellationToken)

PdfRenderer.cs

Renders a page to an image.

public static Image<Rgba32> RenderPage(PdfPage page, PdfRenderOptions? options, CancellationToken cancellationToken)
Parameters
page PdfPage
The page.
options PdfRenderOptions?
The options; null for PdfRenderOptions.Default.
cancellationToken CancellationToken
The token to monitor for cancellation requests: it is checked as the operators, glyphs, images and shadings of the page are drawn.
Returns

Image<Rgba32> The image: the crop box of the page (or the region of the options) at the resolution of the options, rotated by the /Rotate of the page.

Exceptions
PdfResourceLimitException
The page is too large at the resolution, or it does more work than PdfRenderOptions.MaxOperations.
OperationCanceledException
The rendering was canceled.