PdfGraphics

16 Dec 202524 minutes to read

Represents a graphics from a PDF page.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access first page
let page: PdfPage = document.getPage(0);
// Gets the graphics of the PDF page
let graphics: PdfGraphics = page.graphics;
//Create a new pen.
let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);
//Draw line on the page graphics.
graphics.drawLine(pen, {x: 10, y: 10}, {x: 100, y: 100});
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Properties

clientSize Size

Gets the size of the canvas reduced by margins and page templates (Read only).

Methods

drawArc

Draw arc on the page graphics.

Parameter Type Description
bounds Rectangle The bounding rectangle that defines the ellipse from which the arc shape comes.
startAngle number Angle measured in degrees clockwise from the x-axis to the first side of the arc shape.
sweepAngle number Angle measured in degrees clockwise from the startAngle parameter to the second side of the arc shape.
pen PdfPen Pen that determines the stroke color, width, and style of the arc.

Returns void

drawBezier

Draws a Bezier curve using a specified pen and coordinates for the start point, two control points, and end point.

Parameter Type Description
start Point The (x, y) coordinates of the starting point of the Bezier curve.
first Point The (x, y) coordinates of the first control point of the Bezier curve.
second Point The (x, y) coordinates of the second control point of the Bezier curve.
end Point The (x, y) coordinates of the ending point of the Bezier curve.
pen PdfPen The pen that determines the stroke color, width, and style of the Bezier curve.

Returns void

drawEllipse

Draw ellipse on the page graphics.

Parameter Type Description
bounds Rectangle The bounding rectangle that defines the ellipse.
pen PdfPen Pen that determines the stroke color, width, and style of the ellipse.

Returns void

drawEllipse

Draw ellipse on the page graphics.

Parameter Type Description
bounds Rectangle The bounding rectangle that defines the ellipse.
brush PdfBrush Brush that determines the fill color and texture of the ellipse.

Returns void

drawEllipse

Draw ellipse on the page graphics.

Parameter Type Description
bounds Rectangle The bounding rectangle that defines the ellipse.
pen PdfPen Pen that determines the stroke color, width, and style of the ellipse.
brush PdfBrush Brush that determines the fill color and texture of the ellipse.

Returns void

drawImage

Draws an image on the page graphics.

Parameter Type Description
image PdfImage The image to be drawn on the page.
location Point The (x, y) coordinates of the upper-left corner where the image will be drawn.

Returns void

drawImage

Draws an image on the page graphics.

Parameter Type Description
image PdfImage The image to be drawn on the page.
bounds Rectangle The bounding rectangle that defines where the image will be drawn.

Returns void

drawLine

Draws a line on the page graphics.

Parameter Type Description
pen PdfPen The pen that determines the stroke color, width, and style of the line.
start Point The (x, y) coordinates of the starting point of the line.
end Point The (x, y) coordinates of the ending point of the line.

Returns void

drawPath

Draws a graphics path defined by a pen and path.

Parameter Type Description
path PdfPath The path to be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the path.

Returns void

drawPath

Draws a graphics path defined by a brush and path.

Parameter Type Description
path PdfPath The path to be drawn.
brush PdfBrush The brush that determines the fill color and texture of the path.

Returns void

drawPath

Draws a graphics path defined by a pen, brush, and path.

Parameter Type Description
path PdfPath The path to be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the path.
brush PdfBrush The brush that determines the fill color and texture of the path.

Returns void

drawPie

Draws a pie slice on a PDF graphics.

Parameter Type Description
bounds Rectangle The bounding rectangle.
startAngle number The angle in degrees measured clockwise from the x-axis to the start of the pie slice.
sweepAngle number The angle in degrees measured clockwise from the startAngle to the end of the pie slice.
pen PdfPen The pen that determines the stroke color, width, and style of the pie slice.

Returns void

drawPie

Draws a pie slice on PDF graphics.

Parameter Type Description
bounds Rectangle The bounding rectangle.
startAngle number The angle in degrees, measured clockwise from the x-axis to the start of the pie slice.
sweepAngle number The angle in degrees, measured clockwise from the startAngle to the end of the pie slice.
brush PdfBrush The brush that determines the fill color and texture of the pie slice.

Returns void

drawPie

Draws a pie slice on PDF graphics.

Parameter Type Description
bounds Rectangle The bounding rectangle.
startAngle number The angle in degrees, measured clockwise from the x-axis to the start of the pie slice.
sweepAngle number The angle in degrees, measured clockwise from the startAngle to the end of the pie slice.
pen PdfPen The pen that determines the stroke color, width, and style of the pie slice.
brush PdfBrush The brush that determines the fill color and texture of the pie slice.

Returns void

drawPolygon

Draw polygon on the page graphics.

Parameter Type Description
points Point[] The points of the polygon.
pen PdfPen Pen that determines the stroke color, width, and style of the polygon.

Returns void

drawPolygon

Draw polygon on the page graphics.

Parameter Type Description
points Point[] The points of the polygon.
brush PdfBrush Brush that determines the fill color and texture of the polygon.

Returns void

drawPolygon

Draw polygon on the page graphics.

Parameter Type Description
points Point[] The points of the polygon.
pen PdfPen Pen that determines the stroke color, width, and style of the polygon.
brush PdfBrush Brush that determines the fill color and texture of the polygon.

Returns void

drawRectangle

Draw a rectangle on the page graphics.

Parameter Type Description
bounds Rectangle The bounds of the rectangular region.
pen PdfPen Pen that determines the stroke color, width, and style of the rectangle.

typescript<br>// Load an existing PDF document<br>let document: PdfDocument = new PdfDocument(data, password);<br>// Access first page<br>let page: PdfPage = document.getPage(0);<br>// Gets the graphics of the PDF page<br>let graphics: PdfGraphics = page.graphics;<br>// Create a new pen.<br>let pen: PdfPen = new PdfPen({r: 0, g: 0, b: 0}, 1);<br>// Draw a rectangle on the page graphics.<br>graphics.drawRectangle({x: 10, y: 20, width: 100, height: 200}, pen);<br>// Save the document<br>document.save('output.pdf');<br>// Destroy the document<br>document.destroy();<br>

Returns void

drawRectangle

Draw a rectangle on the page graphics.

Parameter Type Description
bounds Rectangle The bounds of the rectangular region.
brush PdfBrush Brush that determines the fill color and texture of the rectangle.

Returns void

drawRectangle

Draw a rectangle on the page graphics.

Parameter Type Description
bounds Rectangle The bounds of the rectangular region.
pen PdfPen Pen that determines the stroke color, width, and style of the rectangle.
brush PdfBrush Brush that determines the fill color and texture of the rectangle.

Returns void

drawRoundedRectangle

Draws a rounded rectangle on the page graphics.

Parameter Type Description
bounds Rectangle The bounding rectangle of the rounded rectangle.
radius number The radius of the rounded corners of the rectangle.
pen PdfPen The pen that determines the stroke color, width, and style of the rectangle.
brush PdfBrush The brush that determines the fill color and texture of the rectangle.

Returns void

drawString

Draw text on the page graphics.

Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
brush PdfBrush The brush that determines the fill color and texture of the string.

Returns void

drawString

Draw text on the page graphics.

Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
brush PdfBrush The brush that determines the fill color and texture of the string.
format PdfStringFormat The format that specifies text layout information such as alignment, line spacing, and trimming.

Returns void

drawString

Draw text on the page graphics.

Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the string.

Returns void

drawString

Draw text on the page graphics.

Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the string.
format PdfStringFormat The format that specifies text layout information such as alignment, line spacing, and trimming.

Returns void

drawString

Draw text on the page graphics.

Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the string.
brush PdfBrush The brush that determines the fill color and texture of the string.

Returns void

drawString

Draw text on the page graphics.

Parameter Type Description
value string The string to be drawn.
font PdfFont The font used to draw the string.
bounds Rectangle The rectangle specifying the bounds where the string will be drawn.
pen PdfPen The pen that determines the stroke color, width, and style of the string.
brush PdfBrush The brush that determines the fill color and texture of the string.
format PdfStringFormat The format that specifies text layout information such as alignment, line spacing, and trimming.

Returns void

drawTemplate

Draws a PDF template onto the page graphics.

Parameter Type Description
template PdfTemplate The PDF template to be drawn.
bounds Rectangle The bounds of the template.

Returns void

restore

Restore the graphics state.

Parameter Type Description
state (optional) PdfGraphicsState graphics state.

Returns void

rotateTransform

Represents a rotate transform of the graphics.

Parameter Type Description
angle number Angle of rotation in degrees.

Returns void

save

Save the current graphics state.

Returns PdfGraphicsState

scaleTransform

Represents a scale transform of the graphics.

Parameter Type Description
scaleX number Scale factor in the x direction.
scaleY number Scale factor in the y direction.

Returns void

setClip

Represents a clipping region of this graphics.

Parameter Type Description
bounds Rectangle Rectangle structure that represents the new clip region.
mode (optional) PdfFillMode Member of the PdfFillMode enumeration that specifies the filling operation to use.

Returns void

setTransparency

Represents a transparency of this graphics.

Parameter Type Description
stroke number The transparency value for strokes.

Returns void

setTransparency

Represents a transparency setting for the graphics.

Parameter Type Description
stroke number The transparency value for strokes.
fill number The transparency value for fills.
mode PdfBlendMode The blend mode to use.

Returns void

translateTransform

Represents a translate transform of the graphics.

Parameter Type Description
location Point (x, y) coordinates of the translation.

Returns void