Add Circle Shapes to PDF in Python

Add Circle object

Aspose.PDF for Python via .NET lets you add Circle shapes to PDF pages through the Graph class. Use circles for diagrams, annotations, and simple visual elements.

Follow the steps below:

  1. Create Document instance.
  2. Create Graph object with certain dimensions.
  3. Set border for Graph object.
  4. Add Graph object to paragraphs collection of page.
  5. Save our PDF file.
import aspose.pdf as ap
import aspose.pdf.drawing as drawing

def add_circle(outfile: str):
    document = ap.Document()
    page = document.pages.add()
    graph = drawing.Graph(400, 200)
    graph.border = ap.BorderInfo(ap.BorderSide.ALL, ap.Color.green)

    circle = drawing.Circle(100, 100, 40)
    circle.graph_info.color = ap.Color.green_yellow
    graph.shapes.add(circle)

    page.paragraphs.add(graph)
    document.save(outfile)

Our drawn circle will look like this:

Drawing Circle

Create Filled Circle Object

This example shows how to add a circle and fill it with color.

import aspose.pdf as ap
import aspose.pdf.drawing as drawing

def add_circle_filled(outfile: str):
    document = ap.Document()
    page = document.pages.add()
    graph = drawing.Graph(400, 200)
    graph.border = ap.BorderInfo(ap.BorderSide.ALL, ap.Color.green)

    circle = drawing.Circle(100, 100, 40)
    circle.graph_info.color = ap.Color.green_yellow
    circle.graph_info.fill_color = ap.Color.green
    circle.text = ap.text.TextFragment("Circle")
    graph.shapes.add(circle)

    page.paragraphs.add(graph)
    document.save(outfile)

Result of adding a filled circle:

Filled Circle