Class Page
Used to create PDF page objects.
Please note:
The coordinate (0.0f, 0.0f) is the top left corner of the page.
The size of the pages are represented in points.
1 point is 1/72 inches.
public class Page
- Inheritance
-
Page
- Inherited Members
Constructors
Page(PDF, PDFobj)
Creates a page from a page object read from an existing PDF.
public Page(PDF pdf, PDFobj pageObj)
Parameters
Page(PDF, PageSize)
Creates page object and add it to the PDF document.
Please note:
The coordinate (0.0, 0.0) is the top left corner of the page.
The size of the pages are represented in points.
1 point is 1/72 inches.
public Page(PDF pdf, PageSize pageSize)
Parameters
Page(PDF, PageSize, bool)
Creates page object and add it to the PDF document.
Please note:
The coordinate (0.0, 0.0) is the top left corner of the page.
The size of the pages are represented in points.
1 point is 1/72 inches.
public Page(PDF pdf, PageSize pageSize, bool addPageToPDF)
Parameters
Fields
DETACHED
Pass to the Page constructor to create a page that is not added to the PDF right away.
public const bool DETACHED = false
Field Value
MSCALE_X
Index of the horizontal scale in an Android Matrix value array.
public const int MSCALE_X = 0
Field Value
MSCALE_Y
Index of the vertical scale in an Android Matrix value array.
public const int MSCALE_Y = 4
Field Value
MSKEW_X
Index of the horizontal skew in an Android Matrix value array.
public const int MSKEW_X = 1
Field Value
MSKEW_Y
Index of the vertical skew in an Android Matrix value array.
public const int MSKEW_Y = 3
Field Value
MTRANS_X
Index of the horizontal translation in an Android Matrix value array.
public const int MTRANS_X = 2
Field Value
MTRANS_Y
Index of the vertical translation in an Android Matrix value array.
public const int MTRANS_Y = 5
Field Value
Methods
AddArcToPath(float, float, float, float, float, float)
Adds an elliptical arc to the current path.
public float[] AddArcToPath(float x, float y, float rx, float ry, float startAngle, float sweepDegrees)
Parameters
xfloatthe x coordinate of the center.
yfloatthe y coordinate of the center.
rxfloatthe horizontal radius.
ryfloatthe vertical radius.
startAnglefloatthe start angle in degrees.
sweepDegreesfloatthe sweep angle in degrees.
Returns
- float[]
the control points and the end point of the last curve segment.
AddArtifactBMC()
Begins an artifact marked content sequence.
public void AddArtifactBMC()
AddBDC(StructElem, string, string)
Begins a marked content sequence with the structure, actual text and alternate description.
public void AddBDC(StructElem structure, string actualText, string altDescription)
Parameters
structureStructElemactualTextstringaltDescriptionstring
AddBDC(StructElem, string, string, string)
Begins a marked content sequence with the structure, language, actual text and alternate description.
public void AddBDC(StructElem structure, string language, string actualText, string altDescription)
Parameters
structureStructElemlanguagestringactualTextstringaltDescriptionstring
AddCircularArcToPath(float, float, float, float, float)
Adds a circular arc to the current path.
public float[] AddCircularArcToPath(float x, float y, float r, float startAngle, float sweepDegrees)
Parameters
xfloatthe x coordinate of the center.
yfloatthe y coordinate of the center.
rfloatthe radius.
startAnglefloatthe start angle in degrees.
sweepDegreesfloatthe sweep angle in degrees.
Returns
- float[]
the control points and the end point of the last curve segment.
AddDestination(string, float)
Adds destination to this page.
public Destination AddDestination(string name, float yPosition)
Parameters
namestringThe destination name.
yPositionfloatThe vertical position of the destination on this page.
Returns
- Destination
the destination.
AddDestination(string, float, float)
Adds destination to this page.
public Destination AddDestination(string name, float xPosition, float yPosition)
Parameters
namestringThe destination name.
xPositionfloatThe horizontal position of the destination on this page.
yPositionfloatThe vertical position of the destination on this page.
Returns
- Destination
the destination.
AddEMC()
Ends the current marked content sequence.
public void AddEMC()
AddFooter(TextLine)
Draws the text line centered at the bottom of the page.
public float[] AddFooter(TextLine textLine)
Parameters
textLineTextLine
Returns
- float[]
AddFooter(TextLine, float)
Draws the text line centered at the bottom of the page, with its baseline at the specified offset from the bottom.
public float[] AddFooter(TextLine textLine, float offset)
Parameters
Returns
- float[]
AddHeader(TextLine)
Draws the text line centered at the top of the page.
public float[] AddHeader(TextLine textLine)
Parameters
textLineTextLine
Returns
- float[]
AddHeader(TextLine, float)
Draws the text line centered at the top of the page, with its baseline at the specified offset.
public float[] AddHeader(TextLine textLine, float offset)
Parameters
Returns
- float[]
AddResource(Font, List<PDFobj>)
Adds a font to the resources of this page.
public void AddResource(Font font, List<PDFobj> objects)
Parameters
AddResource(Image, List<PDFobj>)
Adds an image to the resources of this page.
public void AddResource(Image image, List<PDFobj> objects)
Parameters
AddResource(int, List<PDFobj>)
Adds a core font to the resources of this page and returns the font.
public Font AddResource(int coreFont, List<PDFobj> objects)
Parameters
Returns
AddWatermark(Font, string)
Draws the text as a watermark diagonally across the page.
public void AddWatermark(Font font, string text)
Parameters
BeginStructElement(StructElem)
Begins a structure element of a tagged document, PDF/UA or a PDF/A of level A, that what is drawn until EndStructElement becomes the kids of, like the L of a list whose items are drawn one at a time. The calls nest, and every one needs its EndStructElement. In a document that is not tagged both do nothing.
public void BeginStructElement(StructElem structure)
Parameters
structureStructElem
BezierCurveTo(Point, Point, Point)
Draws a bezier curve starting from the current point. Please note: You must call the StrokePath, ClosePath or FillPath methods after the last BezierCurveTo call.
Author: Pieter Libin, pieter@emweb.be
public void BezierCurveTo(Point p1, Point p2, Point p3)
Parameters
ClipPath()
Clips the path.
public void ClipPath()
ClipRect(float, float, float, float)
Sets the clipping path to the specified rectangle.
public void ClipRect(float x, float y, float w, float h)
Parameters
ClosePath()
Closes the current path and then strokes it using the active pen color.
public void ClosePath()
Complete(List<PDFobj>)
Finishes a page read from an existing PDF by adding its new content to the objects.
public void Complete(List<PDFobj> objects)
Parameters
CurveTo(float, float, float, float, float, float)
Draws a cubic bezier curve starting from the current point to the end point p3
public void CurveTo(float x1, float y1, float x2, float y2, float x3, float y3)
Parameters
x1floatfirst control point x
y1floatfirst control point y
x2floatsecond control point x
y2floatsecond control point y
x3floatend point x
y3floatend point y
DrawCircle(float, float, float)
Draws a circle on the page. The outline of the circle is drawn using the current pen color.
public void DrawCircle(float x, float y, float r)
Parameters
xfloatthe x coordinate of the center of the circle to be drawn.
yfloatthe y coordinate of the center of the circle to be drawn.
rfloatthe radius of the circle to be drawn.
DrawContents(byte[], float, float, float, float, float)
Draws the content stream scaled and placed at the specified location.
public void DrawContents(byte[] content, float h, float x, float y, float xScale, float yScale)
Parameters
DrawEllipse(float, float, float, float)
Draws an ellipse on the page using the current pen color.
public void DrawEllipse(float x, float y, float r1, float r2)
Parameters
xfloatthe x coordinate of the center of the ellipse to be drawn.
yfloatthe y coordinate of the center of the ellipse to be drawn.
r1floatthe horizontal radius of the ellipse to be drawn.
r2floatthe vertical radius of the ellipse to be drawn.
DrawLine(float, float, float, float)
Draws a line on the page, using the current color, between the points (x1, y1) and (x2, y2).
public void DrawLine(float x1, float y1, float x2, float y2)
Parameters
x1floatthe first point's x coordinate.
y1floatthe first point's y coordinate.
x2floatthe second point's x coordinate.
y2floatthe second point's y coordinate.
DrawPath(List<Point>, PathOperator)
Draws a path consisting of multiple points using the specified path operator. Supports both straight line segments and Bézier curve segments with control points.
public void DrawPath(List<Point> path, PathOperator pathOperator)
Parameters
pathList<Point>The list of points defining the path. The first point sets the starting position, subsequent points define line segments or curve control points. Fewer than two points paint nothing.
pathOperatorPathOperatorThe path painting operator to apply, for example PathOperator.STROKE or PathOperator.FILL.
Examples
// Drawing a rectangle with straight lines
List<Point> rect = new List<Point> {
new Point(100, 100),
new Point(200, 100),
new Point(200, 200),
new Point(100, 200)
};
DrawPath(rect, PathOperator.STROKE);
// Drawing a cubic Bézier curve
List<Point> curve = new List<Point> {
new Point(100, 100), // Start point
new Point(150, 50, Point.CONTROL_POINT_C), // First control point
new Point(250, 150, Point.CONTROL_POINT_C), // Second control point
new Point(300, 100) // End point
};
DrawPath(curve, PathOperator.STROKE);
Remarks
The method processes points as follows:
- Starts with MoveTo() to position at the first point
- For each subsequent point:
- If the point has a controlPoint set: stores it for curve definition
- If the point has no controlPoint:
- If previous point had controlPoint: completes curve definition
- Otherwise: creates straight line segment using LineTo()
- Applies the specified path operator at the end
This method supports both simple polygonal paths and complex paths with Bézier curves. Control points should have their controlPoint property set to indicate curve type (e.g., 'C' for cubic Bézier, 'Q' for quadratic Bézier). A path that ends on a control point, whose curve has no end, is refused and nothing of it is drawn.
- See Also
DrawPoint(Point)
Draws a point on the page using the current pen color.
public void DrawPoint(Point p)
Parameters
pPointthe point.
DrawRect(float, float, float, float)
Draws the outline of a rectangle using the current pen color.
public void DrawRect(float x, float y, float w, float h)
Parameters
xfloatX‑coordinate of the top left corner.
yfloatY‑coordinate of the top left corner.
wfloatRectangle width.
hfloatRectangle height.
DrawRoundedRect(float, float, float, float, float, float)
Draws the outline of a rectangle with rounded corners using the current pen color.
public void DrawRoundedRect(float x, float y, float w, float h, float r1, float r2)
Parameters
xfloatthe x coordinate of the top left corner.
yfloatthe y coordinate of the top left corner.
wfloatthe width.
hfloatthe height.
r1floatthe horizontal radius of the corners.
r2floatthe vertical radius of the corners.
DrawString(Font, Font, float, string, float, float)
Draws the string in black. The fallback font is used for characters the main font does not have.
public void DrawString(Font font, Font fallbackFont, float fontSize, string str, float x, float y)
Parameters
DrawString(Font, float, string, float, float)
Draws the string in black with its baseline at the specified location.
public void DrawString(Font font, float fontSize, string str, float x, float y)
Parameters
DrawString(Font, float, string, float, float, float)
Draws each character of str at successive X positions,
advancing by dx after every glyph.
public void DrawString(Font font, float fontSize, string str, float x, float y, float dx)
Parameters
fontFontFont used for rendering.
fontSizefloatSize of the font.
strstringText to draw.
xfloatStarting X coordinate.
yfloatBaseline Y coordinate.
dxfloatHorizontal offset applied after each character.
EndStructElement()
Ends the structure element that BeginStructElement began.
public void EndStructElement()
FillCircle(float, float, float)
Fills a circle on the page using the current brush color.
public void FillCircle(float x, float y, float r)
Parameters
xfloatthe x coordinate of the center of the circle to be filled.
yfloatthe y coordinate of the center of the circle to be filled.
rfloatthe radius of the circle to be filled.
FillEllipse(float, float, float, float)
Fills an ellipse on the page using the current brush color.
public void FillEllipse(float x, float y, float r1, float r2)
Parameters
xfloatthe x coordinate of the center of the ellipse to be drawn.
yfloatthe y coordinate of the center of the ellipse to be drawn.
r1floatthe horizontal radius of the ellipse to be drawn.
r2floatthe vertical radius of the ellipse to be drawn.
FillPath()
Closes the current path and fills it using the active brush color.
public void FillPath()
FillRect(float, float, float, float)
Fills a rectangle using the current brush color.
public void FillRect(float x, float y, float w, float h)
Parameters
xfloatX‑coordinate of the top left corner.
yfloatY‑coordinate of the top left corner.
wfloatRectangle width.
hfloatRectangle height.
FillRoundedRect(float, float, float, float, float, float)
Fills a rectangle with rounded corners using the current brush color.
public void FillRoundedRect(float x, float y, float w, float h, float r1, float r2)
Parameters
xfloatthe x coordinate of the top left corner.
yfloatthe y coordinate of the top left corner.
wfloatthe width.
hfloatthe height.
r1floatthe horizontal radius of the corners.
r2floatthe vertical radius of the corners.
GetBrushColor()
Returns a copy of the current brush color as an RGB float array.
public float[] GetBrushColor()
Returns
- float[]
A
float[]containing the red, green, and blue components (0.0f to 1.0f) of the brush color.
GetContent()
Returns the content stream of this page.
public byte[] GetContent()
Returns
- byte[]
GetHeight()
Returns the height of this page.
public float GetHeight()
Returns
- float
the height of the page.
GetPenColor()
Gets a copy of the current pen color as an RGB float array.
public float[] GetPenColor()
Returns
- float[]
A
float[]with three elements: red, green, and blue components (0.0f to 1.0f).
GetPenWidth()
Returns the current pen width.
public float GetPenWidth()
Returns
GetWidth()
Returns the width of this page.
public float GetWidth()
Returns
- float
the width of the page.
InvertYAxis()
Flips the y axis, so the origin is the top left corner of the page and y grows downward.
public void InvertYAxis()
LineTo(float, float)
Draws a line from the current pen position to the point with coordinates (x, y),
public void LineTo(float x, float y)
Parameters
xfloatThe horizontal offset for the line endpoint.
yfloatThe vertical offset for the line endpoint (before Y‑axis inversion).
MoveTo(float, float)
Moves the pen to the absolute point (x, y) on the page.
public void MoveTo(float x, float y)
Parameters
xfloatHorizontal coordinate of the new position.
yfloatVertical coordinate (before Y‑axis flip).
Remarks
Converts Y to height - y because the renderer uses a top‑left origin.
Appends a move‑to command in the form “x y m\n”.
RestoreGraphicsState()
Restores the graphics state. Please see Example_30.
public void RestoreGraphicsState()
SaveGraphicsState()
Saves the graphics state. Please see Example_30.
public void SaveGraphicsState()
SetArtBox(float, float, float, float)
Sets the page ArtBox. See page 77 of the PDF32000_2008.pdf specification.
public Page SetArtBox(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY)
Parameters
upperLeftXfloatthe top left X coordinate of the ArtBox.
upperLeftYfloatthe top left Y coordinate of the ArtBox.
lowerRightXfloatthe bottom right X coordinate of the ArtBox.
lowerRightYfloatthe bottom right Y coordinate of the ArtBox.
Returns
- Page
this Page object.
SetBleedBox(float, float, float, float)
Sets the page BleedBox. See page 77 of the PDF32000_2008.pdf specification.
public Page SetBleedBox(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY)
Parameters
upperLeftXfloatthe top left X coordinate of the BleedBox.
upperLeftYfloatthe top left Y coordinate of the BleedBox.
lowerRightXfloatthe bottom right X coordinate of the BleedBox.
lowerRightYfloatthe bottom right Y coordinate of the BleedBox.
Returns
- Page
this Page object.
SetBrushColor(int)
Sets the brush color. Color.transparent leaves it unchanged.
public Page SetBrushColor(int color)
Parameters
colorintthe color. See the Color class for predefined values or define your own using 0x00RRGGBB packed integers.
Returns
- Page
this Page object.
SetBrushColor(float[])
Sets the color for brush operations.
public Page SetBrushColor(float[] rgbColor)
Parameters
rgbColorfloat[]the color.
Returns
- Page
this Page object.
SetBrushColorCMYK(float, float, float, float)
Sets the color for brush operations using CMYK. This is the color used when drawing regular text and filling shapes.
public Page SetBrushColorCMYK(float c, float m, float y, float k)
Parameters
cfloatthe cyan component is float value from 0.0f to 1.0f.
mfloatthe magenta component is float value from 0.0f to 1.0f.
yfloatthe yellow component is float value from 0.0f to 1.0f.
kfloatthe black component is float value from 0.0f to 1.0f.
Returns
- Page
this Page object.
SetCropBox(float, float, float, float)
Sets the page CropBox. See page 77 of the PDF32000_2008.pdf specification.
public Page SetCropBox(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY)
Parameters
upperLeftXfloatthe top left X coordinate of the CropBox.
upperLeftYfloatthe top left Y coordinate of the CropBox.
lowerRightXfloatthe bottom right X coordinate of the CropBox.
lowerRightYfloatthe bottom right Y coordinate of the CropBox.
Returns
- Page
this Page object.
SetDefaultPenWidth()
Sets the line width to the default. The default is the finest line width.
public Page SetDefaultPenWidth()
Returns
- Page
this Page object.
SetDefaultStrokeDashPattern()
Sets the default stroke pattern to be solid line or curve.
public Page SetDefaultStrokeDashPattern()
Returns
- Page
this Page object.
SetFigureBoundingBox(float, float, float, float)
Sets the bounding box of the figure that AddBDC began last: the box it is drawn in, x and y its top left corner, w wide and h tall. PDF/UA asks for the bounding box of every figure, which a screen reader or a program that reflows the page uses to find it. The figures of the library, images, SVG images, charts, barcodes and QR codes, set it themselves; a figure drawn with AddBDC and AddEMC around other drawing needs it set before AddEMC. It does nothing in a document that is not tagged.
public void SetFigureBoundingBox(float x, float y, float w, float h)
Parameters
SetGraphicsState(GraphicsState)
Sets the graphics state. Please see Example_30.
public Page SetGraphicsState(GraphicsState gs)
Parameters
gsGraphicsStatethe graphics state to use.
Returns
- Page
this Page object.
SetLineCapStyle(CapStyle)
Sets the current line cap style.
public Page SetLineCapStyle(CapStyle style)
Parameters
styleCapStylethe cap style of the current line. Supported values: CapStyle.BUTT, CapStyle.ROUND and CapStyle.PROJECTING_SQUARE
Returns
- Page
this Page object.
SetLineJoinStyle(JoinStyle)
Sets the line join style.
public Page SetLineJoinStyle(JoinStyle style)
Parameters
styleJoinStylethe line join style code. Supported values: JoinStyle.MITER, JoinStyle.ROUND and JoinStyle.BEVEL
Returns
- Page
this Page object.
SetPenColor(int)
Sets the pen color using a packed 0x00RRGGBB integer value. Color.transparent leaves it unchanged.
public Page SetPenColor(int color)
Parameters
colorintThe color value, where each component (red, green, blue) is packed into a 24-bit integer. You can use predefined colors from the Color class or define your own.
Returns
SetPenColor(float[])
Sets the pen color using an RGB color array.
public Page SetPenColor(float[] rgbColor)
Parameters
Returns
Remarks
Logs a warning and does not set the color if the values are out of range or the array is null.
SetPenColorCMYK(float, float, float, float)
Sets the color for stroking operations using CMYK. The pen color is used when drawing lines and splines.
public Page SetPenColorCMYK(float c, float m, float y, float k)
Parameters
cfloatthe cyan component is float value from 0.0f to 1.0f.
mfloatthe magenta component is float value from 0.0f to 1.0f.
yfloatthe yellow component is float value from 0.0f to 1.0f.
kfloatthe black component is float value from 0.0f to 1.0f.
Returns
- Page
this Page object.
SetPenWidth(float)
Sets the pen width that will be used to draw lines and splines on this page.
public Page SetPenWidth(float width)
Parameters
widthfloatthe pen width.
Returns
- Page
this Page object.
SetRotation(int)
Rotates this page clockwise when it is displayed, as every rotation in PDFjet turns and as /Rotate does, by 0, 90, 180 or 270 degrees; other angles are ignored.
public Page SetRotation(int degrees)
Parameters
degreesint
Returns
SetStrokeDashPattern(string)
The stroke dash pattern controls the pattern of dashes and gaps used to stroke paths. It is specified by a dash array and a dash phase. The elements of the dash array are positive numbers that specify the lengths of alternating dashes and gaps. The dash phase specifies the distance into the dash pattern at which to start the dash. The elements of both the dash array and the dash phase are expressed in user space units.
Examples of line dash patterns:
"[Array] Phase" Appearance Description
_______________ _________________ ____________________________________
"[] 0" ----------------- Solid line
"[3] 0" --- --- --- 3 units on, 3 units off, ...
"[2] 1" - -- -- -- -- 1 on, 2 off, 2 on, 2 off, ...
"[2 1] 0" -- -- -- -- -- -- 2 on, 1 off, 2 on, 1 off, ...
"[3 5] 6" --- --- 2 off, 3 on, 5 off, 3 on, 5 off, ...
"[2 3] 11" - -- -- -- 1 on, 3 off, 2 on, 3 off, 2 on, ...
public Page SetStrokeDashPattern(string strokeDashPattern)
Parameters
strokeDashPatternstringthe stroke dash pattern.
Returns
- Page
this Page object.
SetTextRenderingMode(int)
Sets the text rendering mode.
public Page SetTextRenderingMode(int mode)
Parameters
modeintthe rendering mode.
Returns
- Page
this Page object.
SetTextRotation(int)
Sets the rotation of the text that is drawn next. A positive angle turns clockwise, as every rotation in PDFjet turns, and a negative angle counterclockwise.
public Page SetTextRotation(int degrees)
Parameters
degreesintthe angle.
Returns
- Page
this Page object.
SetTrimBox(float, float, float, float)
Sets the page TrimBox. See page 77 of the PDF32000_2008.pdf specification.
public Page SetTrimBox(float upperLeftX, float upperLeftY, float lowerRightX, float lowerRightY)
Parameters
upperLeftXfloatthe top left X coordinate of the TrimBox.
upperLeftYfloatthe top left Y coordinate of the TrimBox.
lowerRightXfloatthe bottom right X coordinate of the TrimBox.
lowerRightYfloatthe bottom right Y coordinate of the TrimBox.
Returns
- Page
this Page object.
StrokePath()
Strokes the current path using the active pen color.
public void StrokePath()
Transform(float[])
Concatenates a transformation matrix to the current one. Save the graphics state before and restore it after. The page height is divided by the vertical scale.
public void Transform(float[] values)
Parameters
valuesfloat[]the scale x, skew x, translate x, skew y, scale y and translate y at the MSCALE_X to MTRANS_Y indices, the first six values of an Android Matrix.getValues() array.