How do I extract the image from a digital signature

172 views
Skip to first unread message

Ryan

unread,
Aug 21, 2014, 12:40:28 PM8/21/14
to pdfne...@googlegroups.com
Q:

We are working on the digital signature now. As part of our application, we required to extract the signature image. We able to extract the annotations as FDF format. But, we couldn't do the same with signature image. Could you please tell us how do we export the signature image from the pdf ?

-----------------------------------------------------------------------------------

A:

The "signature" annotation widget, which is the visual appearance of the actual underlying digital signature, is not necessarily an image. It can be any arbitrary PDF content.

The code below will isolate the appearance of any annotation, into its own page, which can then be used for a variety of purposes, including converting to image, but could also be used for stamping.

void ProcessElements(ElementReader reader, ElementWriter writer, List<int> visited)
{
   
Element element;
   
while((element = reader.Next()) != null)
   
{
       
if(element.GetType() == Element.Type.e_form)
       
{
           
Obj form_obj = element.GetXObject();
           
if (!visited.Contains(form_obj.GetObjNum())) // if this XObject has not been processed
           
{
               
// recursively process the Form XObject
                visited
.Add(form_obj.GetObjNum());
                writer
.WriteElement(element);
               
ElementWriter new_writer = new ElementWriter();
                reader
.FormBegin();
                new_writer
.Begin(form_obj);
               
ProcessElements(reader, new_writer, visited);

                new_writer
.End();
                reader
.End();
           
}
       
}
       
else
       
{
            writer
.WriteElement(element);
       
}
   
}
}

List<int> visited = new List<int>();

// annot.RefreshAppearance(); // optional
Obj app_obj = annot.GetAppearance();
Page page = doc.PageCreate(Rect(-7200, -7200, 7200, 7200)); // max page dimension in pdf spec

ElementReader reader = new ElementReader();
ElementWriter writer = new ElementWriter();
reader
.Begin(app_obj);

writer
.Begin(page);
ProcessElements(reader, writer, visited);
reader
.End();
writer
.End();

page.SetMediaBox(page.GetVisibleContentBox()); // reduce back to bbox

// at this point you have a page that contains just the digital signature
// you can now use PDFDraw or PDFRasterizer to create an image however you like


Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages