Add Arc Shapes to PDF in Java
Contents
[
Hide
]
Aspose.PDF for Java uses Graph together with shape objects such as Arc and Line to render vector graphics.
Add arc outlines
- Create a new PDF Document.
- Add a Page to the document.
- Create a Graph container and add it to the page.
- Create the Arc shape and configure its geometry.
- Add the Arc to the Graph container.
- Set the shape properties required by the example, including Color.
- Save the output PDF Document.
public static void addArc(Path outputFile) {
try (Document document = new Document()) {
Page page = document.getPages().add();
Graph graph = new Graph(400.0, 400.0);
graph.setBorder(new BorderInfo(BorderSide.All, Color.getGreen()));
Arc arc1 = new Arc(100, 100, 95, 0, 90);
arc1.getGraphInfo().setColor(Color.getGreenYellow());
graph.getShapes().addItem(arc1);
page.getParagraphs().add(graph);
document.save(outputFile.toString());
}
}
The full example adds three arcs with different radii, angles, and colors to the same graph.
Add a filled arc segment
- Create a new PDF Document.
- Add a Page to the document.
- Create a Graph container and add it to the page.
- Create the Line shape and configure its coordinates.
- Create the Arc shape and configure its geometry.
- Add the Line and Arc to the Graph container.
- Save the output PDF Document.
public static void addArcFilled(Path outputFile) {
try (Document document = new Document()) {
Page page = document.getPages().add();
Graph graph = new Graph(400.0, 400.0);
graph.setBorder(new BorderInfo(BorderSide.All, Color.getGreen()));
Arc arc = new Arc(100, 100, 95, 0, 90);
arc.getGraphInfo().setFillColor(Color.getGreenYellow());
graph.getShapes().addItem(arc);
Line line = new Line(new float[]{195, 100, 100, 100, 100, 195});
line.getGraphInfo().setFillColor(Color.getGreenYellow());
graph.getShapes().addItem(line);
page.getParagraphs().add(graph);
document.save(outputFile.toString());
}
}