Hello
Is there any way to draw a rectangle in existing pdf ?
thanks
shailendra mishra
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sharon WhitePosted Mar 26, 2013, 1:30 AM
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);