Re: [Podofo-users] digital signatures
A PDF parsing, modification and creation library.
Brought to you by:
domseichter
|
From: Alvaro C. <alv...@gm...> - 2012-01-05 14:39:33
|
Hello Leonard, thanks for your reply. What do you think about the next code?
bool isSignatureField(const PdfMemDocument &doc, const PdfObject *const pObj)
{
if (pObj == 0) return false;
if (not pObj->IsDictionary()) return false;
const PdfObject *const keyFTValue =
pObj->GetDictionary().GetKey(PdfName("FT"));
if (keyFTValue == 0) return false;
string value;
keyFTValue->ToString(value);
if (value != "/Sig") return false;
const PdfObject *const keyVValue =
pObj->GetDictionary().GetKey(PdfName("V"));
if (keyVValue == 0) return false;
const PdfObject *const signature =
doc.GetObjects().GetObject(keyVValue->GetReference());
if (signature->IsDictionary()) return true;
else return false;
}
int getNumberOfSignatures(const PdfMemDocument &doc)
{
/// Find the document catalog dictionary
const PdfObject *const trailer = doc.GetTrailer();
if (not trailer->IsDictionary())
throw std::invalid_argument("Document invalid, non-dictionary trailer!");
const PdfObject *const catalogRef =
trailer->GetDictionary().GetKey(PdfName("Root"));
if (catalogRef==0 or not catalogRef->IsReference())
throw std::invalid_argument("Invalid /Root entry");
const PdfObject *const catalog =
doc.GetObjects().GetObject(catalogRef->GetReference());
if (catalog==0 or not catalog->IsDictionary())
throw std::invalid_argument("Invalid or non-dictionary
referenced by /Root entry");
/// Find the Fields array in catalog dictionary
const PdfObject *acroFormValue =
catalog->GetDictionary().GetKey(PdfName("AcroForm"));
if (acroFormValue == 0) return 0;
if (acroFormValue->IsReference())
acroFormValue = doc.GetObjects().GetObject(acroFormValue->GetReference());
if (not acroFormValue->IsDictionary()) return 0;
const PdfObject *fieldsValue =
acroFormValue->GetDictionary().GetKey(PdfName("Fields"));
if (fieldsValue == 0) return 0;
if (fieldsValue->IsReference())
fieldsValue = doc.GetObjects().GetObject(acroFormValue->GetReference());
if (not fieldsValue->IsArray()) return 0;
/// Verify if each object of the array is a signature field
int n = 0;
const PdfArray &array =fieldsValue->GetArray();
for (unsigned int i=0; i<array.size(); i++) {
const PdfObject *const obj =
doc.GetObjects().GetObject(array[i].GetReference());
if (isSignatureField(doc, obj)) n++;
}
return n;
}
I tested it with some pdf files and it seems to work correctly, but I
am not sure about its completeness (sorry but I am newbie using podofo
and the pdf standard).
-
Alvaro
On 30 December 2011 14:51, Leonard Rosenthol <lro...@ad...> wrote:
> You have to iterate over all the fields in the Fields array in the AcroForm dictionary looking for those of type Sig.
>
> Of course, that will only tell you the number of signature fields. For each field, you'll need to see if it's signed or not.
>
> Leonard
>
> -----Original Message-----
> From: Alvaro Cuno [mailto:alv...@gm...]
> Sent: Friday, December 30, 2011 10:10 AM
> To: pod...@li...
> Subject: [Podofo-users] digital signatures
>
> Hi,
>
> Is it possible to obtain the number of digital signatures in a pdf file directly? How can get a reference for them?
>
> -
> Alvaro
>
> ------------------------------------------------------------------------------
> Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
> _______________________________________________
> Podofo-users mailing list
> Pod...@li...
> https://lists.sourceforge.net/lists/listinfo/podofo-users
|