Table of Contents

Class PdfPage

Namespace
PdfSharp.Pdf
Assembly
PdfSharp.dll

Represents a page in a PDF document.

public sealed class PdfPage : PdfDictionary, ICloneable, IEnumerable<KeyValuePair<string, PdfItem?>>, IEnumerable
Inheritance
PdfPage
Implements
Inherited Members

Constructors

PdfPage()

Initializes a new page. The page must be added to a document before it can be used. Depending on the IsMetric property of the current region the page size is set to A4 or Letter respectively. If this size is not appropriate it should be changed before any drawing operations are performed on the page.

public PdfPage()

PdfPage(PdfDocument)

Initializes a new instance of the PdfPage class.

public PdfPage(PdfDocument document)

Parameters

document PdfDocument

The document.

Properties

Annotations

Gets the annotations array of this page.

public PdfAnnotations Annotations { get; }

Property Value

PdfAnnotations

ArtBox

Gets or sets the art box.

public PdfRectangle ArtBox { get; set; }

Property Value

PdfRectangle

BleedBox

Gets or sets the bleed box.

public PdfRectangle BleedBox { get; set; }

Property Value

PdfRectangle

Contents

Gets the array of content streams of the page.

public PdfContents Contents { get; }

Property Value

PdfContents

CropBox

Gets or sets the crop box.

public PdfRectangle CropBox { get; set; }

Property Value

PdfRectangle

CustomValues

Gets or sets the custom values.

public PdfCustomValues CustomValues { get; set; }

Property Value

PdfCustomValues

HasAnnotations

Gets the annotations array of this page.

public bool HasAnnotations { get; }

Property Value

bool

Height

Gets or sets the height of the page. If orientation is Landscape, this function applies to the width.

public XUnit Height { get; set; }

Property Value

XUnit

MediaBox

Gets or sets the media box directly. XGraphics is not prepared to work with a media box with an origin other than (0,0).

public PdfRectangle MediaBox { get; set; }

Property Value

PdfRectangle

Orientation

Gets or sets the orientation of the page. The default value PageOrientation.Portrait. If an imported page has a /Rotate value that matches the formula 90 + n * 180 the orientation is set to PageOrientation.Landscape.

public PageOrientation Orientation { get; set; }

Property Value

PageOrientation

Resources

Gets the PdfResources object of this page.

public PdfResources Resources { get; }

Property Value

PdfResources

Rotate

Gets or sets the /Rotate entry of the PDF page. The value is the number of degrees by which the page should be rotated clockwise when displayed or printed. The value must be a multiple of 90. PDFsharp does not set this value, but for imported pages this value can be set and must be taken into account when adding graphic to such a page.

public int Rotate { get; set; }

Property Value

int

Size

Gets or sets one of the predefined standard sizes like.

public PageSize Size { get; set; }

Property Value

PageSize

Tag

Gets or sets a user defined object that contains arbitrary information associated with this PDF page. The tag is not used by PDFsharp.

public object? Tag { get; set; }

Property Value

object

TrimBox

Gets or sets the trim box.

public PdfRectangle TrimBox { get; set; }

Property Value

PdfRectangle

TrimMargins

Gets or sets the trim margins.

public TrimMargins TrimMargins { get; set; }

Property Value

TrimMargins

Width

Gets or sets the width of the page. If orientation is Landscape, this function applies to the height.

public XUnit Width { get; set; }

Property Value

XUnit

Methods

Adds an internal document link.

public PdfLinkAnnotation AddDocumentLink(PdfRectangle rect, int destinationPage, XPoint? point = null)

Parameters

rect PdfRectangle

The link area in default page coordinates.

destinationPage int

The destination page.

point XPoint?

The position in the destination page.

Returns

PdfLinkAnnotation

Adds an internal document link.

public PdfLinkAnnotation AddDocumentLink(PdfRectangle rect, string destinationName)

Parameters

rect PdfRectangle

The link area in default page coordinates.

destinationName string

The Named Destination’s name.

Returns

PdfLinkAnnotation

Adds an external document link.

public PdfLinkAnnotation AddDocumentLink(PdfRectangle rect, string documentPath, string destinationName, bool? newWindow = null)

Parameters

rect PdfRectangle

The link area in default page coordinates.

documentPath string

The path to the target document.

destinationName string

The Named Destination’s name in the target document.

newWindow bool?

True, if the destination document shall be opened in a new window. If not set, the viewer application should behave in accordance with the current user preference.

Returns

PdfLinkAnnotation

Adds an embedded document link.

public PdfLinkAnnotation AddEmbeddedDocumentLink(PdfRectangle rect, string destinationPath, bool? newWindow = null)

Parameters

rect PdfRectangle

The link area in default page coordinates.

destinationPath string

The path to the named destination through the embedded documents. The path is separated by '' and the last segment is the name of the named destination. The other segments describe the route from the current (root or embedded) document to the embedded document holding the destination. ".." references to the parent, other strings refer to a child with this name in the EmbeddedFiles name dictionary.

newWindow bool?

True, if the destination document shall be opened in a new window. If not set, the viewer application should behave in accordance with the current user preference.

Returns

PdfLinkAnnotation

Adds an external embedded document link.

public PdfLinkAnnotation AddEmbeddedDocumentLink(PdfRectangle rect, string documentPath, string destinationPath, bool? newWindow = null)

Parameters

rect PdfRectangle

The link area in default page coordinates.

documentPath string

The path to the target document.

destinationPath string

The path to the named destination through the embedded documents in the target document. The path is separated by '' and the last segment is the name of the named destination. The other segments describe the route from the root document to the embedded document. Each segment name refers to a child with this name in the EmbeddedFiles name dictionary.

newWindow bool?

True, if the destination document shall be opened in a new window. If not set, the viewer application should behave in accordance with the current user preference.

Returns

PdfLinkAnnotation

Adds a link to a file.

public PdfLinkAnnotation AddFileLink(PdfRectangle rect, string fileName)

Parameters

rect PdfRectangle

The rect.

fileName string

Name of the file.

Returns

PdfLinkAnnotation

Adds a link to the Web.

public PdfLinkAnnotation AddWebLink(PdfRectangle rect, string url)

Parameters

rect PdfRectangle

The rect.

url string

The URL.

Returns

PdfLinkAnnotation

Close()

Closes the page. A closed page cannot be modified anymore, and it is not possible to get an XGraphics object for a closed page. Closing a page is not required, but may save resources if the document has many pages.

public void Close()