PdfRenderSession Class

Renders the pages of a document with caches the pages share: the fonts, images, color spaces, functions, glyph procedures and meshes a page reads are kept for the next pages, so that the resources several pages use are read and decoded once.

public sealed class PdfRenderSession : IDisposable

Remarks

The work each page may do is counted separately (PdfRenderOptions.MaxOperations): an image decoded for a page is not decoded, nor charged, again for the next ones. The caches are emptied between two pages when what they keep exceeds about 256 MB, and when the session is disposed of.

The caches are found by the objects of the document: a change made to an object of the document after a page that uses it is rendered (the data of a stream, an entry of a dictionary) may not be seen by the next pages. Create a new session after changing the document. A session renders one page at a time: it must not be used by several threads at once.

Implements

Constructors

NameDescription
PdfRenderSession(PdfDocument, PdfRenderOptions?)Initializes a new instance of the PdfRenderSession class.

PdfRenderSession(PdfDocument, PdfRenderOptions?)

PdfRenderSession.cs

Initializes a new instance of the PdfRenderSession class.

public PdfRenderSession(PdfDocument document, PdfRenderOptions? options = null)

Parameters

document PdfDocument
The document whose pages are rendered.
options PdfRenderOptions?
The options; null for PdfRenderOptions.Default.

Properties

NameDescription
DocumentGets the document whose pages are rendered.
OptionsGets the options of the rendering.

Gets the document whose pages are rendered.

public PdfDocument Document { get; }

Property value

PdfDocument

Gets the options of the rendering.

public PdfRenderOptions Options { get; }

Property value

PdfRenderOptions

Methods

NameDescription
Dispose()Releases the objects the caches keep.
RenderPage(PdfPage)Renders a page of the document to an image.
RenderPage(PdfPage, Image, CancellationToken)Renders a page of the document 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, CancellationToken)Renders a page of the document to an image.

Releases the objects the caches keep.

public void Dispose()

RenderPage overloads

RenderPage(PdfPage)

PdfRenderSession.cs

Renders a page of the document to an image.

public Image<Rgba32> RenderPage(PdfPage page)
Parameters
page PdfPage
The page, a page of PdfRenderSession.Document.
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
ArgumentException
The page is not a page of PdfRenderSession.Document.
ObjectDisposedException
The session is disposed of.
PdfResourceLimitException
The page is too large at the resolution, or it does more work than PdfRenderOptions.MaxOperations.

RenderPage(PdfPage, Image, CancellationToken)

PdfRenderSession.cs

Renders a page of the document 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 void RenderPage(PdfPage page, Image target, CancellationToken cancellationToken = default)
Parameters
page PdfPage
The page, a page of PdfRenderSession.Document.
target Image
The image the page is drawn on: every frame of it. What exceeds it is not drawn.
cancellationToken CancellationToken
The token to monitor for cancellation requests. The shapes already drawn stay on the image.
Exceptions
ArgumentException
The page is not a page of PdfRenderSession.Document.
ObjectDisposedException
The session is disposed of.
PdfResourceLimitException
The page is too large at the resolution, or it does more work than PdfRenderOptions.MaxOperations.
OperationCanceledException
The rendering was canceled.

RenderPage(PdfPage, CancellationToken)

PdfRenderSession.cs

Renders a page of the document to an image.

public Image<Rgba32> RenderPage(PdfPage page, CancellationToken cancellationToken)
Parameters
page PdfPage
The page, a page of PdfRenderSession.Document.
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
ArgumentException
The page is not a page of PdfRenderSession.Document.
ObjectDisposedException
The session is disposed of.
PdfResourceLimitException
The page is too large at the resolution, or it does more work than PdfRenderOptions.MaxOperations.
OperationCanceledException
The rendering was canceled.