Class PdfPage
public class PdfPage : PdfObject, IDisposable
- Inheritance
-
PdfPage
- Implements
- Inherited Members
Properties
Height
Gets the height of the current PDF page in points.
public double Height { get; }
Property Value
Remarks
The height is retrieved directly from the underlying PDF page handle. The value is typically used for rendering or layout purposes.
HeightF
Gets the height of the current PDF page in points as a float.
public float HeightF { get; }
Property Value
Width
Gets the width of the current PDF page in points.
public double Width { get; }
Property Value
Remarks
The width is retrieved directly from the underlying PDF page handle. The value is typically used for rendering or layout purposes.
WidthF
Gets the width of the current PDF page in points as a float.
public float WidthF { get; }
Property Value
Methods
Close()
Closes the current page and releases the associated resources.
public void Close()
CreateAnnotation(PdfAnnotationSubtype)
Creates a new annotation of the specified subtype on the current PDF page.
public PdfAnnotation CreateAnnotation(PdfAnnotationSubtype subtype)
Parameters
subtype
PdfAnnotationSubtypeThe subtype of the annotation to create. This determines the type of annotation, such as a text note, highlight, or shape.
Returns
- PdfAnnotation
A PdfAnnotation object representing the newly created annotation.
Exceptions
- dotPDFiumException
Thrown if the annotation could not be created for the specified
subtype
.
DeviceToPage(int, int, int, int, PdfPageRotation, int, int, out double, out double)
Converts device (pixel) coordinates into page-space coordinates (points).
public void DeviceToPage(int startX, int startY, int width, int height, PdfPageRotation rotate, int deviceX, int deviceY, out double pageX, out double pageY)
Parameters
startX
intThe X position of the rendered area in device pixels (usually 0).
startY
intThe Y position of the rendered area in device pixels (usually 0).
width
intThe width of the rendered area in pixels (matches the bitmap width).
height
intThe height of the rendered area in pixels (matches the bitmap height).
rotate
PdfPageRotationThe rotation of the page (0, 90, 180, 270 degrees). See PdfRotation enum. Do not swap width and height manually; PDFium handles this automatically.
deviceX
intThe device-space X coordinate (in pixels) to convert.
deviceY
intThe device-space Y coordinate (in pixels) to convert.
pageX
doubleOutput variable for the resulting X coordinate in page-space points.
pageY
doubleOutput variable for the resulting Y coordinate in page-space points.
Exceptions
- ObjectDisposedException
Thrown if the page has been disposed.
Dispose(bool)
Releases the resources used by the page, optionally unregistering it from the parent document.
protected override void Dispose(bool disposing)
Parameters
disposing
booltrue to release both managed and unmanaged resources; false to release only unmanaged resources.
Remarks
When disposing
is true, this method unregisters
the page from its parent document, if applicable. Ensure that this method is called to properly clean up
resources associated with the page.
EnumerateLinks()
Enumerates all link annotations on the current PDF page.
public IEnumerable<PdfLinkAnnotation> EnumerateLinks()
Returns
- IEnumerable<PdfLinkAnnotation>
An IEnumerable<T> of PdfLinkAnnotation objects representing the link annotations found on the page. The enumeration will be empty if no link annotations are present.
Remarks
This method lazily enumerates the link annotations on the page. Each PdfLinkAnnotation object represents a single link annotation and provides access to its properties and behaviors.
FinalizeContent()
Finalizes the content of the current page. This method should be called after all modifications to the page are complete.
public void FinalizeContent()
Exceptions
- dotPDFiumException
Throws on PDFium library error
FindLinkAtPoint(double, double)
Finds a link annotation at the specified point on the PDF page.
public PdfLinkAnnotation? FindLinkAtPoint(double x, double y)
Parameters
x
doubleThe x-coordinate of the point, in the coordinate system of the PDF page.
y
doubleThe y-coordinate of the point, in the coordinate system of the PDF page.
Returns
- PdfLinkAnnotation
A PdfLinkAnnotation object representing the link annotation at the specified point, or null if no link annotation is found.
Flatten(PdfFlattenMode)
Flattens the PDF page content into a single layer, making annotations and form fields part of the page content.
public PdfFlattenResult Flatten(PdfFlattenMode mode = PdfFlattenMode.NormalDisplay)
Parameters
mode
PdfFlattenModeThe flattening mode that determines how the content is rendered. Defaults to NormalDisplay.
Returns
- PdfFlattenResult
A PdfFlattenResult indicating the result of the flattening operation: Success if the operation was successful, NothingToDo if there was no content to flatten, or Fail if the operation failed.
Remarks
Flattening a PDF page can be useful for ensuring that annotations and form fields are no longer interactive and are instead rendered as part of the static page content. This operation is typically irreversible.
GetAnnotation(int)
Retrieves the annotation at the specified index on the PDF page.
public PdfAnnotation GetAnnotation(int index)
Parameters
index
intThe zero-based index of the annotation to retrieve. Must be within the range of available annotations on the page.
Returns
- PdfAnnotation
A PdfAnnotation object representing the annotation at the specified index.
Exceptions
- dotPDFiumException
Thrown if the annotation at the specified
index
cannot be retrieved.
GetAnnotationCount()
Gets the total number of annotations on the current PDF page.
public int GetAnnotationCount()
Returns
- int
The number of annotations on the page. Returns 0 if the page has no annotations.
Remarks
This method retrieves the count of annotations present on the PDF page represented by this instance.
GetAnnotationIndex(PdfAnnotation)
Retrieves the index of the specified annotation within the PDF page.
public int GetAnnotationIndex(PdfAnnotation annotation)
Parameters
annotation
PdfAnnotationThe annotation whose index is to be retrieved. Must not be
null
.
Returns
- int
The zero-based index of the annotation within the page.
Exceptions
- dotPDFiumException
Thrown if the annotation cannot be located on the page.
GetArtBox()
Retrieves the ArtBox of the current PDF page.
public FsRectF GetArtBox()
Returns
- FsRectF
A FsRectF structure representing the ArtBox of the page. The rectangle's coordinates are in user space units.
Remarks
The ArtBox defines the extent of the page's meaningful content as intended by the creator. This method returns the rectangle that represents the ArtBox in user space coordinates.
GetBleedBox()
Retrieves the bleed box of the page, which defines the region to which the page's content should be clipped when printed.
public FsRectF GetBleedBox()
Returns
- FsRectF
An FsRectF structure representing the bleed box of the page. The bleed box is defined in the page's coordinate system.
Remarks
The bleed box is typically used in printing workflows to account for content that extends beyond the trim box, such as bleeds.
GetBoundingBox()
Retrieves the bounding box of the current PDF page.
public FsRectF GetBoundingBox()
Returns
Exceptions
- ObjectDisposedException
Thrown if the PDF page has been disposed.
- dotPDFiumException
Thrown if the bounding box could not be retrieved.
GetCropBox()
Retrieves the crop box of the current page.
public FsRectF GetCropBox()
Returns
- FsRectF
A FsRectF structure representing the crop box of the page. The crop box defines the visible area of the page in user space coordinates.
GetDecodedThumbnailData()
Retrieves the decoded thumbnail image data for the current PDF page.
public byte[] GetDecodedThumbnailData()
Returns
- byte[]
A byte array containing the decoded thumbnail image data. Returns an empty array if no thumbnail data is available.
Remarks
The returned byte array represents the raw image data of the thumbnail. Callers can process this data further as needed, such as converting it into an image format.
GetLinkAnnotation(int)
Retrieves the link annotation at the specified index as a PdfAnnotation, if it exists.
public PdfAnnotation? GetLinkAnnotation(int linkIndex)
Parameters
linkIndex
intThe zero-based index of the link annotation.
Returns
- PdfAnnotation
The corresponding PdfAnnotation or
null
if not found.
GetLinkZOrderAtPoint(double, double)
Gets the z-order index of a link at the specified point on the page.
public int GetLinkZOrderAtPoint(double x, double y)
Parameters
x
doubleThe x-coordinate of the point, in the page's coordinate system.
y
doubleThe y-coordinate of the point, in the page's coordinate system.
Returns
- int
The zero-based z-order index of the link at the specified point, where a lower index indicates a link closer to the top of the z-order. Returns -1 if no link is found at the specified point.
Remarks
The z-order index determines the stacking order of links at a given point, with lower indices representing links that are visually on top. This method can be used to identify and interact with specific links in a document.
GetMediaBox()
Retrieves the MediaBox of the current PDF page.
public FsRectF GetMediaBox()
Returns
- FsRectF
An FsRectF structure representing the MediaBox of the page. The MediaBox defines the boundaries of the physical medium on which the page is intended to be displayed or printed.
Remarks
The MediaBox is the default boundary for the page content in a PDF document. It specifies the dimensions of the page in user space units.
GetObject(int)
Gets the object at the specified index on the current page.
public PdfPageObject GetObject(int index)
Parameters
index
intThe index of the object to retrieve
Returns
- PdfPageObject
The object at the specified index
Exceptions
- dotPDFiumException
Throws on PDFium library error
GetObjectCount()
Gets the number of objects on the current page.
public int GetObjectCount()
Returns
GetOrLoadText()
Gets the text content of the current PDF page if it is already loaded, otherwise loads it.
public PdfPageText GetOrLoadText()
Returns
Exceptions
- ObjectDisposedException
Throws if the page has been disposed
- dotPDFiumException
Throws on PDFium library error
GetRawThumbnailData()
Retrieves the raw thumbnail data for the current PDF page.
public byte[] GetRawThumbnailData()
Returns
- byte[]
A byte array containing the raw thumbnail data of the PDF page. Returns an empty array if no thumbnail data is available.
Remarks
The raw thumbnail data can be used for further processing or rendering. The caller is responsible for interpreting the data appropriately.
GetRotation()
Gets the rotation of the current PDF page.
public PdfPageRotation GetRotation()
Returns
- PdfPageRotation
A PdfPageRotation value representing the rotation of the page.
Exceptions
- dotPDFiumException
Thrown if the rotation value retrieved from the native PDF library is invalid.
GetStructTree()
Gets the logical structure tree for this page, if one exists.
public PdfStructTree? GetStructTree()
Returns
- PdfStructTree
A PdfStructTree, or
null
if the page has no tagged content.
GetThumbnailBitmap()
Retrieves the thumbnail image of the current PDF page as a PdfBitmap object.
public PdfBitmap? GetThumbnailBitmap()
Returns
- PdfBitmap
A PdfBitmap representing the thumbnail image of the current PDF page, or null if no thumbnail is available.
Remarks
The returned PdfBitmap contains the thumbnail image of the current PDF page, with its dimensions estimated based on the bitmap's stride and format. If the thumbnail cannot be retrieved, the method returns null.
Exceptions
- dotPDFiumException
Thrown if the thumbnail image is in an unsupported format.
GetTrimBox()
Retrieves the trim box of the current page.
public FsRectF GetTrimBox()
Returns
- FsRectF
An FsRectF structure representing the trim box of the page. The trim box defines the intended dimensions of the page's content after trimming.
HasTransparency()
Determines whether the PDF page contains any transparent elements.
public bool HasTransparency()
Returns
Remarks
This method checks for the presence of transparency on the PDF page, which may affect rendering or printing.
InsertObject(PdfPageObject)
Insert a PDF page object into the current page.
public void InsertObject(PdfPageObject obj)
Parameters
obj
PdfPageObjectThe PdfObject to insert into the page
Exceptions
- ArgumentNullException
Throws if obj is null
PageToDevice(int, int, int, int, PdfPageRotation, double, double, out int, out int)
Converts a point from page coordinates (points) to device coordinates (pixels).
public void PageToDevice(int startX, int startY, int width, int height, PdfPageRotation rotate, double pageX, double pageY, out int deviceX, out int deviceY)
Parameters
startX
intThe X offset in device pixels where the page rendering starts (usually 0).
startY
intThe Y offset in device pixels where the page rendering starts (usually 0).
width
intThe width of the rendered area in device pixels (e.g., the bitmap width).
height
intThe height of the rendered area in device pixels (e.g., the bitmap height).
rotate
PdfPageRotationpageX
doubleThe X coordinate in page space (points, where 1 point = 1/72 inch).
pageY
doubleThe Y coordinate in page space (points).
deviceX
intOutput parameter receiving the corresponding X coordinate in device space (pixels).
deviceY
intOutput parameter receiving the corresponding Y coordinate in device space (pixels).
Exceptions
- ObjectDisposedException
Thrown if the page has been disposed.
RemoveAnnotation(PdfAnnotation)
Removes the specified annotation from the PDF page.
public void RemoveAnnotation(PdfAnnotation annotation)
Parameters
annotation
PdfAnnotationThe annotation to remove from the page. This parameter cannot be null.
Remarks
Use this method to delete an annotation from the current PDF page. Ensure that the annotation is valid and associated with this page before calling this method.
Exceptions
- dotPDFiumException
Thrown if the annotation could not be removed from the page.
RemoveObject(PdfPageObject)
Removes the specified PDF page object from the current page.
public void RemoveObject(PdfPageObject obj)
Parameters
obj
PdfPageObjectThe PdfPageObject to remove. This parameter cannot be null.
Exceptions
- dotPDFiumException
Thrown if the removal operation fails due to an error in the underlying PDF library.
RenderToBitmap(PdfBitmap, int, int, int, int, PdfPageRotation, PdfRenderFlags)
This method renders the current PDF page to a bitmap.
public void RenderToBitmap(PdfBitmap bitmap, int startX, int startY, int width, int height, PdfPageRotation rotate = PdfPageRotation.NoRotation, PdfRenderFlags flags = PdfRenderFlags.None)
Parameters
bitmap
PdfBitmapThe bitmap to render the page to
startX
intThe starting x coordinate in pixels
startY
intThe starting y coordinate in pixels
width
intThe width of the bitmap to render in pixels
height
intThe height of the bitmap to render in pixels
rotate
PdfPageRotationThe rotation of the page (see PdfRotation enum)
flags
PdfRenderFlagsSee PdfRenderFlags
Exceptions
RenderToBitmapWithMatrix(PdfBitmap, ref FsMatrixF, ref FsRectF, PdfRenderFlags)
Renders the current PDF page to a bitmap using a transformation matrix and clipping rectangle.
public void RenderToBitmapWithMatrix(PdfBitmap bitmap, ref FsMatrixF transform, ref FsRectF clip, PdfRenderFlags flags = PdfRenderFlags.None)
Parameters
bitmap
PdfBitmapThe bitmap to render to
transform
FsMatrixFThe transform matrix for the page
clip
FsRectFThe clipping rectangle for the page
flags
PdfRenderFlagsFlags - see PdfRenderFlags
Exceptions
- ObjectDisposedException
Thrown if the PDF page has already been disposed
- ArgumentNullException
Thrown if the PDF bitmap is null
SetArtBox(FsRectF)
Sets the ArtBox for the current page.
public void SetArtBox(FsRectF box)
Parameters
box
FsRectFThe FsRectF structure defining the ArtBox dimensions. The coordinates must be specified in the page's coordinate system.
Remarks
The ArtBox defines the extent of the page's meaningful content, excluding any
additional elements such as bleed or trim areas. Ensure that the specified box
is valid
and within the page's boundaries.
SetBleedBox(FsRectF)
Sets the bleed box for the current page.
public void SetBleedBox(FsRectF box)
Parameters
box
FsRectFThe FsRectF structure representing the bleed box dimensions. The bleed box defines the region to which the page content should extend, typically used for printing purposes.
Remarks
The bleed box is used to ensure that content intended to extend to the edge of the
page is printed correctly, even if the page is trimmed. Ensure that the box
parameter
specifies valid dimensions within the page boundaries.
SetCropBox(FsRectF)
Sets the crop box for the current page.
public void SetCropBox(FsRectF box)
Parameters
box
FsRectFThe FsRectF structure defining the crop box dimensions. The coordinates are specified in points, with the origin at the bottom-left corner of the page.
Remarks
The crop box defines the visible area of the page when displayed or printed. Any content outside the crop box will be clipped.
SetMediaBox(FsRectF)
Sets the MediaBox for the current page.
public void SetMediaBox(FsRectF box)
Parameters
box
FsRectFThe FsRectF structure representing the new MediaBox dimensions. The coordinates must be specified in points and follow the PDF coordinate system.
Remarks
The MediaBox defines the boundaries of the physical medium on which the page is
intended to be displayed or printed. Ensure that the provided box
is valid and within the
acceptable range for the page.
SetRotation(PdfPageRotation)
Sets the rotation of the current PDF page.
public void SetRotation(PdfPageRotation rotation)
Parameters
rotation
PdfPageRotationThe desired rotation for the page, specified as a PdfPageRotation value.
Remarks
This method updates the rotation of the page to the specified value. The rotation is applied in 90-degree increments, as defined by the PdfPageRotation enumeration.
SetTrimBox(FsRectF)
Sets the trim box for the current page.
public void SetTrimBox(FsRectF box)
Parameters
box
FsRectFThe FsRectF structure representing the trim box dimensions. The trim box defines the intended visible area of the page after trimming.
Remarks
The trim box is typically used to specify the final dimensions of the page after any
trimming or cutting operations. Ensure that the provided box
dimensions are valid and
within the bounds of the page.
TransformAnnotations(FsMatrix)
Applies a transformation matrix to all annotations on the current PDF page.
public void TransformAnnotations(FsMatrix matrix)
Parameters
matrix
FsMatrixThe transformation matrix to apply. Each element of the matrix represents a specific transformation component (e.g., scaling, rotation, translation).
Remarks
This method modifies the appearance and positioning of annotations on the page by applying the specified transformation matrix. The transformation is applied directly to the annotations and does not affect the page content itself.
TransformWithClip(FsMatrixF, FsRectF)
Applies a transformation matrix and a clipping rectangle to the current page.
public void TransformWithClip(FsMatrixF matrix, FsRectF clip)
Parameters
matrix
FsMatrixFThe transformation matrix to apply to the page. This defines how the page content is scaled, rotated, or translated.
clip
FsRectFThe clipping rectangle that limits the visible area of the page after the transformation is applied.
Exceptions
- dotPDFiumException
Thrown if the transformation or clipping operation fails.
TryGetOrLoadText(out PdfPageText?)
Gets the text content of the current PDF page if it is already loaded, otherwise loads it.
public bool TryGetOrLoadText(out PdfPageText? pdfText)
Parameters
pdfText
PdfPageTextOut parameter for receiving the PdfText object
Returns
- bool
true on success, false on failure