How to Draw Circles in PDF

In the last article, we mentioned how to draw rectangles in PDF. This article will show you how to draw circles in PDF with the same .NET PDF componentSpire.PDF for .NET.

What You Need:

How to Draw Circles in PDF via Spire.PDF

By using Spire.PDF, it’s very easy to draw a circle in PDF document. Make sure Spire.PDF and Visual Studio are correctly installed on system. Follow the instructions below to draw circles in PDF.

Step 1 Create Project

Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under “C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project.

Step 2 Create PDF document with Page

Create a PDF document and a Page for drawing circles on.
[C#]

            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page = doc.Pages.Add();

[VB.NET]

			'Create a pdf document.
			Dim doc As New PdfDocument()

			' Create one page
			Dim page As PdfPageBase = doc.Pages.Add()

Step 3 Draw Circle in PDF

Spire.PDF allows developers to draw circles and enables to set styles like adding color.
[C#]

            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            PdfPen pen = new PdfPen(Color.Red, 0.1f);
            PdfBrush brush = new PdfSolidBrush(Color.RoyalBlue);

            page.Canvas.DrawPie(pen, 23, 25, 60, 90, 360, 360);

            //restor graphics
            page.Canvas.Restore(state);

[VB.NET]

			'save graphics state
			Dim state As PdfGraphicsState = page.Canvas.Save()

			Dim pen As New PdfPen(Color.Red, 0.1f)
			Dim brush As PdfBrush = New PdfSolidBrush(Color.RoyalBlue)

			page.Canvas.DrawPie(pen, 23, 25, 60, 90, 360, 360)

			'restor graphics
			page.Canvas.Restore(state)

Step 4 Save

Use the simple code below to save the document as .pdf format.
[C#]

            doc.SaveToFile("Circles.pdf");

[VB.NET]

			doc.SaveToFile("Circles.pdf")

Press F5 to start the project and a PDF will be generated in the project bin->debug folder. Let’s check out the effect screenshot.
Effective Screenshot:


Full Sample Code:
[C#]

using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

namespace Circles
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page = doc.Pages.Add();

            //save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            PdfPen pen = new PdfPen(Color.Red, 0.1f);
            PdfBrush brush = new PdfSolidBrush(Color.RoyalBlue);

            page.Canvas.DrawPie(pen, 23, 25, 60, 90, 360, 360);

            //restor graphics
            page.Canvas.Restore(state);

            doc.SaveToFile("Circles.pdf");
        }
    }
}

[VB.NET]

Imports Spire.Pdf
Imports Spire.Pdf.Graphics

Namespace Circles
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			'Create a pdf document.
			Dim doc As New PdfDocument()

			' Create one page
			Dim page As PdfPageBase = doc.Pages.Add()

			'save graphics state
			Dim state As PdfGraphicsState = page.Canvas.Save()

			Dim pen As New PdfPen(Color.Red, 0.1f)
			Dim brush As PdfBrush = New PdfSolidBrush(Color.RoyalBlue)

			page.Canvas.DrawPie(pen, 23, 25, 60, 90, 360, 360)

			'restor graphics
			page.Canvas.Restore(state)

			doc.SaveToFile("Circles.pdf")
		End Sub
	End Class
End Namespace

More about Spire.PDF
Spire.PDF is a PDF document creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more…

Related Articles:

  1. How to Draw Rectangles in PDF
  2. How to Draw Circles in PDF
  3. How to Draw Arcs in PDF
  4. How to Draw Ellipses in PDF

Leave a Reply