We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to draw a rounded corner rectangle?

How to draw a rounded corner rectangle in PDF document?

The rounded corner rectangle can be draw in the PDF document using the GraphicsPath class. Please find the code example and sample below for the same.

C#:

//Create a new document

PdfDocument doc = new PdfDocument();

doc.PageSettings.Margins.All = 0;

//Add a new page

PdfPage page = doc.Pages.Add();

//create the Rectangle

RectangleF rect = new RectangleF(100, 100, 100, 100);

int dimension = 30;

//Create the graphics path

GraphicsPath graphicsPath = new GraphicsPath();

//Draw the rounded rectangle as separate 4 arcs with same dimensions of width and height

graphicsPath.AddArc(rect.X, rect.Y, dimension, dimension, 180, 90);

graphicsPath.AddArc(rect.X + rect.Width - dimension, rect.Y, dimension, dimension, 270, 90);

graphicsPath.AddArc(rect.X + rect.Width - dimension, rect.Y + rect.Height - dimension, dimension, dimension, 0, 90);

graphicsPath.AddArc(rect.X, rect.Y + rect.Height - dimension, dimension, dimension, 90, 90);

//close path

graphicsPath.CloseFigure();

//Get the path points

PointF[] points = graphicsPath.PathPoints;

//Get the path types

byte[] pathTypes = graphicsPath.PathTypes;

//Drawing the Path in Pdf Document

PdfPath drawPath = new PdfPath(PdfPens.Black, points, pathTypes);

//Draw the pdf path

page.Graphics.DrawPath(PdfPens.Black, drawPath);

//Save the Pdf Document

doc.Save("Sample.pdf");

//Close the document

doc.Close(true);

//Dispose the Graphics Path

graphicsPath.Dispose();

Sample link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfSample-108599372

Article ID: Published Date: Last Revised Date: Platform: Control:
6004 01/19/2016 01/19/2016 Windows Forms PDF
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.