PdfPath
16 Dec 20257 minutes to read
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({r: 0, g: 0, b: 0}, 1);
// Create a new PDF path
let path: PdfPath = new PdfPath();
// Add a line to the Graphics path
path.addLine({x: 10, y: 250}, {x: 200, y: 250});
// Draw the path on the PDF page
graphics.drawPath(path, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Properties
fillMode PdfFillMode
Gets the fill mode.
lastPoint Point
Gets the last point of the path.
pathPoints Array
Gets the array of points that represent the x and y coordinates defining the path.
pathTypes PathPointType[]
Gets the types of the corresponding points in the path.
Methods
addArc
Adds an arc within a bounding rectangle using the angles that define the start and sweep of the arc.
| Parameter | Type | Description |
|---|---|---|
| bounds | Rectangle |
The bounding rectangle. |
| startAngle | number |
The start angle of the arc. |
| sweepAngle | number |
The angle between start angle and the end of the arc. |
Returns void
addBezier
Adds a Bezier curve to the path using specified coordinates for the start point, two control points, and the 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. |
Returns void
addEllipse
Adds an ellipse to the path.
| Parameter | Type | Description |
|---|---|---|
| bounds | Rectangle |
The bounds of the ellipse. |
Returns void
addLine
Adds a line segment to the path.
| Parameter | Type | Description |
|---|---|---|
| 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
addPath
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({r: 0, g: 0, b: 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([{x: 50, y: 50}, {x: 100, y: 50}, {x: 100, y: 100}, {x: 50, y: 100}, {x: 50, y: 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
addPath
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
addPie
Adds a pie slice to the path.
| 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 parameter to the end of the pie slice. |
Returns void
addPolygon
Adds a polygon to the path.
| Parameter | Type | Description |
|---|---|---|
| points | Array |
The points of the polygon, where each point representing the x and y coordinates. |
Returns void
addRectangle
Adds a rectangle to the path.
| Parameter | Type | Description |
|---|---|---|
| bounds | Rectangle |
The bounding rectangle. |
Returns void
closeAllFigures
Closes all non-closed figures in the path.
Returns void
closeFigure
Closes all open figures in the path.
Returns void
closeFigure
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
startFigure
Starts a new figure in the path.
Returns void