Articles in this section
Category / Section

How to draw the circular shape image in a PDF using C# and VB.NET

5 mins read

Syncfusion Essential® PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can draw an image in a circular shape in the PDF document using C# and VB.NET.

Steps to draw a circular shape image on a PDF programmatically:

  1. Create a new C# console application project. Create a new C# console application project
  2. Install the Syncfusion.Pdf.WinForms NuGet packages as reference to your .NET Framework application from NuGet.org. NuGet package reference
  3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics

 

  1. Use the following code snippet to create circular image in PDF.

C#

//Create a PdfDocument
PdfDocument document = new PdfDocument();
 
//Add page to PdfDocument
PdfPage page = document.Pages.Add();
 
//Create image from file
PdfImage image = PdfImage.FromFile("../../data/Xamarin_JPEG.jpg");
 
PdfGraphics pageGraphics = page.Graphics;
 
//Save Pdf graphics state
pageGraphics.Save();
 
//Create GraphicsPath
GraphicsPath path = new GraphicsPath();
 
//Add rectangle to GraphicsPath
path.AddEllipse(new RectangleF(150, 50, 200, 200));
 
//Create PdfPath with pathPoints and pathTypes
PdfPath pdfpath = new PdfPath(path.PathPoints, path.PathTypes);
 
//Clip the rectangle bounds in page graphics
pageGraphics.SetClip(pdfpath);
 
//Draw the image in page rectangle clip bounds
pageGraphics.DrawImage(image, new RectangleF(150, 50, 200, 200));
 
//Restore the page graphics
pageGraphics.Restore();
 
//Save the PDF document
document.Save("Circular_Image.pdf");
 
//Close the document
document.Close(true);
 
//This will open the PDF file so, the result will be seen in default PDF viewer
Process.Start("Circular_Image.pdf");

 

VB.NET

'Create a PdfDocument
Dim document As New PdfDocument()
 
'Add page to PdfDocument
Dim page As PdfPage = document.Pages.Add()
 
'Create image from file
Dim image As PdfImage = PdfImage.FromFile("../../data/Xamarin_JPEG.jpg")
 
Dim pageGraphics As PdfGraphics = page.Graphics
 
'Save Pdf graphics state
pageGraphics.Save()
 
'Create GraphicsPath
Dim path As New GraphicsPath()
 
'Add rectangle to GraphicsPath
path.AddEllipse(New RectangleF(150, 50, 200, 200))
 
'Create PdfPath with pathPoints and pathTypes
Dim pdfpath As New PdfPath(path.PathPoints, path.PathTypes)
 
'Clip the rectangle bounds in page graphics
pageGraphics.SetClip(pdfpath)
 
'Draw the image in page rectangle clip bounds
pageGraphics.DrawImage(image, New RectangleF(150, 50, 200, 200))
 
'Restore the page graphics
pageGraphics.Restore()
 
'Save the PDF document
document.Save("Circular_Image.pdf")
 
'Close the document
document.Close(True)
 
'This will open the PDF file so, the result will be seen in default PDF Viewer
Process.Start("Circular_Image.pdf")

 

A complete working sample can be downloaded from Circular Image Sample.zip

By executing the program, you will get the PDF document as follows. Screenshot of output PDF file

Take a moment to peruse the documentation for working with images, where you will find other options like inserting, replacing image in PDF document, and image masking.

Refer here to explore the rich set of Syncfusion Essential® PDF features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion

I hope you enjoyed learning about how to draw the circular shape image in a PDF using C# and VB.NET.

You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied