Syncfusion AI Assistant

How can I help you?

PdfPath

21 Apr 202622 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

Get fillMode PdfFillMode

Gets the fill mode.

Set fillMode void

Sets the fill mode.

Parameter Type Description
mode PdfFillMode The fill mode of the path.

Get lastPoint Point

Gets the last point of the path.

Get pathPoints Array

Gets the array of points that represent the x and y coordinates defining the path.

Get 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.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(readFromResources('Empty.pdf'));
// 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 arc to the path
path.addArc({x: 10, y: 10, width: 100, height: 200}, 90, 270);
// Draw the path on the PDF page
graphics.drawPath(path, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
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.

// 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 brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Create a new PDF path
let path: PdfPath = new PdfPath();
// Add a Bezier curve to the path
path.addBezier({x: 100, y: 100}, {x: 150, y: 150}, {x: 50, y: 250}, {x: 100, y: 300});
// Draw the path on the PDF page
graphics.drawPath(path, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
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.

// 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 brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Create a new PDF path
let path: PdfPath = new PdfPath();
// Add an ellipse to the path
path.addEllipse({x: 200, y: 200, width: 100, height: 50});
// Draw the path on the PDF page
graphics.drawPath(path, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounds of the ellipse.

Returns void

addLine

Adds a line segment to the path.

// 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 segment to the 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();
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.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Get 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 path1: PdfPath = new PdfPath();
// Add path points and path type
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]);
path1.addPath(path2);
// Draw the path on the PDF page
graphics.drawPath(path1, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
path PdfPath The path to append.

Returns void

addPath

Appends the specified path points and their types to this path.

// 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 path1: PdfPath = new PdfPath();
// Add path points and their types
path1.addPath([{x: 50, y: 50}, {x: 100, y: 100}], [PathPointType.start, PathPointType.line]);
// Draw the path on the PDF page
graphics.drawPath(path1, pen);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
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.

// 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 brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Create a new PDF path
let path: PdfPath = new PdfPath();
// Add a pie slice to the path
path.addPie({x: 0, y: 20, width: 100, height: 100}, 270, 45);
// Draw the path on the PDF page
graphics.drawPath(path, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
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.

// 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 brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Create a new PDF path
let path: PdfPath = new PdfPath();
// Add a polygon to the path
path.addPolygon([{x: 200, y: 10}, {x: 300, y: 100}, {x: 150, y: 100}, {x: 200, y: 10}]);
// Draw the path on the PDF page
graphics.drawPath(path, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
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.

// 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 brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Create a new PDF path
let path: PdfPath = new PdfPath();
// Add a rectangle to the path
path.addRectangle({x: 10, y: 20, width: 50, height: 100});
// Draw the path on the PDF page
graphics.drawPath(path, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
Parameter Type Description
bounds Rectangle The bounding rectangle.

Returns void

closeAllFigures

Closes all non-closed figures in the path.

// 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 brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Create a new PDF path
let path: 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]);
// Close all non-closed figures
path.closeAllFigures();
// Draw the path on the PDF page
page.graphics.drawPath(path, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Returns void

closeFigure

Closes all open figures in the path.

// 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 brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Create a new PDF path
let path: 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]);
// Close all open figures
path.closeFigure();
// Draw the path on the PDF page
page.graphics.drawPath(path, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Returns void

closeFigure

Closes all non-closed figures in the path.

// 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 brush
let brush: PdfBrush = new PdfBrush({r: 0, g: 255, b: 255});
// Create a new PDF path
let path: 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]);
// Close the figure at index 1
path.closeFigure(1);
// Draw the path on the PDF page
page.graphics.drawPath(path, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
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.

// 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 brush
let brush: PdfBrush = new PdfBrush([{r: 0, g: 255, b: 255});
// Create a new PDF path
let path: PdfPath = new PdfPath();
// Start a new figure in the path
path.startFigure();
// Add some path points (optional)
path.addLine({x: 50, y: 50}, {x: 100, y: 50});
// Draw the path on the PDF page
graphics.drawPath(path, pen, brush);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();

Returns void