Hello
Is there any way to draw a rectangle in existing pdf ?
thanks
shailendra mishra
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sharon White50 reputationPosted Mar 25, 2013, 9:30 PM EDT
Here is my code to draw rectangle in existing PDF document. But I don't use itextpdf but another .NET PDF component.
PdfDocument document = new PdfDocument();
document.LoadFromFile("Sample");
PdfPageBase page = document.Pages[0];
//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(10, 350), new Size(120, 120)));
page.Canvas.DrawRectangle(pen1, new Rectangle(new Point(350, 350), new Size(160, 120)));
page.Canvas.DrawRectangle(brush, new RectangleF(new Point(158, 350), new SizeF(160, 120)));
//restor graphics
page.Canvas.Restore(state);