/ PDF / PdfGraphics
Search results

PdfGraphics API in JavaScript PDF API control

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([0, 0, 0], 1);
//Draw line on the page graphics.
graphics.drawLine(pen, 10, 10, 100, 100);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Properties

clientSize number[]

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
x number The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse from which the arc shape comes.
y number The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse from which the arc shape comes.
width number Width of the bounding rectangle that defines the ellipse from which the arc shape comes.
height number Height of 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
startX number The x-coordinate of the starting point of the Bezier curve.
startY number The y-coordinate of the starting point of the Bezier curve.
firstX number The x-coordinate of the first control point of the Bezier curve.
firstY number The y-coordinate of the first control point of the Bezier curve.
secondX number The x-coordinate of the second control point of the Bezier curve.
secondY number The y-coordinate of the second control point of the Bezier curve.
endX number The x-coordinate of the ending point of the Bezier curve.
endY number The y-coordinate 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
x number The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.
y number The y-coordinate of the upper-left corner of the bounding rectangle that defines ellipse.
width number The width of the bounding rectangle that defines ellipse.
height number The height of the bounding rectangle that defines 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
x number The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.
y number The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.
width number The width of the bounding rectangle that defines ellipse.
height number The height of the bounding rectangle that defines 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
x number The x-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.
y number The y-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse.
width number The width of the bounding rectangle that defines ellipse.
height number The height of the bounding rectangle that defines 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.
x number The x-coordinate of the upper-left corner where the image will be drawn.
y number The y-coordinate 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.
x number The x-coordinate of the upper-left corner where the image will be drawn.
y number The y-coordinate of the upper-left corner where the image will be drawn.
width number The width of the image to be drawn.
height number The height of the image to 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.
x1 number The x-coordinate of the starting point of the line.
y1 number The y-coordinate of the starting point of the line.
x2 number The x-coordinate of the ending point of the line.
y2 number The y-coordinate 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
x number The x-coordinate of the upper-left corner of the bounding rectangle.
y number The y-coordinate of the upper-left corner of the bounding rectangle.
width number The width of the bounding rectangle.
height number The height of 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
x number The x-coordinate of the upper-left corner of the bounding rectangle.
y number The y-coordinate of the upper-left corner of the bounding rectangle.
width number The width of the bounding rectangle.
height number The height of 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
x number The x-coordinate of the upper-left corner of the bounding rectangle.
y number The y-coordinate of the upper-left corner of the bounding rectangle.
width number The width of the bounding rectangle.
height number The height of 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 Array 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 Array 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 Array 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
x number The x-coordinate of the upper-left corner of the rectangular region.
y number The y-coordinate of the upper-left corner of the rectangular region.
width number The width of the rectangular region.
height number The height 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([0, 0, 0], 1);<br>// Draw a rectangle on the page graphics.<br>graphics.drawRectangle(10, 20, 100, 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
x number The x-coordinate of the upper-left corner of the rectangular region.
y number The y-coordinate of the upper-left corner of the rectangular region.
width number The width of the rectangular region.
height number The height 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
x number The x-coordinate of the upper-left corner of the rectangular region.
y number The y-coordinate of the upper-left corner of the rectangular region.
width number The width of the rectangular region.
height number The height 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
x number The x-coordinate of the upper-left corner of the rounded rectangle.
y number The y-coordinate of the upper-left corner of the rounded rectangle.
width number The width of the rounded rectangle.
height number The height 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 number[] An array specifying the bounds [x, y, width, height] where the string will be drawn.
pen (optional) PdfPen The pen that determines the stroke color, width, and style of the string.
brush (optional) PdfBrush The brush that determines the fill color and texture of the string.
format (optional) 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 Object 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 number[] Rectangle structure that represents the new clip region, specified as [x, y, width, height].
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
x number x-coordinate of the translation.
y number y-coordinate of the translation.

Returns void