Table of Contents

Class PdfPage

Namespace
MiPdf
Assembly
MiPdf.dll

A page of a PdfDocument.

public sealed class PdfPage : IResourceContainer
Inheritance
PdfPage
Implements
Inherited Members

Properties

Annotations

The annotations of the page.

public IReadOnlyList<PdfAnnotation> Annotations { get; }

Property Value

IReadOnlyList<PdfAnnotation>

ArtBox

The art box (extent of the meaningful content); the CropBox if not set (ISO 32000-1, 14.11.2). Not inherited. Whether the page defines it: page.Dictionary.ContainsKey(PdfName.ArtBox); remove it with page.Dictionary.Remove.

public PdfRectangle ArtBox { get; set; }

Property Value

PdfRectangle

BleedBox

The bleed box (clipping region for production output); the CropBox if not set (ISO 32000-1, 14.11.2). Not inherited. Whether the page defines it: page.Dictionary.ContainsKey(PdfName.BleedBox); remove it with page.Dictionary.Remove.

public PdfRectangle BleedBox { get; set; }

Property Value

PdfRectangle

CropBox

The crop box (visible region). Defaults to the media box.

public PdfRectangle CropBox { get; set; }

Property Value

PdfRectangle

Dictionary

The page dictionary.

public PdfDictionary Dictionary { get; }

Property Value

PdfDictionary

Document

The document the page belongs to.

public PdfDocument Document { get; }

Property Value

PdfDocument

Height

Displayed height in points (crop box, considering rotation).

public double Height { get; }

Property Value

double

MediaBox

The media box (physical page size). Defaults to US Letter if missing.

public PdfRectangle MediaBox { get; set; }

Property Value

PdfRectangle

Reference

The indirect reference of the page dictionary.

public PdfReference Reference { get; }

Property Value

PdfReference

Resources

The page's own resource dictionary. Inherited resources are copied into the page on first access, so that adding resources never affects other pages.

public PdfDictionary Resources { get; }

Property Value

PdfDictionary

Rotation

Page rotation in degrees (0, 90, 180 or 270), clockwise when displayed.

public int Rotation { get; set; }

Property Value

int

TrimBox

The trim box (intended size of the finished page); the CropBox if not set (ISO 32000-1, 14.11.2). Not inherited. Whether the page defines it: page.Dictionary.ContainsKey(PdfName.TrimBox); remove it with page.Dictionary.Remove.

public PdfRectangle TrimBox { get; set; }

Property Value

PdfRectangle

Width

Displayed width in points (crop box, considering rotation).

public double Width { get; }

Property Value

double

Methods

AddAnnotation(PdfDictionary)

Adds an annotation dictionary to the page and returns it.

public PdfAnnotation AddAnnotation(PdfDictionary annotation)

Parameters

annotation PdfDictionary

Returns

PdfAnnotation

AddEllipseAnnotation(PdfRectangle, PdfColor?, PdfColor?, double, AnnotationOptions?)

Adds an ellipse inscribed in rect (Circle annotation).

public PdfAnnotation AddEllipseAnnotation(PdfRectangle rect, PdfColor? stroke = null, PdfColor? fill = null, double lineWidth = 1, AnnotationOptions? options = null)

Parameters

rect PdfRectangle
stroke PdfColor?
fill PdfColor?
lineWidth double
options AnnotationOptions

Returns

PdfAnnotation

AddFileAttachmentAnnotation(double, double, string, byte[], string?, string?, AnnotationOptions?)

Adds a file attachment annotation (paperclip icon) at (x, y) with the embedded file.

public PdfAnnotation AddFileAttachmentAnnotation(double x, double y, string fileName, byte[] data, string? mimeType = null, string? description = null, AnnotationOptions? options = null)

Parameters

x double
y double
fileName string
data byte[]
mimeType string
description string
options AnnotationOptions

Returns

PdfAnnotation

AddFreeText(PdfRectangle, string, PdfFont?, double, PdfColor?, PdfColor?, PdfColor?, TextAlignment, AnnotationOptions?)

Adds a text box (FreeText annotation) displayed directly on the page.

public PdfAnnotation AddFreeText(PdfRectangle rect, string text, PdfFont? font = null, double fontSize = 10, PdfColor? textColor = null, PdfColor? border = null, PdfColor? background = null, TextAlignment alignment = TextAlignment.Left, AnnotationOptions? options = null)

Parameters

rect PdfRectangle
text string
font PdfFont
fontSize double
textColor PdfColor?
border PdfColor?
background PdfColor?
alignment TextAlignment
options AnnotationOptions

Returns

PdfAnnotation

AddImageStamp(PdfRectangle, PdfImage, AnnotationOptions?)

Adds an image stamp (e.g. a company seal or a scanned signature).

public PdfAnnotation AddImageStamp(PdfRectangle rect, PdfImage image, AnnotationOptions? options = null)

Parameters

rect PdfRectangle
image PdfImage
options AnnotationOptions

Returns

PdfAnnotation

AddInk(IEnumerable<IEnumerable<(double X, double Y)>>, PdfColor?, double, AnnotationOptions?)

Adds a freehand drawing (Ink annotation).

public PdfAnnotation AddInk(IEnumerable<IEnumerable<(double X, double Y)>> strokes, PdfColor? color = null, double lineWidth = 1.5, AnnotationOptions? options = null)

Parameters

strokes IEnumerable<IEnumerable<(double X, double Y)>>
color PdfColor?
lineWidth double
options AnnotationOptions

Returns

PdfAnnotation

AddLineAnnotation(double, double, double, double, PdfColor?, double, LineEnding, LineEnding, AnnotationOptions?)

Adds a line, optionally with arrow heads (Line annotation).

public PdfAnnotation AddLineAnnotation(double x1, double y1, double x2, double y2, PdfColor? color = null, double lineWidth = 1, LineEnding start = LineEnding.None, LineEnding end = LineEnding.None, AnnotationOptions? options = null)

Parameters

x1 double
y1 double
x2 double
y2 double
color PdfColor?
lineWidth double
start LineEnding
end LineEnding
options AnnotationOptions

Returns

PdfAnnotation

Adds a link to a page of this document (optionally to a vertical position).

public PdfAnnotation AddLink(PdfRectangle area, PdfPage target, double? top = null)

Parameters

area PdfRectangle
target PdfPage
top double?

Returns

PdfAnnotation

Adds a link to a web address.

public PdfAnnotation AddLink(PdfRectangle area, string uri)

Parameters

area PdfRectangle
uri string

Returns

PdfAnnotation

AddRectangleAnnotation(PdfRectangle, PdfColor?, PdfColor?, double, AnnotationOptions?)

Adds a rectangle (Square annotation).

public PdfAnnotation AddRectangleAnnotation(PdfRectangle rect, PdfColor? stroke = null, PdfColor? fill = null, double lineWidth = 1, AnnotationOptions? options = null)

Parameters

rect PdfRectangle
stroke PdfColor?
fill PdfColor?
lineWidth double
options AnnotationOptions

Returns

PdfAnnotation

AddResource(PdfName, PdfObject, string)

Adds resource to the resource category (e.g. /Font, /XObject) and returns its name. If the same indirect object is already registered, its existing name is returned.

public PdfName AddResource(PdfName category, PdfObject resource, string prefix)

Parameters

category PdfName
resource PdfObject
prefix string

Returns

PdfName

AddStamp(PdfRectangle, string, PdfColor?, AnnotationOptions?, PdfFont?)

Adds a rubber stamp with text (e.g. "GENEHMIGT", "ENTWURF") framed by a rounded rectangle.

public PdfAnnotation AddStamp(PdfRectangle rect, string text, PdfColor? color = null, AnnotationOptions? options = null, PdfFont? font = null)

Parameters

rect PdfRectangle
text string
color PdfColor?
options AnnotationOptions
font PdfFont

Returns

PdfAnnotation

Remarks

Pass an embedded font (PdfTrueTypeFont) for PDF/A or PDF/UA documents.

AddTextMarkup(TextMarkupType, IEnumerable<PdfRectangle>, PdfColor?, AnnotationOptions?)

Adds a text markup annotation (highlight, underline, strike-out, squiggly) over the given areas (e.g. from FindText(string, StringComparison)).

public PdfAnnotation AddTextMarkup(TextMarkupType type, IEnumerable<PdfRectangle> areas, PdfColor? color = null, AnnotationOptions? options = null)

Parameters

type TextMarkupType
areas IEnumerable<PdfRectangle>
color PdfColor?
options AnnotationOptions

Returns

PdfAnnotation

AddTextNote(double, double, string, string?, PdfColor?)

Adds a sticky note (text annotation) at the given position.

public PdfAnnotation AddTextNote(double x, double y, string text, string? author = null, PdfColor? color = null)

Parameters

x double
y double
text string
author string
color PdfColor?

Returns

PdfAnnotation

AddTextWatermark(string, PdfFont?, double, PdfColor?, double, double, bool)

Draws a text watermark centered on the visible page area. The angle is relative to the page as displayed, so the watermark looks the same on rotated pages.

public void AddTextWatermark(string text, PdfFont? font = null, double fontSize = 60, PdfColor? color = null, double opacity = 0.25, double angle = 45, bool behindContent = false)

Parameters

text string
font PdfFont
fontSize double
color PdfColor?
opacity double
angle double
behindContent bool

AppendContent(byte[], bool, bool)

Appends content drawn on top of the existing content. With isolate the existing content is wrapped in q ... Q so its graphics state cannot leak into the new content.

public void AppendContent(byte[] content, bool isolate = true, bool compress = true)

Parameters

content byte[]
isolate bool
compress bool

ExtractImages()

Images drawn on the page with their position (see PdfImageExtractor).

public IReadOnlyList<PdfExtractedImage> ExtractImages()

Returns

IReadOnlyList<PdfExtractedImage>

ExtractText(TextExtractionOptions?)

Extracts the text of the page in reading order. See PdfTextExtractor for positions.

public string ExtractText(TextExtractionOptions? options = null)

Parameters

options TextExtractionOptions

Returns

string

FindFreeSpaces(double, double, bool)

Rectangles of free (empty) space on the page that are at least minWidth x minHeight points (see FreeSpaceFinder).

public IReadOnlyList<PdfRectangle> FindFreeSpaces(double minWidth, double minHeight, bool includeAnnotations = true)

Parameters

minWidth double
minHeight double
includeAnnotations bool

Returns

IReadOnlyList<PdfRectangle>

FindText(string, StringComparison)

Finds occurrences of text and returns their bounding boxes.

public IReadOnlyList<PdfRectangle> FindText(string text, StringComparison comparison = StringComparison.Ordinal)

Parameters

text string
comparison StringComparison

Returns

IReadOnlyList<PdfRectangle>

FindText(Regex)

Returns the bounds of all regular expression matches on the page (matched per text line).

public IReadOnlyList<PdfRectangle> FindText(Regex pattern)

Parameters

pattern Regex

Returns

IReadOnlyList<PdfRectangle>

FlattenAnnotations(Func<PdfAnnotation, bool>?)

Draws the appearance of annotations into the page content and removes them (links and popups are removed without drawing). Form fields are not affected; use Flatten(IEnumerable<PdfFormField>?) for them.

public int FlattenAnnotations(Func<PdfAnnotation, bool>? filter = null)

Parameters

filter Func<PdfAnnotation, bool>

Returns

int

GetCanvas(bool)

Returns a canvas for drawing on this page. The drawing is added when the canvas is disposed. With background the content is placed below the existing page content.

public PdfCanvas GetCanvas(bool background = false)

Parameters

background bool

Returns

PdfCanvas

GetContentBytes()

Returns the decoded, concatenated content of the page.

public byte[] GetContentBytes()

Returns

byte[]

GetContentStreams()

The content streams of the page in order.

public IReadOnlyList<PdfStream> GetContentStreams()

Returns

IReadOnlyList<PdfStream>

GetInheritable(PdfName)

Returns an attribute, following the /Parent chain for inheritable attributes.

public PdfObject? GetInheritable(PdfName key)

Parameters

key PdfName

Returns

PdfObject

GetOrCreateAnnotations()

The annotations array of the page (created on demand).

public PdfArray GetOrCreateAnnotations()

Returns

PdfArray

HighlightText(string, PdfColor?, StringComparison, TextMarkupType, AnnotationOptions?)

Highlights all occurrences of text on the page; returns the created annotations.

public IReadOnlyList<PdfAnnotation> HighlightText(string text, PdfColor? color = null, StringComparison comparison = StringComparison.Ordinal, TextMarkupType type = TextMarkupType.Highlight, AnnotationOptions? options = null)

Parameters

text string
color PdfColor?
comparison StringComparison
type TextMarkupType
options AnnotationOptions

Returns

IReadOnlyList<PdfAnnotation>

MarkForRedaction(PdfRectangle, string?)

Marks an area for later redaction with ApplyRedactions(RedactionOptions?).

public PdfAnnotation MarkForRedaction(PdfRectangle area, string? overlayText = null)

Parameters

area PdfRectangle
overlayText string

Returns

PdfAnnotation

PrependContent(byte[], bool)

Prepends content drawn below the existing content (e.g. backgrounds, watermarks under text).

public void PrependContent(byte[] content, bool compress = true)

Parameters

content byte[]
compress bool

Redact(IEnumerable<PdfRectangle>, RedactionOptions?)

Removes all content inside areas and covers them (see PdfRedactor).

public RedactionResult Redact(IEnumerable<PdfRectangle> areas, RedactionOptions? options = null)

Parameters

areas IEnumerable<PdfRectangle>
options RedactionOptions

Returns

RedactionResult

RemoveAnnotation(PdfAnnotation)

Removes an annotation from the page.

public bool RemoveAnnotation(PdfAnnotation annotation)

Parameters

annotation PdfAnnotation

Returns

bool

SetContent(byte[], bool)

Replaces the page content with a single stream.

public void SetContent(byte[] content, bool compress = true)

Parameters

content byte[]
compress bool