How do I create a digital signature annotation and set its appearance?

186 views
Skip to first unread message

Support

unread,
May 7, 2009, 8:40:56 PM5/7/09
to PDFTron PDFNet SDK
Q: I need a sample of how to create a signature and set its appearance
stream.
I will populate the signature data, but I need to create a signature
annotation and set its appearance (to a scanned image of a signature)

Can you provide me with a sample?

---------
A: Sample code to create a digital signature and set its appearance:

Field sig = doc.FieldCreate("sig", Field.Type.e_signature);
pdftron.PDF.Annots.Widget a = pdftron.PDF.Annots.Widget.Create(sdfdoc,
new Rect(50, 550, 350, 600), sig); a.SetAppearance
(CreateSignatureAppearance(doc));
page.AnnotPushBack(a);

static Obj CreateSignatureAppearance(PDFDoc doc)
{
ElementBuilder b = new ElementBuilder();
ElementWriter w = new ElementWriter();
w.Begin(doc);

pdftron.PDF.Image img = pdftron.PDF.Image.Create(doc,
"signature.png");
int width = img.GetImageWidth();
int height = img.GetImageHeight();
Element img_element = b.CreateImage(img, 0, 0, width, height);
w.WritePlacedElement(img_element);

Obj stm = w.End();

// Set the bounding box
stm.PutRect("BBox", 0, 0, width, height);
stm.PutName("Subtype", "Form");

w.Dispose();
b.Dispose();

return stm;
}

You can see a digital signature annotation when viewing the file in
Acrobat. In order to see the image you need to switch off 'Highlight
Fields' option in the upper right corner.
Reply all
Reply to author
Forward
0 new messages