Rectangle without fill (only borders)

How can I draw a rectangle without filled with colors. I want to draw the rectangle only with borders. How can I?


2 Replies 1 reply marked as answer

IJ Irfana Jaffer Sadhik Syncfusion Team May 15, 2023 05:52 AM UTC

You can able to draw a rectangle with a PdfPen instead of a PdfBrush. this will draw a rectangle with a border alone instead of a fill color. Please use the below code snippet:

 //Create a new PDF document

PdfDocument document = new PdfDocument();

//Add a page to the document

PdfPage page = document.Pages.Add();

//Initialize PdfPen for drawing the rectangle

PdfPen pen = new PdfPen(Color.Green);

//Set the bounds for the rectangle

RectangleF bounds = new RectangleF(10, 10, 100, 50);

//Draw the rectangle on a PDF document

page.Graphics.DrawRectangle(pen, bounds);

//Save the PDF document

document.Save("Output.pdf");

//Close the instance of PdfDocument

document.Close(true);


output:

Try this on your end and let us know the result


Marked as answer

KD Kodeeswaran Duraisamy May 15, 2023 11:01 AM UTC

Working!!! Thanks


Loader.
Up arrow icon