PdfPage Class
A page of a document (ISO 32000-2, 7.7.3.3). The members read and write the page dictionary; the inheritable entries are looked up in the page tree.
public sealed class PdfPageProperties
| Name | Description |
|---|---|
| Annotations | Gets the annotations of the page (ISO 32000-2, 12.5). |
| ArtBox | Gets or sets the art box (ISO 32000-2, 14.11.2): the extent of the meaningful content of the page. It is not inherited; the default is the crop box. |
| BleedBox | Gets or sets the bleed box (ISO 32000-2, 14.11.2): the region the content is clipped to in a production environment, which includes the bleed area of the trimmed page. It is not inherited; the default is the crop box. |
| CropBox | Gets or sets the crop box: the region of the page that is displayed or printed. It is inherited from the page tree; the default is the media box. |
| Dictionary | Gets the page dictionary. |
| DisplaySize | Gets the size of the page as it is displayed, in 1/72 inch: the visible region (the crop box clipped to the media box) rotated by PdfPage.Rotation and scaled by PdfPage.UserUnit. |
| DisplayToUserSpace | Gets the matrix from the display space of the page to its default user space. In the display space, the origin is the lower-left corner of the page as it is displayed (cropped and rotated), x increases to the right, y upward, and the unit is 1/72 inch. |
| Document | Gets the document of the page. |
| Label | Gets the label of the page (ISO 32000-2, 12.4.2), such as iii or A-2, or null when the document has no page labels or the page is not in it. |
| MediaBox | Gets or sets the media box: the boundaries of the medium the page is printed on. It is inherited from the page tree; the default is US Letter. |
| Reference | Gets the reference to the page object. |
| Resources | Gets the resource dictionary of the page, inherited from the page tree, or null when there is none. |
| Rotation | Gets or sets the clockwise rotation of the page when it is displayed: 0, 90, 180 or 270 degrees. It is inherited from the page tree. |
| TrimBox | Gets or sets the trim box (ISO 32000-2, 14.11.2): the intended dimensions of the finished page after trimming. It is not inherited; the default is the crop box. |
| UserSpaceToDisplay | Gets the matrix from the default user space of the page to its display space: the inverse of PdfPage.DisplayToUserSpace. |
| UserUnit | Gets the size of the user space unit in 1/72 inch (ISO 32000-2, 14.11.2). The default is 1, which is also the value of a page whose /UserUnit is not a positive number. |
Annotations
PdfPage.csGets the annotations of the page (ISO 32000-2, 12.5).
public PdfAnnotationCollection Annotations { get; }Property value
ArtBox
PdfPage.csGets or sets the art box (ISO 32000-2, 14.11.2): the extent of the meaningful content of the page. It is not inherited; the default is the crop box.
public PdfRectangle ArtBox { get; set; }BleedBox
PdfPage.csGets or sets the bleed box (ISO 32000-2, 14.11.2): the region the content is clipped to in a production environment, which includes the bleed area of the trimmed page. It is not inherited; the default is the crop box.
public PdfRectangle BleedBox { get; set; }CropBox
PdfPage.csGets or sets the crop box: the region of the page that is displayed or printed. It is inherited from the page tree; the default is the media box.
public PdfRectangle CropBox { get; set; }Dictionary
PdfPage.csDisplaySize
PdfPage.csGets the size of the page as it is displayed, in 1/72 inch: the visible region (the crop box clipped to the media box) rotated by PdfPage.Rotation and scaled by PdfPage.UserUnit.
public PdfSize DisplaySize { get; }Property value
DisplayToUserSpace
PdfPage.csGets the matrix from the display space of the page to its default user space. In the display space, the origin is the lower-left corner of the page as it is displayed (cropped and rotated), x increases to the right, y upward, and the unit is 1/72 inch.
public PdfMatrix DisplayToUserSpace { get; }Property value
Remarks
Concatenate it to the transformation matrix (PdfContentBuilder.Transform) to draw on a rotated or cropped page as on an upright page of PdfPage.DisplaySize; transform the points of the display, such as the position of a click, with it to get the coordinates of the annotations.
Document
PdfPage.csLabel
PdfPage.csMediaBox
PdfPage.csGets or sets the media box: the boundaries of the medium the page is printed on. It is inherited from the page tree; the default is US Letter.
public PdfRectangle MediaBox { get; set; }Reference
PdfPage.csResources
PdfPage.csGets the resource dictionary of the page, inherited from the page tree, or null when there is none.
public PdfDictionary? Resources { get; }Property value
Rotation
PdfPage.csGets or sets the clockwise rotation of the page when it is displayed: 0, 90, 180 or 270 degrees. It is inherited from the page tree.
public int Rotation { get; set; }TrimBox
PdfPage.csGets or sets the trim box (ISO 32000-2, 14.11.2): the intended dimensions of the finished page after trimming. It is not inherited; the default is the crop box.
public PdfRectangle TrimBox { get; set; }UserSpaceToDisplay
PdfPage.csGets the matrix from the default user space of the page to its display space: the inverse of PdfPage.DisplayToUserSpace.
public PdfMatrix UserSpaceToDisplay { get; }Property value
UserUnit
PdfPage.csMethods
| Name | Description |
|---|---|
| CreateContentBuilder() | Creates a builder that appends a content stream to the page. When the page already has content, including the content of the builders created before, it is wrapped between q and Q first, so that the new content starts with the default graphics state. |
| ExtractText() | Extracts the text of the page, in the order of the content, with a line break between the lines. |
| ExtractText(PdfTextExtractionOptions?) | Extracts the text of the page, in the order of the content, with a line break between the lines. |
| ExtractTextLayout(PdfTextExtractionOptions?) | Extracts the text of the page with the position of its lines, words and glyphs, in the default user space of the page. |
| GetContentData() | Gets the content of the page: its content streams decoded and joined (ISO 32000-2, 7.8.2). |
| GetImages() | Gets the images the content of the page paints (ISO 32000-2, 8.9): the image XObjects, painted by the content or by the forms it paints, and the inline images, in the order they are painted, with the matrix they are painted with. The images of the annotations, of the patterns and of the soft masks are not included. |
CreateContentBuilder()
PdfPage.csCreates a builder that appends a content stream to the page. When the page already has content, including the content of the builders created before, it is wrapped between q and Q first, so that the new content starts with the default graphics state.
public PdfContentBuilder CreateContentBuilder()Returns
PdfContentBuilder The builder.
Remarks
The isolation relies on the content of each builder being balanced: call PdfContentBuilder.Complete to check it. The resources the builder adds go to a resource dictionary of the page itself: the resources the page shares with other pages (an indirect dictionary, or a category of the page tree) are copied first, so that the other pages do not change.
ExtractText overloads
ExtractText()
PdfPage.csExtracts the text of the page, in the order of the content, with a line break between the lines.
public string ExtractText()Returns
string The text.
Exceptions
PdfResourceLimitException- The content runs more operators and glyphs than the limit (forms that paint forms).
ExtractText(PdfTextExtractionOptions?)
PdfPage.csExtracts the text of the page, in the order of the content, with a line break between the lines.
public string ExtractText(PdfTextExtractionOptions? options)Parameters
optionsPdfTextExtractionOptions?- The options, or
nullforPdfTextExtractionOptions.Default.
Returns
string The text.
Exceptions
PdfResourceLimitException- The content runs more operators and glyphs than the limit (forms that paint forms).
ExtractTextLayout(PdfTextExtractionOptions?)
PdfPage.csExtracts the text of the page with the position of its lines, words and glyphs, in the default user space of the page.
public PdfTextLayout ExtractTextLayout(PdfTextExtractionOptions? options = null)Parameters
optionsPdfTextExtractionOptions?- The options, or
nullforPdfTextExtractionOptions.Default.
Returns
PdfTextLayout The lines of the page; its PdfTextLayout.Text is the result of PdfPage.ExtractText.
Exceptions
PdfResourceLimitException- The content runs more operators and glyphs than the limit (forms that paint forms).
GetContentData()
PdfPage.csGets the content of the page: its content streams decoded and joined (ISO 32000-2, 7.8.2).
public byte[] GetContentData()Returns
byte[] The content.
GetImages()
PdfPage.csGets the images the content of the page paints (ISO 32000-2, 8.9): the image XObjects, painted by the content or by the forms it paints, and the inline images, in the order they are painted, with the matrix they are painted with. The images of the annotations, of the patterns and of the soft masks are not included.
public IReadOnlyList<PdfImageOccurrence> GetImages()Returns
IReadOnlyList<PdfImageOccurrence> The images.
Exceptions
InvalidPdfContentException- A content stream cannot be decoded.