Using ContentReplacer to fill-in or modify PDF template based on variable information

Skip to first unread message


Nov 14, 2013, 9:15:44 PM11/14/13


We need to replace fields / text areas in PDF like
[the story]


with text from a database.
This is similar to your ContentReplacer sample ( however it does not seem to allow spaces in field name. 

In addition, can we replace a word with the new replacer if it is not in []?

Can we replace in a different enclosing character set like {} or ()?
Starting with V6.1 pdftron.PDF.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. Also the field names can now include spaces, dashes, and underscore characters.


The relevant documentation is:


ContentReplacer.SetMatchStrings(string start_str, string end_str)



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
0 new messages