Can I replace images / text in a PDF template using PDFNet?

136 views
Skip to first unread message

Support

unread,
Apr 23, 2008, 6:46:24 PM4/23/08
to PDFTron PDFNet SDK
Q: I would like to know whether I can use PDFNet SDK for the
following:

* inspect a PDF for signature placeholder images and replace them with
an arbitrary image, maintaining document position, size, and layer
depth in the render order. (Placeholder images can be identified via
whatever works best - EXIF data, md5sum, or even binary size if that
is the best we can do).

* inspect a PDF for placeholder text area and replace it with
arbitrary text. This sounds like trouble dealing with wraping, etc.
Perhaps delete the text object, and insert a form input element with
the same typographic properties? Better ideas?

Can I use PDFNet to achieve this? I looked through the PDFNet SDK
samples and saw a few things that looked promising, but figured I
would ask my question directly.

-----
A: You can use PDFNet SDK to implement your requirements.

As a starting point you may want to take a look at ElementEdit sample
project (http://www.pdftron.com/net/samplecode.html#ElementEdit).

There are couple of approaches to implement image swapping. If you
only want to replace images on a given page without modifying image
position/size you could simply swap the XObject reference.
Alternatively you would need to 'edit' the page as shown in
ElementEdit sample.

For additional information you may want to search this forum for
keywords such as "ElementEdit", "replace image", "optimize image",
etc.

For an example of how to add text to an existing page you may want to
take a look at ElementBuilder sample project. Essentially you would
need to specify explicit layout (positioning information).

A quick and dirty way to place a multi-line text within a given
rectangle would be to create a new text widget annotation, set multi-
line flag to true, call field.RefreshAppearance(), followed by
field.FlattenField(). For a concrete example of how to create a text
field please take a look at InteractiveForms sample project (http://
www.pdftron.com/net/samplecode.html#InteractiveForms). So the
pseudocode may look as follows:

// In C++
Field fld= pdfdoc.FieldCreate("Text000", Field::e_text, "My text 1. My
text 2. My text 3.", ""); fld.SetFlag(Field::Flag::e_multiline, true);
Annot txt_box = Annot::CreateWidget(pdfdoc, Rect(50, 550, 350, 600),
fld);

// Add the annotation to a given page
page.AnnotPushBack(txt_box);

// Merge the annotation with the page content fld.RefreshAppearance();
fld.FlattenField(page);

Code for C#, JAVA, VB.NET is along the same lines.
Reply all
Reply to author
Forward
0 new messages