Q:
I am looking at PDF tools and in particular I am looking for a tool that can search and replace text in a pdf. I think PDFNet can do it but before I get to far I would like to make sure. I am on a very short timeline.
Can PDFNet search and replace strings in a pdf?
Do you have a code example of doing this?
Which versions do I need at a minimum?
Any help would be of great benefit.
A:
If you are working with PDF templates, you would use the ContentReplacer like this:
ContentReplacer replacer = new ContentReplacer();
replacer.AddString(“NAME”,“John Smith”);
replacer.Process(doc.GetPage(1));
This would replace any instances of the template string “[NAME]” with “John Smith”
Please see the ContentReplacerTest sample in the trial package.
Alternatively, you can use TextSearch class to find the rectangle region of the text to replace.
Then use ContentReplacer to replace all existing text in that rectangle with your new text.
Please see the TextSearchTest sample for this.
ContentReplacer itself is a utility class that is using ElementWriter/ElementBuilder as shown in the ElementEdit sample:
http://www.pdftron.com/pdfnet/samplecode.html#ElementEdit
ContentReplacer was added in PDFNet v.5.8, ElementWriter/ElementBuilder were part of the SDK for a long time.