This article describes how to add circle to PDF using C#. It provides the step-wise logic to write this application along with the running sample code to add circle in Adobe Acrobat using C#. Different formatting options are also discussed along with the environment configurations.
Steps to Add a Circle to a PDF using C#
- Set the environment to add Aspose.PDF for .NET to the project to add a circle to the PDF
- Create a PDF file using the Document object and add a page to it
- Create a graph object and a circle with a specified color
- Add the circle to the shapes collection of the graph object
- Add the resultant graph object to the paragraph collection of the selected page
- Save the resultant PDF file with a circle in it
These steps explain the process to add circle to PDF document using C# such that all the necessary classes and methods are highlighted and links are provided for more details. It shows that for drawing any shape on a PDF page, you need to add a Graph object by providing its dimensions and then create the required shape like a circle for adding it to the graph object. Once the graph object is filled with the drawing objects, the graph object is added to the PDF page as a paragraph item.
Code to Draw a Circle in Adobe Acrobat using C#
using Aspose.Pdf; | |
using Aspose.Pdf.Drawing; | |
namespace AsposeProjects | |
{ | |
class Program | |
{ | |
static void Main(string[] args) // Main function to draw circle in PDF using C# | |
{ | |
// Initialize license | |
License lic = new License(); | |
lic.SetLicense("Aspose.Total.lic"); | |
// Instantiate Document instance | |
var document = new Document(); | |
// Add an empty page | |
var page = document.Pages.Add(); | |
// Create Graph object | |
var graph = new Aspose.Pdf.Drawing.Graph(400, 200); | |
// Create a circle | |
var circle = new Circle(100, 100, 40); | |
// Set Circle color | |
circle.GraphInfo.Color = Color.GreenYellow; | |
// Add circle to shapes collection | |
graph.Shapes.Add(circle); | |
// Add Graph object to the page | |
page.Paragraphs.Add(graph); | |
// Save PDF file | |
document.Save("DrawingCircle1_out.pdf"); | |
System.Console.WriteLine("Done"); | |
} | |
} | |
} |
This code demonstrates how to insert a circle in PDF using C# where a Graph object is used to hold the circle and other types of shapes. This graph object has a specified dimension, you can set its border, title, ZIndex and set the flag to create a new page for this item, to name a very few. For the circle object, you can set its position in the graph object, radius, and text.
This article has provided us with details for adding a circle to the PDF. If you want to learn the process to add a watermark to a PDF, refer to the article on how to add watermark to PDF in C#.