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 “<>” with
“Doctor”. Similarly, after SetMatchStrings(“Beginning…”, “…ending.”),
AddString(“TITLE”, “Doctor”) will replace “Beginning…TITLE…ending.” with “Doctor”.