Knowledgebase (2330)
Children categories
Circles can be defined as the curves traced out by points that move so that its distance from a given point is constant. They are also look as special ellipses in which the two foci are coincident and the eccentricity is “0”. Whatever they are, they are indispensable in PDF document. This section will introduce a solution to draw circles and set their size and position in PDF file via a .NET PDF component Spire.PDF for .NET in C#, VB.NET.
When we draw circles in PDF, we only need to call one method in Spire.PDF: Spire.Pdf.PdfPageBase.Canvas.DrawPie(PdfPen pen, float x, float y, float width, float height, float startAngle, float sweepAngle); Here there are seven parameters in this method. The first one is the class Spire.Pdf.Graphics.PdfPen which can define the color and the outline of the circle. If we change this parameter to be another class Spire.Pdf.Graphics.PdfBrush, we can easily fill the circle with a certain color. The second and third parameters determine the exact distance between the PDF margin and the circle. "float x" decides the distance of left margin with circle, while "float y" means the distance between the top margin with the circle. By setting the fourth and fifth parameters, we can decide the circle width and height. The last two parameters are the start angle and sweep angle when drawing circles. Now please view the circles in PDF as below picture:

Here we can quickly download Spire.PDF for .NET . After adding Spire.Pdf dll in the download Bin folder, we can draw circles in PDF file via Spire.PDF by below code.
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;
namespace pdf_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, 1f);
PdfPen pen1 = new PdfPen(Color.GreenYellow, 2f);
PdfBrush brush = new PdfSolidBrush(Color.DeepSkyBlue);
page.Canvas.DrawPie(pen, 30, 30, 80, 90, 360, 360);
page.Canvas.DrawPie(brush, 150, 30, 100, 90, 360, 360);
page.Canvas.DrawPie(pen1,290, 30, 70, 90, 360, 360);
//restor graphics
page.Canvas.Restore(state);
doc.SaveToFile("Circles.pdf");
System.Diagnostics.Process.Start("Circles.pdf");
}
}
}
Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Namespace pdf_circles
Class Program
Private Shared Sub Main(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, 1F)
Dim pen1 As New PdfPen(Color.GreenYellow, 2F)
Dim brush As PdfBrush = New PdfSolidBrush(Color.DeepSkyBlue)
page.Canvas.DrawPie(pen, 30, 30, 80, 90, 360, _
360)
page.Canvas.DrawPie(brush, 150, 30, 100, 90, 360, _
360)
page.Canvas.DrawPie(pen1, 290, 30, 70, 90, 360, _
360)
'restor graphics
page.Canvas.Restore(state)
doc.SaveToFile("Circles.pdf")
System.Diagnostics.Process.Start("Circles.pdf")
End Sub
End Class
End Namespace
Spire.PDF for .NET is a PDF component that enables users to draw different kinds of shapes in PDF document in C#, VB.NET.
In Euclidean plane geometry, a rectangle is any quadrilateral with four right angles. The term "oblong" is occasionally used to refer to a non-square rectangle. A rectangle with vertices ABCD would be denoted as ABCD. It’s simple for people to draw rectangles in paper. While how about drawing rectangles in PDF document? This section will show you the exact answer. This section will introduce a solution to draw rectangles and set the size and position of rectangles in PDF via a .NET PDF component Spire.PDF for .NET with C#, VB.NET.
In Spire.PDF, there are two classes: Spire.Pdf.Graphics.PdfPen and Spire.Pdf.Granphics.PdfBrush. By using the first class, we can set the color and decide the outline of the PDF rectangle. While the second class can quickly help us fill the rectangles with a color we want. Now let us see this method: Spire.Pdf.PdfPageBase.Canvas.DrawRectangle(PdfPen pen, RectangleF rectangle); There are two parameters passed. One is the PdfPen which I referred above. The other represents the location and size of a rectangle. By calling this method, we can draw rectangles and set their size and position very quickly. Now let us view the rectangles as below picture:

Here we can download Spire.PDF for .NET and install it on system. After adding Spire.Pdf dll, we can draw rectangle in our PDF document as below code:
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;
namespace PDF_rectangles
{
class Program
{
static void Main(string[] args)
{
//create a PDF
PdfDocument pdfDoc = new PdfDocument();
PdfPageBase page = pdfDoc.Pages.Add();
//save graphics state
PdfGraphicsState state = page.Canvas.Save();
//draw rectangles
PdfPen pen = new PdfPen(Color.ForestGreen, 0.1f);
PdfPen pen1 = new PdfPen(Color.Red, 3f);
PdfBrush brush = new PdfSolidBrush(Color.Orange);
page.Canvas.DrawRectangle(pen, new Rectangle(new Point(2, 7), new Size(120, 120)));
page.Canvas.DrawRectangle(pen1, new Rectangle(new Point(350, 7), new Size(160, 120)));
page.Canvas.DrawRectangle(brush, new RectangleF(new Point(158, 7), new SizeF(160, 120)));
//restor graphics
page.Canvas.Restore(state);
pdfDoc.SaveToFile("Rectangles.pdf");
System.Diagnostics.Process.Start("Rectangles.pdf");
}
}
}
Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Namespace PDF_rectangles
Class Program
Private Shared Sub Main(args As String())
'create a PDF
Dim pdfDoc As New PdfDocument()
Dim page As PdfPageBase = pdfDoc.Pages.Add()
'save graphics state
Dim state As PdfGraphicsState = page.Canvas.Save()
'draw rectangles
Dim pen As New PdfPen(Color.ForestGreen, 0.1F)
Dim pen1 As New PdfPen(Color.Red, 3F)
Dim brush As PdfBrush = New PdfSolidBrush(Color.Orange)
page.Canvas.DrawRectangle(pen, New Rectangle(New Point(2, 7), New Size(120, 120)))
page.Canvas.DrawRectangle(pen1, New Rectangle(New Point(350, 7), New Size(160, 120)))
page.Canvas.DrawRectangle(brush, New RectangleF(New Point(158, 7), New SizeF(160, 120)))
'restor graphics
page.Canvas.Restore(state)
pdfDoc.SaveToFile("Rectangles.pdf")
System.Diagnostics.Process.Start("Rectangles.pdf")
End Sub
End Class
End Namespace
Spire.PDF for .NET is a .NET PDF component that can draw different kinds of shapes in PDF document such as Circles, Arcs. Ellipse and Five-pointed Star.
As PDF documents become increasingly popular in business, ensuring their authenticity has become a key concern. Signing PDFs with a certificate-based signature can protect the content and also let others know who signed or approved the document. In this article, you will learn how to digitally sign PDF with an invisible or a visible signature, and how to remove digital signatures from PDF by using Spire.PDF for .NET.
- Add an Invisible Digital Signature to PDF
- Add a Visible Digital Signature to PDF
- Remove Digital Signatures from PDF
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Add an Invisible Digital Signature to PDF
The following are the steps to add an invisible digital signature to PDF using Spire.PDF for .NET.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Load a pfx certificate file while initializing the PdfCertificate object.
- Create a PdfSignature object based on the certificate.
- Set the document permissions through the PdfSignature object.
- Save the document to another PDF file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Security;
namespace AddInvisibleSignature
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
//Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");
//Create a PdfSignature object
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "MySignature");
//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges Or PdfCertificationFlags.AllowFormFill
//Save to another PDF file
doc.SaveToFile("InvisibleSignature.pdf");
doc.Close();
}
}
}

Add a Visible Digital Signature to PDF
The following are the steps to add a visible digital signature to PDF using Spire.PDF for .NET.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Load a pfx certificate file while initializing the PdfCertificate object.
- Create a PdfSignature object and specify its position and size on the document.
- Set the signature details including date, name, location, reason, handwritten signature image, and document permissions.
- Save the document to another PDF file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using System;
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Security;
using Spire.Pdf.Graphics;
namespace AddVisibleSignature
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
//Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");
//Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "MySignature");
RectangleF rectangleF = new RectangleF(doc.Pages[0].ActualSize.Width - 260 - 54, 200, 260, 110);
signature.Bounds = rectangleF;
signature.Certificated = true;
//Set the graphics mode to ImageAndSignDetail
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
//Set the signature content
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "Phone:";
signature.ContactInfo = "0123456";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "USA";
signature.ReasonLabel = "Reason:";
signature.Reason = "I am the author";
signature.DistinguishedNameLabel = "DN:";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;
//Set the signature image source
signature.SignImageSource = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\handwrittingSignature.png");
//Set the signature font
signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Arial Unicode MS", 12f, FontStyle.Regular));
//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;
//Save to file
doc.SaveToFile("VisiableSignature.pdf");
doc.Close();
}
}
}

Remove Digital Signatures from PDF
The following are the steps to remove digital signatures from PDF using Spire.PDF for .NET.
- Create a PdfDocument object.
- Get form widgets from the document through PdfDocument.Form property.
- Loop through the widgets and determine if a specific widget is a PdfSignatureFieldWidget.
- Remove the signature widget using PdfFieldCollection.RemoveAt() method.
- Save the document to another PDF file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Widget;
namespace RemoveSignature
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument("C:\\Users\\Administrator\\Desktop\\VisiableSignature.pdf");
//Get form widgets from the document
PdfFormWidget widgets = doc.Form as PdfFormWidget;
//Loop through the widgets
for (int i = 0; i < widgets.FieldsWidget.List.Count; i++)
{
//Get the specific widget
PdfFieldWidget widget = widgets.FieldsWidget.List[i] as PdfFieldWidget;
//Determine if the widget is a PdfSignatureFieldWidget
if (widget is PdfSignatureFieldWidget)
{
//Remove the widget
widgets.FieldsWidget.RemoveAt(i);
}
}
//Save the document to another PDF file
doc.SaveToFile("RemoveSignatures.pdf");
}
}
}
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.