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 : IDisposableRemarks
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
| Name | Description |
|---|---|
| PdfRenderSession(PdfDocument, PdfRenderOptions?) | Initializes a new instance of the PdfRenderSession class. |
PdfRenderSession(PdfDocument, PdfRenderOptions?)
PdfRenderSession.csInitializes a new instance of the PdfRenderSession class.
public PdfRenderSession(PdfDocument document, PdfRenderOptions? options = null)Parameters
documentPdfDocument- The document whose pages are rendered.
optionsPdfRenderOptions?- The options;
nullforPdfRenderOptions.Default.
Properties
| Name | Description |
|---|---|
| Document | Gets the document whose pages are rendered. |
| Options | Gets the options of the rendering. |
Document
PdfRenderSession.csOptions
PdfRenderSession.csMethods
| Name | Description |
|---|---|
| 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. |
Dispose()
PdfRenderSession.csReleases the objects the caches keep.
public void Dispose()RenderPage overloads
RenderPage(PdfPage)
PdfRenderSession.csRenders a page of the document to an image.
Parameters
pagePdfPage- 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.csRenders 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
pagePdfPage- The page, a page of
PdfRenderSession.Document. targetImage- The image the page is drawn on: every frame of it. What exceeds it is not drawn.
cancellationTokenCancellationToken- 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.csRenders a page of the document to an image.
public Image<Rgba32> RenderPage(PdfPage page, CancellationToken cancellationToken)Parameters
pagePdfPage- The page, a page of
PdfRenderSession.Document. cancellationTokenCancellationToken- 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.