Add Circle Object to PDF file
Contents
[
Hide
]
Add Circle object
Like bar graphs, circle graphs can be used to display data in a number of separate categories. Unlike bar graphs, however, circle graphs can be used only when you have data for all the categories that make up the whole. So let’s take a look at adding a Circle object with Aspose.PDF for Java.
Follow the steps below:
-
Create Document instance
-
Create Drawing object with certain dimensions
-
Set Border for Drawing object
-
Add Graph object to paragraphs collection of page
-
Save our PDF file
public static void ExampleCircle() {
// Create Document instance
Document pdfDocument = new Document();
// Add page to pages collection of PDF file
Page page = pdfDocument.getPages().add();
// Create Drawing object with certain dimensions
Graph graph = new Graph(400, 200);
// Set border for Drawing object
BorderInfo borderInfo = new BorderInfo(BorderSide.All, Color.getGreen());
graph.setBorder(borderInfo);
Circle circle = new Circle(100,100,40);
circle.getGraphInfo().setColor(Color.getGreenYellow());
graph.getShapes().add(circle);
// Add Graph object to paragraphs collection of page
page.getParagraphs().add(graph);
// Save PDF file
pdfDocument.save(_dataDir + "DrawingCircle1_out.pdf");
}
Our drawn circle will look like this:
Create Filled Circle Object
This example shows how to add a Circle object that is filled with color.
public static void ExampleFilledCircle() {
// Create Document instance
Document pdfDocument = new Document();
// Add page to pages collection of PDF file
Page page = pdfDocument.getPages().add();
// Create Drawing object with certain dimensions
Graph graph = new Graph(400, 200);
// Set border for Drawing object
BorderInfo borderInfo = new BorderInfo(BorderSide.All, Color.getGreen());
graph.setBorder(borderInfo);
Circle circle = new Circle(100,100,40);
circle.getGraphInfo().setColor(Color.getGreenYellow());
circle.getGraphInfo().setFillColor(Color.getGreenYellow());
graph.getShapes().add(circle);
// Add Graph object to paragraphs collection of page
page.getParagraphs().add(graph);
// Save PDF file
pdfDocument.save(_dataDir + "DrawingCircle2_out.pdf");
}
Let’s see the result of adding a filled Circle: