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. Image for the cookie policy date

Removing page graphics

I need to remove the graphics from a page in the PDF.

I started by drawing a line and then trying to remove it, using the Restore() function but it didn't work, I used the following code:

PdfLoadedDocument lDoc = new PdfLoadedDocument(stream);
PdfGraphics graphics = lDoc.Pages[0].Graphics;

PdfGraphicsState state = graphics.Save();
           
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);
graphics.DrawString("New page - Test", font, PdfBrushes.Red, new System.Drawing.PointF(200, 10));

PdfViewer.LoadDocument(lDoc);

and to delete the graphics:

graphics.Restore(state);


What should I do to remove the graphics ?

1 Reply

KK Karthik Krishnaraj Syncfusion Team June 2, 2015 12:11 PM UTC

Hi Karine,
Thank you for using syncfusion products,
As per your query regarding “Need to remove the graphics from the page”, we don’t have support to remove the page graphics. Here you used graphics.Restore() function to delete the page graphics, whereas the purpose of graphics.Restore() function is to restore the saved graphics state not to delete it. We can able to delete only the annotations from the page, I have attached a simple sample regarding this in the below link, please check through it and let us know if these helps.
Sample Link:
http://www.syncfusion.com/downloads/support/directtrac/139746/ze/RemoveGraphicsWRT-1791672907
Thanks,
Karthik

Loader.
Up arrow icon