Implements graphics path, which is a sequence of primitive graphics elements.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Gets the graphics object of the PDF page
let graphics: PdfGraphics = page.graphics;
// Create a new pen
let pen: PdfPen = new PdfPen([0, 0, 0], 1);
// Create a new PDF path
let path: PdfPath = new PdfPath();
// Add a line to the Graphics path
path.addLine(10, 250, 200, 250);
// Draw the path on the PDF page
graphics.drawPath(path, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
PdfFillMode
Gets the fill mode.
number[]
Gets the last point of the path.
Array
Gets the array of points that represent the x and y coordinates defining the path.
PathPointType[]
Gets the types of the corresponding points in the path.
Adds an arc within a bounding rectangle using the angles that define the start and sweep of the arc.
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. |
startAngle | number |
The start angle of the arc. |
sweepAngle | number |
The angle between start angle and the end of the arc. |
Returns void
Adds a Bezier curve to the path using specified coordinates for the start point, two control points, and the 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. |
Returns void
Adds an ellipse to the path.
Parameter | Type | Description |
---|---|---|
x | number |
The x-coordinate of the upper-left corner of the rectangular region that bounds the ellipse. |
y | number |
The y-coordinate of the upper-left corner of the rectangular region that bounds the ellipse. |
width | number |
The width of the bounding rectangle for the ellipse. |
height | number |
The height of the bounding rectangle for the ellipse. |
Returns void
Adds a line segment to the path.
Parameter | Type | Description |
---|---|---|
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
Appends the specified path to this one.
Parameter | Type | Description |
---|---|---|
path | PdfPath |
The path to append.typescript<br>// Load an existing PDF document<br>let document: PdfDocument = new PdfDocument(data, password);<br>// Access the first page<br>let page: PdfPage = document.getPage(0);<br>// Get the graphics object 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>// Create a new PDF path<br>let path1: PdfPath = new PdfPath();<br>// Add path points and path type<br>let path2: PdfPath = new PdfPath([[50, 50], [100, 50], [100, 100], [50, 100], [50, 50]], [0, 1, 1, 1, 1]);<br>path1.addPath(path2);<br>// Draw the path on the PDF page<br>graphics.drawPath(path1, pen);<br>// Save the document<br>document.save('output.pdf');<br>// Destroy the document<br>document.destroy();<br> |
Returns void
Appends the specified path points and their types to this path.
Parameter | Type | Description |
---|---|---|
pathPoints | Array |
The path points to append. |
pathPointTypes | PathPointType[] |
The types of the path points. |
Returns void
Adds a pie slice to the path.
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 parameter to the end of the pie slice. |
Returns void
Adds a polygon to the path.
Parameter | Type | Description |
---|---|---|
points | Array |
The points of the polygon, where each point is an array of two numbers representing the x and y coordinates. |
Returns void
Adds a rectangle to the path.
Parameter | Type | Description |
---|---|---|
x | number |
The x-coordinate of the upper-left corner of the rectangle. |
y | number |
The y-coordinate of the upper-left corner of the rectangle. |
width | number |
The width of the rectangle. |
height | number |
The height of the rectangle. |
Returns void
Closes all non-closed figures in the path.
Returns void
Closes all open figures in the path.
Returns void
Closes all non-closed figures in the path.
Parameter | Type | Description |
---|---|---|
index | number |
The optional index of the figure to close. If not provided, the last figure is closed. |
Returns void
Starts a new figure in the path.
Returns void