Problem with ContentReplacer

Hello,

I seem to be having an issue using the ContentReplacer. The text to be replaced is never changed and the replacing text is put in the middle of the page. Also when replacing text, all images are removed in the saved document. I am using PDFNet 6.0.1.0

This is my method:

PDFNet.Initialize();

string fileIn1 = @“C:\LetterIn4.pdf”;
string fileOut = @“C:\LetterOut.pdf”;
try {
PDFDoc doc = new PDFDoc(fileIn1);
doc.InitSecurityHandler();
ContentReplacer replacer = new ContentReplacer();
Page page = doc.GetPage(1);
//replace the text place holders
replacer.AddString(“FIRSTNAME”, “William”);
// finally, apply
replacer.Process(page);
doc.Save(fileOut, 0);
doc.Close();
}
catch (PDFNetException e) {
throw new NotImplementedException(e.Message);
}

The attached file: LetterIn4.pdf is my input document and
LetterOut.pdf is the resulting document.

Any ideas?

LetterIn4.pdf (71.6 KB)

LetterOut.pdf (110 KB)

Hi Mike,

This issue should be fixed in PDFNet V6.1 that was just announced (http://www.pdftron.com/pdfnet/whatsnew.html).

Btw. starting with 6.1 the ContentReplacer includes a new method SetMatchStrings() that can be used to match string that are surrounded by custom delimiters. So instead of [FIELD_ID ] you could use <<FIELD_ID>> etc:

The relevant documentation is:

Change the delimiters from ‘[’ and ‘]’ to arbitary strings.

@param start_str - The starting delimiter string.
@param end_str - The ending delimiter string.

@note
While empty strings are allowed as delimiters, a warning is displayed.
Otherwise there are no restrictions. For example, after SetMatchStrings("<<", “>>”),
AddString(“TITLE”, “Doctor”) will replace any text consisting of “<>” with
“Doctor”. Similarly, after SetMatchStrings(“Beginning…”, “…ending.”),
AddString(“TITLE”, “Doctor”) will replace “Beginning…TITLE…ending.” with “Doctor”.

On Friday, November 8, 2013 1:41:00 PM UTC-8, Mike McFarland wrote:

Hello,

I seem to be having an issue using the ContentReplacer. The text to be replaced is never changed and the replacing text is put in the middle of the page. Also when replacing text, all images are removed in the saved document. I am using PDFNet 6.0.1.0

This is my method:

PDFNet.Initialize();

string fileIn1 = @“C:\LetterIn4.pdf”;
string fileOut = @“C:\LetterOut.pdf”;
try {
PDFDoc doc = new PDFDoc(fileIn1);
doc.InitSecurityHandler();
ContentReplacer replacer = new ContentReplacer();
Page page = doc.GetPage(1);
//replace the text place holders
replacer.AddString(“FIRSTNAME”, “William”);
// finally, apply
replacer.Process(page);
doc.Save(fileOut, 0);
doc.Close();
}
catch (PDFNetException e) {
throw new NotImplementedException(e.Message);
}

The attached file: LetterIn4.pdf is my input document and
LetterOut.pdf is the resulting document.

Any ideas?