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