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

44 views
Skip to first unread message

Support

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

Q:

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

[#pU#]

[#PC#]
 
with text from a database.
 
This is similar to your ContentReplacer sample (http://www.pdftron.com/pdfnet/samplecode.html#ContentReplacer) 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 ()?
 
--------
A:
 
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. 

 

@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 "<<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