Click or drag to resize

ContentReplacer Class

ContentReplacer is a utility class for replacing content (text and images) in existing PDF (template) documents. Users can replace content in a PDF page using the following operations: - Replace an image that exists in a target rectangle with a replacement image. - Replace text that exists in a target rectangle with replacement text. - Replace all instances of a specially marked string with replacement string.
Examples
The following code replaces an image in a target region. It also replaces the text "[NAME]" and "[JOB_TITLE]" with "John Smith" and "Software Developer" respectively. Notice the square braces ('[' and ']') on the target strings in the original PDFDoc. These square braces are not included in the actual function calls below, as they're implicitly added.
PDFDoc doc("../../TestFiles/BusinessCardTemplate.pdf");
doc.InitSecurityHandler();
ContentReplacer replacer;
Page pg = doc.GetPage(1);
Image img = Image::Create(doc, "../../TestFiles/peppers.jpg");
replacer.AddImage(page.GetMediaBox(), img.GetSDFObj());
replacer.AddString("NAME", "John Smith");
replacer.AddString("JOB_TITLE", "Software Developer");
replacer.Process(page);
Inheritance Hierarchy
SystemObject
  pdftron.PDFContentReplacer

Namespace:  pdftron.PDF
Assembly:  pdftron (in pdftron.dll) Version: 255.255.255.255
Syntax
public sealed class ContentReplacer : IClosable

The ContentReplacer type exposes the following members.

Constructors
  NameDescription
Public methodContentReplacer
Create a new ContentReplacer object, to which replacement rules will be added. The same object can be used to 'Process' multiple pages.
Top
Methods
  NameDescription
Public methodAddImage
Replace the image that best fits 'target_region' with 'replacement_image'.
Public methodAddString
Any text of the form "[template_text]" will be replaced by "replacement_text".
Public methodAddText
All text inside 'target_region' will be deleted and replaced with 'replacement_text'.
Public methodClose
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodProcess
Public methodSetMatchStrings
Change the delimiters from '[' and ']' to arbitary strings.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
See Also