Table of Contents

Class PdfPageBuilder

Namespace
UglyToad.PdfPig.Writer
Assembly
UglyToad.PdfPig.dll

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

IReadOnlyList<PdfPageBuilder.IContentStream>

CurrentStream

Access to the underlying data structures for advanced use cases.

public PdfPageBuilder.IContentStream CurrentStream { get; }

Property Value

PdfPageBuilder.IContentStream

PageNumber

The number of this page, 1-indexed.

public int PageNumber { get; }

Property Value

int

PageSize

The current size of the page.

public PdfRectangle PageSize { get; set; }

Property Value

PdfRectangle

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.AddedImage
placementRectangle 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

PdfPageBuilder.AddedImage

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 Stream
placementRectangle PdfRectangle

Returns

PdfPageBuilder.AddedImage

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.AddedImage

An image previously added to this page or another page.

placementRectangle PdfRectangle

The 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

PdfPageBuilder.AddedImage

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 Stream
placementRectangle PdfRectangle

Returns

PdfPageBuilder.AddedImage

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 string

The text to draw to the page.

fontSize decimal

The size of the font in user space units.

position PdfPoint

The position of the baseline (lower-left corner) to start drawing the text from.

font PdfDocumentBuilder.AddedFont

A 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 Page

Page to be copied

Returns

PdfPageBuilder

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 PdfPoint

The center position of the circle.

diameter decimal

The diameter of the circle.

lineWidth decimal

The width of the line border of the circle.

fill bool

Whether to fill with the color set by SetTextAndFillColor(byte, byte, byte).

Returns

PdfPageBuilder

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 PdfPoint

The center position of the ellipsis.

width decimal

The width of the ellipsis.

height decimal

The height of the ellipsis.

lineWidth decimal

The width of the line border of the ellipsis.

fill bool

Whether to fill with the color set by SetTextAndFillColor(byte, byte, byte).

Returns

PdfPageBuilder

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 PdfPoint

The first point on the line.

to PdfPoint

The last point on the line.

lineWidth decimal

The width of the line in user space units.

Returns

PdfPageBuilder

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 PdfPoint

The position of the rectangle, for positive width and height this is the bottom-left corner.

width decimal

The width of the rectangle.

height decimal

The height of the rectangle.

lineWidth decimal

The width of the line border of the rectangle.

fill bool

Whether to fill with the color set by SetTextAndFillColor(byte, byte, byte).

Returns

PdfPageBuilder

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 PdfPoint

Position of the first corner of the triangle.

point2 PdfPoint

Position of the second corner of the triangle.

point3 PdfPoint

Position of the third corner of the triangle.

lineWidth decimal

The width of the line border of the triangle.

fill bool

Whether to fill with the color set by SetTextAndFillColor(byte, byte, byte).

Returns

PdfPageBuilder

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 string

The text to measure each letter of.

fontSize decimal

The size of the font in user space units.

position PdfPoint

The position of the baseline (lower-left corner) to start drawing the text from.

font PdfDocumentBuilder.AddedFont

A 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

PdfPageBuilder

SelectContentStream(int)

Select a content stream from the list, by his index

public void SelectContentStream(int index)

Parameters

index int

index 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

PdfPageBuilder

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

r byte

Red - 0 to 255

g byte

Green - 0 to 255

b byte

Blue - 0 to 255

Returns

PdfPageBuilder

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

r byte

Red - 0 to 255

g byte

Green - 0 to 255

b byte

Blue - 0 to 255

Returns

PdfPageBuilder

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 TextRenderingMode

Text rendering mode to set.

Returns

PdfPageBuilder