How to I added a path/rectangle to an existing PDF?

Q:

I am simply trying to put a rectangle on a PDF, say white to block out certain areas but I cant get the code to run, can you point me to some sample code please.

Just open a pdf, add a rectangle save and close.

A:

I suggest taking a look at ElementBuilder sample (included as part of the SDK):

http://www.pdftron.com/pdfnet/samplecode.html#ElementBuilder

For example:

ElementBuilder eb = new ElementBuilder();

ElementWriter writer = new ElementWriter();

Page page = doc.GetPage(1);

writer.Begin(page);

Element element = eb.CreateRect(new Rect(100, 100, 300, 400));

element.SetPathFill(true);

writer.WriteElement(element);

writer.End(); // save changes to the current page

}

Btw. it you want to redact PDF, the proper tool to use is ‘pdftron.PDF.Redacrtor’ (http://www.pdftron.com/pdfnet/samplecode.html#PDFRedact). Adding stuff on top of page does not really remove sensitive info.