Class PdfPageBuilder
A builder used to add construct a page in a PDF document.
public class PdfPageBuilder
- Inheritance
-
PdfPageBuilder
- Inherited Members
Properties
ContentStreams
Access to
public IReadOnlyList<PdfPageBuilder.IContentStream> ContentStreams { get; }
Property Value
CurrentStream
Access to the underlying data structures for advanced use cases.
public PdfPageBuilder.IContentStream CurrentStream { get; }
Property Value
PageNumber
The number of this page, 1-indexed.
public int PageNumber { get; }
Property Value
PageSize
The current size of the page.
public PdfRectangle PageSize { get; set; }
Property Value
Methods
AddImage(AddedImage, PdfRectangle)
Adds the image previously added using AddJpeg(byte[], PdfRectangle) or AddPng(byte[], PdfRectangle) sharing the same image to prevent duplication.
public void AddImage(PdfPageBuilder.AddedImage image, PdfRectangle placementRectangle)
Parameters
image
PdfPageBuilder.AddedImageplacementRectangle
PdfRectangle
AddJpeg(byte[], PdfRectangle)
Adds the JPEG image represented by the input bytes at the specified location.
public PdfPageBuilder.AddedImage AddJpeg(byte[] fileBytes, PdfRectangle placementRectangle)
Parameters
fileBytes
byte[]placementRectangle
PdfRectangle
Returns
AddJpeg(Stream, PdfRectangle)
Adds the JPEG image represented by the input stream at the specified location.
public PdfPageBuilder.AddedImage AddJpeg(Stream fileStream, PdfRectangle placementRectangle = default)
Parameters
fileStream
StreamplacementRectangle
PdfRectangle
Returns
AddJpeg(AddedImage, PdfRectangle)
Adds the JPEG image previously added using AddJpeg(byte[], PdfRectangle), this will share the same image data to prevent duplication.
public void AddJpeg(PdfPageBuilder.AddedImage image, PdfRectangle placementRectangle)
Parameters
image
PdfPageBuilder.AddedImageAn image previously added to this page or another page.
placementRectangle
PdfRectangleThe size and location to draw the image on this page.
AddPng(byte[], PdfRectangle)
Adds the PNG image represented by the input bytes at the specified location.
public PdfPageBuilder.AddedImage AddPng(byte[] pngBytes, PdfRectangle placementRectangle)
Parameters
pngBytes
byte[]placementRectangle
PdfRectangle
Returns
AddPng(Stream, PdfRectangle)
Adds the PNG image represented by the input stream at the specified location.
public PdfPageBuilder.AddedImage AddPng(Stream pngStream, PdfRectangle placementRectangle = default)
Parameters
pngStream
StreamplacementRectangle
PdfRectangle
Returns
AddText(string, decimal, PdfPoint, AddedFont)
Draws the text in the provided font at the specified position and returns the letters which will be drawn.
public IReadOnlyList<Letter> AddText(string text, decimal fontSize, PdfPoint position, PdfDocumentBuilder.AddedFont font)
Parameters
text
stringThe text to draw to the page.
fontSize
decimalThe size of the font in user space units.
position
PdfPointThe position of the baseline (lower-left corner) to start drawing the text from.
font
PdfDocumentBuilder.AddedFontA font added to the document using AddTrueTypeFont(IReadOnlyList<byte>) or AddStandard14Font(Standard14Font) methods.
Returns
- IReadOnlyList<Letter>
The letters from the input text with their corresponding size and position.
CopyFrom(Page)
Copy a page from unknown source to this page
public PdfPageBuilder CopyFrom(Page srcPage)
Parameters
srcPage
PagePage to be copied
Returns
DrawCircle(PdfPoint, decimal, decimal, bool)
Draws a circle on the current page centering at the specified point with the given diameter and line width.
public PdfPageBuilder DrawCircle(PdfPoint center, decimal diameter, decimal lineWidth = 1, bool fill = false)
Parameters
center
PdfPointThe center position of the circle.
diameter
decimalThe diameter of the circle.
lineWidth
decimalThe width of the line border of the circle.
fill
boolWhether to fill with the color set by SetTextAndFillColor(byte, byte, byte).
Returns
DrawEllipsis(PdfPoint, decimal, decimal, decimal, bool)
Draws an ellipsis on the current page centering at the specified point with the given width, height and line width.
public PdfPageBuilder DrawEllipsis(PdfPoint center, decimal width, decimal height, decimal lineWidth = 1, bool fill = false)
Parameters
center
PdfPointThe center position of the ellipsis.
width
decimalThe width of the ellipsis.
height
decimalThe height of the ellipsis.
lineWidth
decimalThe width of the line border of the ellipsis.
fill
boolWhether to fill with the color set by SetTextAndFillColor(byte, byte, byte).
Returns
DrawLine(PdfPoint, PdfPoint, decimal)
Draws a line on the current page between two points with the specified line width.
public PdfPageBuilder DrawLine(PdfPoint from, PdfPoint to, decimal lineWidth = 1)
Parameters
from
PdfPointThe first point on the line.
to
PdfPointThe last point on the line.
lineWidth
decimalThe width of the line in user space units.
Returns
DrawRectangle(PdfPoint, decimal, decimal, decimal, bool)
Draws a rectangle on the current page starting at the specified point with the given width, height and line width.
public PdfPageBuilder DrawRectangle(PdfPoint position, decimal width, decimal height, decimal lineWidth = 1, bool fill = false)
Parameters
position
PdfPointThe position of the rectangle, for positive width and height this is the bottom-left corner.
width
decimalThe width of the rectangle.
height
decimalThe height of the rectangle.
lineWidth
decimalThe width of the line border of the rectangle.
fill
boolWhether to fill with the color set by SetTextAndFillColor(byte, byte, byte).
Returns
DrawTriangle(PdfPoint, PdfPoint, PdfPoint, decimal, bool)
Draws a triangle on the current page with the specified points and line width.
public PdfPageBuilder DrawTriangle(PdfPoint point1, PdfPoint point2, PdfPoint point3, decimal lineWidth = 1, bool fill = false)
Parameters
point1
PdfPointPosition of the first corner of the triangle.
point2
PdfPointPosition of the second corner of the triangle.
point3
PdfPointPosition of the third corner of the triangle.
lineWidth
decimalThe width of the line border of the triangle.
fill
boolWhether to fill with the color set by SetTextAndFillColor(byte, byte, byte).
Returns
MeasureText(string, decimal, PdfPoint, AddedFont)
Calculates the size and position of each letter in a given string in the provided font without changing the state of the page.
public IReadOnlyList<Letter> MeasureText(string text, decimal fontSize, PdfPoint position, PdfDocumentBuilder.AddedFont font)
Parameters
text
stringThe text to measure each letter of.
fontSize
decimalThe size of the font in user space units.
position
PdfPointThe position of the baseline (lower-left corner) to start drawing the text from.
font
PdfDocumentBuilder.AddedFontA font added to the document using AddTrueTypeFont(IReadOnlyList<byte>) or AddStandard14Font(Standard14Font) methods.
Returns
- IReadOnlyList<Letter>
The letters from the input text with their corresponding size and position.
NewContentStreamAfter()
Allow to append a new content stream after the current one and select it
public void NewContentStreamAfter()
NewContentStreamBefore()
Allow to append a new content stream before the current one and select it
public void NewContentStreamBefore()
ResetColor()
Restores the stroke, text and fill color to default (black).
public PdfPageBuilder ResetColor()
Returns
SelectContentStream(int)
Select a content stream from the list, by his index
public void SelectContentStream(int index)
Parameters
index
intindex of the content stream to be selected
SetRotation(PageRotationDegrees)
Set the number of degrees by which the page is rotated clockwise when displayed or printed.
public PdfPageBuilder SetRotation(PageRotationDegrees degrees)
Parameters
degrees
PageRotationDegrees
Returns
SetStrokeColor(byte, byte, byte)
Sets the stroke color for any following operations to the RGB value. Use ResetColor() to reset.
public PdfPageBuilder SetStrokeColor(byte r, byte g, byte b)
Parameters
Returns
SetTextAndFillColor(byte, byte, byte)
Sets the fill and text color for any following operations to the RGB value. Use ResetColor() to reset.
public PdfPageBuilder SetTextAndFillColor(byte r, byte g, byte b)
Parameters
Returns
SetTextRenderingMode(TextRenderingMode)
Set the text rendering mode. This will apply to all future calls to AddText until called again.
To insert invisible text, for example output of OCR, use TextRenderingMode.Neither
.
public PdfPageBuilder SetTextRenderingMode(TextRenderingMode mode)
Parameters
mode
TextRenderingModeText rendering mode to set.