Problem with ContentReplacer

75 views
Skip to first unread message

Mike McFarland

unread,
Nov 8, 2013, 4:41:00 PM11/8/13
to pdfne...@googlegroups.com
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
LetterOut.pdf

Support

unread,
Nov 14, 2013, 8:50:44 PM11/14/13
to pdfne...@googlegroups.com
 
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. 
 
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 "<<TITLE>>" with 
    "Doctor". Similarly, after SetMatchStrings("Beginning...", "...ending."), 
     AddString("TITLE", "Doctor") will replace "Beginning...TITLE...ending." with "Doctor". 
Reply all
Reply to author
Forward
0 new messages