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
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
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
CropBox
The crop box (visible region). Defaults to the media box.
public PdfRectangle CropBox { get; set; }
Property Value
Dictionary
The page dictionary.
public PdfDictionary Dictionary { get; }
Property Value
Document
The document the page belongs to.
public PdfDocument Document { get; }
Property Value
Height
Displayed height in points (crop box, considering rotation).
public double Height { get; }
Property Value
MediaBox
The media box (physical page size). Defaults to US Letter if missing.
public PdfRectangle MediaBox { get; set; }
Property Value
Reference
The indirect reference of the page dictionary.
public PdfReference Reference { get; }
Property Value
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
Rotation
Page rotation in degrees (0, 90, 180 or 270), clockwise when displayed.
public int Rotation { get; set; }
Property Value
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
Width
Displayed width in points (crop box, considering rotation).
public double Width { get; }
Property Value
Methods
AddAnnotation(PdfDictionary)
Adds an annotation dictionary to the page and returns it.
public PdfAnnotation AddAnnotation(PdfDictionary annotation)
Parameters
annotationPdfDictionary
Returns
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
rectPdfRectanglestrokePdfColor?fillPdfColor?lineWidthdoubleoptionsAnnotationOptions
Returns
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
xdoubleydoublefileNamestringdatabyte[]mimeTypestringdescriptionstringoptionsAnnotationOptions
Returns
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
rectPdfRectangletextstringfontPdfFontfontSizedoubletextColorPdfColor?borderPdfColor?backgroundPdfColor?alignmentTextAlignmentoptionsAnnotationOptions
Returns
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
rectPdfRectangleimagePdfImageoptionsAnnotationOptions
Returns
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
strokesIEnumerable<IEnumerable<(double X, double Y)>>colorPdfColor?lineWidthdoubleoptionsAnnotationOptions
Returns
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
x1doubley1doublex2doubley2doublecolorPdfColor?lineWidthdoublestartLineEndingendLineEndingoptionsAnnotationOptions
Returns
AddLink(PdfRectangle, PdfPage, double?)
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
areaPdfRectangletargetPdfPagetopdouble?
Returns
AddLink(PdfRectangle, string)
Adds a link to a web address.
public PdfAnnotation AddLink(PdfRectangle area, string uri)
Parameters
areaPdfRectangleuristring
Returns
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
rectPdfRectanglestrokePdfColor?fillPdfColor?lineWidthdoubleoptionsAnnotationOptions
Returns
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
Returns
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
rectPdfRectangletextstringcolorPdfColor?optionsAnnotationOptionsfontPdfFont
Returns
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
typeTextMarkupTypeareasIEnumerable<PdfRectangle>colorPdfColor?optionsAnnotationOptions
Returns
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
Returns
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
textstringfontPdfFontfontSizedoublecolorPdfColor?opacitydoubleangledoublebehindContentbool
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
ExtractImages()
Images drawn on the page with their position (see PdfImageExtractor).
public IReadOnlyList<PdfExtractedImage> ExtractImages()
Returns
ExtractText(TextExtractionOptions?)
Extracts the text of the page in reading order. See PdfTextExtractor for positions.
public string ExtractText(TextExtractionOptions? options = null)
Parameters
optionsTextExtractionOptions
Returns
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
Returns
FindText(string, StringComparison)
Finds occurrences of text and returns their bounding boxes.
public IReadOnlyList<PdfRectangle> FindText(string text, StringComparison comparison = StringComparison.Ordinal)
Parameters
textstringcomparisonStringComparison
Returns
FindText(Regex)
Returns the bounds of all regular expression matches on the page (matched per text line).
public IReadOnlyList<PdfRectangle> FindText(Regex pattern)
Parameters
patternRegex
Returns
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
filterFunc<PdfAnnotation, bool>
Returns
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
backgroundbool
Returns
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
GetInheritable(PdfName)
Returns an attribute, following the /Parent chain for inheritable attributes.
public PdfObject? GetInheritable(PdfName key)
Parameters
keyPdfName
Returns
GetOrCreateAnnotations()
The annotations array of the page (created on demand).
public PdfArray GetOrCreateAnnotations()
Returns
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
textstringcolorPdfColor?comparisonStringComparisontypeTextMarkupTypeoptionsAnnotationOptions
Returns
MarkForRedaction(PdfRectangle, string?)
Marks an area for later redaction with ApplyRedactions(RedactionOptions?).
public PdfAnnotation MarkForRedaction(PdfRectangle area, string? overlayText = null)
Parameters
areaPdfRectangleoverlayTextstring
Returns
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
Redact(IEnumerable<PdfRectangle>, RedactionOptions?)
Removes all content inside areas and covers them (see PdfRedactor).
public RedactionResult Redact(IEnumerable<PdfRectangle> areas, RedactionOptions? options = null)
Parameters
areasIEnumerable<PdfRectangle>optionsRedactionOptions
Returns
RemoveAnnotation(PdfAnnotation)
Removes an annotation from the page.
public bool RemoveAnnotation(PdfAnnotation annotation)
Parameters
annotationPdfAnnotation
Returns
SetContent(byte[], bool)
Replaces the page content with a single stream.
public void SetContent(byte[] content, bool compress = true)