Add Circle Object to PDF file
Contents
[
Hide
]
The following code snippet also work with Aspose.PDF.Drawing library.
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 .NET.
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 Circle()
{
// Create Document instance
var document = new Document();
// Add page to pages collection of PDF file
var page = document.Pages.Add();
// Create Drawing object with certain dimensions
var graph = new Aspose.Pdf.Drawing.Graph(400, 200);
// Set border for Drawing object
var borderInfo = new BorderInfo(BorderSide.All, Color.Green);
graph.Border = borderInfo;
var circle = new Circle(100, 100, 40);
circle.GraphInfo.Color = Color.GreenYellow;
graph.Shapes.Add(circle);
// Add Graph object to paragraphs collection of page
page.Paragraphs.Add(graph);
// Save PDF file
document.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 CircleFilled()
{
// Create Document instance
var document = new Document();
// Add page to pages collection of PDF file
var page = document.Pages.Add();
// Create Drawing object with certain dimensions
var graph = new Aspose.Pdf.Drawing.Graph(400, 200);
// Set border for Drawing object
var borderInfo = new BorderInfo(BorderSide.All, Color.Green);
graph.Border = borderInfo;
var circle = new Circle(100, 100, 40);
circle.GraphInfo.Color = Color.GreenYellow;
circle.GraphInfo.FillColor = Color.Green;
circle.Text = new TextFragment("Circle");
graph.Shapes.Add(circle);
// Add Graph object to paragraphs collection of page
page.Paragraphs.Add(graph);
// Save PDF file
document.Save(dataDir + "DrawingCircle2_out.pdf");
}
Let’s see the result of adding a filled Circle: