Class PageContent
The drawing surface for a PDF page.
Accumulates drawing operations that are serialized to a content stream on
Save(Stream).
Assembly: DRIT.Pdf.dll
Syntax
public sealed class PageContent
Properties
Elements
Access the page's content-element collection (paths, images, etc.).
Declaration
public ContentElementCollection Elements { get; }
Property Value
Methods
AddAxialShading(double, double, double, double, double, double, double, double, List<(double t, PdfColor c)>)
Add a PDF Type-2 axial shading (linear gradient) bounded by the given clipping rectangle.
clipX, clipY are the PDF bottom-left of the clip rect.
(x0, y0) and (x1, y1)
are the axis endpoints in PDF page coordinates (t=0 and t=1 respectively).
stops are (position 0–1, PdfColor) pairs in ascending position order.
Declaration
public void AddAxialShading(double clipX, double clipY, double clipW, double clipH, double x0, double y0, double x1, double y1, List<(double t, PdfColor c)> stops)
Parameters
BeginLayer(OptionalContentGroup)
Begin an optional-content group (layer) section. All subsequent drawing operations
until the matching EndLayer() call are placed inside this OCG.
Declaration
public void BeginLayer(OptionalContentGroup group)
Parameters
DrawAnnotation(FormField)
Draw a form field's visual content at the field's page position.
Use this when flattening an AcroForm: call for each field, then
Fields.Clear(), then Save.
Declaration
public void DrawAnnotation(FormField field)
Parameters
DrawImage(PdfImage, PdfMatrix)
Draw a PdfImage using a custom transform matrix.
Declaration
public void DrawImage(PdfImage image, PdfMatrix matrix)
Parameters
DrawImage(PdfImage, PdfPoint)
Draw a PdfImage at the given bottom-left origin at its natural size.
Declaration
public void DrawImage(PdfImage image, PdfPoint point)
Parameters
DrawImage(PdfImage, PdfPoint, PdfSize)
Draw a PdfImage scaled to the given size.
Declaration
public void DrawImage(PdfImage image, PdfPoint point, PdfSize size)
Parameters
DrawImageClipped(PdfImage, PdfMatrix, double, double, double, double)
Draws an image using a transform matrix and an axis-aligned clip rectangle.
Declaration
public void DrawImageClipped(PdfImage image, PdfMatrix matrix, double clipX, double clipY, double clipWidth, double clipHeight)
Parameters
DrawImageClipped(PdfImage, PdfPoint, PdfSize, double, double, double, double)
Draws an image clipped to an axis-aligned PDF rectangle.
Declaration
public void DrawImageClipped(PdfImage image, PdfPoint point, PdfSize size, double clipX, double clipY, double clipWidth, double clipHeight)
Parameters
DrawTable(Table, PdfPoint)
Draw a table DOM starting from a top-left position on the current page.
Declaration
public TableRenderResult DrawTable(Table table, PdfPoint topLeft)
Parameters
Returns
DrawTable(Table, PdfPoint, TableRenderOptions?)
Draw a table DOM with optional render options (for example row slicing).
Declaration
public TableRenderResult DrawTable(Table table, PdfPoint topLeft, TableRenderOptions? options)
Parameters
Returns
DrawText(FormattedText, PdfMatrix)
Draw formatted text using a transform matrix.
Declaration
public void DrawText(FormattedText text, PdfMatrix matrix)
Parameters
DrawText(FormattedText, PdfPoint)
Draw formatted text at the given point (bottom-left of text block).
Declaration
public void DrawText(FormattedText text, PdfPoint point)
Parameters
DrawTextLines(IReadOnlyList<FormattedTextLine>, PdfPoint, double, TextAlignment)
Draws explicitly laid-out text lines at the given bottom-left origin.
The caller supplies line breaks and segment widths; this method does not wrap text.
Declaration
public void DrawTextLines(IReadOnlyList<FormattedTextLine> lines, PdfPoint point, double maxTextWidth = 0, TextAlignment alignment = TextAlignment.Left)
Parameters
| Type |
Name |
Description |
| IReadOnlyList<FormattedTextLine> |
lines |
The visual lines to emit.
|
| PdfPoint |
point |
The bottom-left origin of the text block.
|
| double |
maxTextWidth |
The alignment column width, or 0 for line-width alignment.
|
| TextAlignment |
alignment |
The horizontal alignment within the column.
|
EndLayer()
End the current optional-content group section.
Declaration
GetText()
Returns the concatenated text currently present on the page, including
text drawing operations that have not yet been serialized.
Declaration
Returns
| Type |
Description |
| string |
The page text separated into visual lines.
|
RecognizeTables(TableRecognitionOptions?)
Recognizes table-like text layouts from the page's interpreted content stream.
The detection is heuristic and intended for extraction scenarios (for example
exporting tabular data to spreadsheet formats).
Declaration
public IReadOnlyList<DetectedTable> RecognizeTables(TableRecognitionOptions? options = null)
Parameters
Returns
RemoveAllText()
Removes queued text drawing operations from this page content.
Returns the number of removed text operations.
Declaration
public int RemoveAllText()
Returns
RemoveGraphicsObjects()
Removes vector graphics drawing operations queued on this page content.
Returns the number of removed operations.
Declaration
public int RemoveGraphicsObjects()
Returns
RemoveImages()
Removes queued image drawing operations from this page content.
Returns the number of removed image operations.
Declaration
public int RemoveImages()
Returns
ReplaceFontFamily(string, string, bool)
Replaces queued text segment font family names.
Returns the number of changed segments.
Declaration
public int ReplaceFontFamily(string oldFontFamily, string newFontFamily, bool ignoreCase = true)
Parameters
Returns
ReplaceText(string, string, bool, int)
Replaces occurrences of oldValue in queued text drawing operations.
Returns the number of replacements performed.
Declaration
public int ReplaceText(string oldValue, string newValue, bool ignoreCase = false, int maxReplacements = 2147483647)
Parameters
Returns
ReplaceTextInStream(string, string, bool)
Replaces occurrences of oldValue with
newValue in the page's existing content stream
(text shown via Tj, TJ, ', " operators). Returns the number of
replacements performed. This operates on the already-saved content
stream, not on queued drawing operations.
Declaration
public int ReplaceTextInStream(string oldValue, string newValue, bool ignoreCase = false)
Parameters
Returns
ReplaceTextRegex(string, string, bool)
Replaces regular expression matches in queued text drawing operations.
Returns the number of replacements performed.
Declaration
public int ReplaceTextRegex(string pattern, string replacement, bool ignoreCase = false)
Parameters
Returns
ReplaceTextRegexInStream(string, string, bool)
Replaces regular expression matches in the page's existing content
stream. Returns the number of replacements performed.
Declaration
public int ReplaceTextRegexInStream(string pattern, string replacement, bool ignoreCase = false)
Parameters
Returns
ToString()
Returns the concatenated text of all TextContent elements on the page,
separated by spaces.
Declaration
public override string ToString()
Returns
Overrides