Get signature info from signed pdf (Java)

Hi,

I have signed a PDF document via ASPOSE. And then I want to get information about the person or authority signing the document. And I get null results.

code.zip (5.5 KB)
If you need, In attached you can find code for signing-pdf, code for getting signature-information, and used .pfx file.

In aspose.word I could fetch the needed information

for (DigitalSignature digitalSignature : document.getDigitalSignatures()) {
subjects.add(digitalSignature.getSubjectName());
}

@razmik.mkrtchyan

You may please try using following code snippet in order to get Signer Name. However, if you face any issue, please share the PDF document from which you are trying to extract it. We will test the scenario in our environment and address it accordingly.

com.aspose.pdf.facades.PdfFileSignature pdfSign = new com.aspose.pdf.facades.PdfFileSignature();
pdfSign.bindPdf(dataDir + "input.pdf");
if (pdfSign.containsSignature()) {
 java.util.List<String> sigNames = pdfSign.getSignNames();
  if (sigNames.size() > 0) {
     for(String s:sigNames)
          System.out.println(pdfSign.getSignerName(s));
   }
 }
 pdfSign.close();

@asad.ali

Thank you for your response!

It didn’t work, returns null.

pdfSign.containsSignature() is true
pdfSign.getSignNames() Restruns “Singature1” - which I don’t know from where is it.
And pdfSign.getSignerName(s) returns null

**response.pdf (307.7 KB)
**

In attached you can find signed document. (signature is on the first page)

@razmik.mkrtchyan

We further tried following code snippet with Aspose.PDF for Java 20.6 to extract signature information but, we did not get much success:

Document pdfDocument = new Document(dataDir + "response.pdf");
        for(com.aspose.pdf.Field field:pdfDocument.getForm().getFields()){
            if(field instanceof SignatureField){
                SignatureField s = (SignatureField)field;
                System.out.println(s.getSignature().getAuthority());
                System.out.println(s.getSignature().getContactInfo());
                System.out.println(s.getSignature().getReason());
            }
        }

Therefore, we have logged an issue as PDFJAVA-39571 in our issue tracking system for the sake of further investigation. We will look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

1 Like

@asad.ali
Thanks,I will wait!

Hi,
I would like to join the question regarding the problem getting signer information.

I am trying to use java aspose.pdf-21.1 to get the information from the PDF about the signer.
I ran into the same problem. For some PDF files the getSignerName method returns null.
Mostly for unqualified signatures, but also for qualified and encrypted files.

What is the status of the PDFJAVA-39571 issue?
Is there any progress?

@TomPil

The earlier logged issue is currently under the phase of investigation. We have recorded your concerns and will surely let you know as soon as we have some definite updates regarding ticket resolution. Please be patient and spare us some time.

We apologize for the inconvenience.

@TomPil, @razmik.mkrtchyan

We have investigated the earlier logged ticket. The provided document does not contain the signer information, only the date of the sign.

You can check it in Adobe Reader, screenshot with difference attached.
File example with signer info attached too.

short_signed.pdf (8.6 KB)
Screen.png (60.0 KB)

Hey,

I’m also having the same problem getSignerName returns null.
Despite having created the PDF with signature in ASPOSE.

pdfSign.getSignerName(sigName) return NULL

                    pdfSign.getDateTime(sigName);   return OK
                    pdfSign.getReason(sigName);   return OK
                   pdfSign.getLocation(sigName);    return OK
                    pdfSign.getContactInfo(sigName);    return OK

Digitally_Sign_Customizada.pdf (142.1 KB)

@Leecastro

Would you please also share the code snippet and .pfx file that you used for signing this PDF document? We will test the scenario in our environment and address it accordingly.

Follow the requested data.

public List<String> retornarInformacoesAssinaturaDigitalInPDF(DocumentoDTO documentoDTO){
    // Criar assinatura de arquivo PDF
    PdfFileSignature pdfSign = new PdfFileSignature();
    // Vincular PDF
    pdfSign.bindPdf(_dataDir + "Digitally_Signed_PDF.pdf");

    //Obtém os nomes de todas as assinaturas não vazias.
    List<String> sigNames = pdfSign.getSignNames();

    //Recupera a primeira assinatura (pode haver outras assinaturas no PDF)
    String sigName = (String) sigNames.get(0);

    List<String> signInfo = new ArrayList<>();

    // Verifique a assinatura usando o nome da assinatura
    //if (pdfSign.verifySigned("Signature1"))

               // for(int i=0 ; i<sigNames.size() ; i++)
                //{
                    signInfo.add("Nome da Assinatura: " + sigName);
                    signInfo.add("Assinado Digitalmente por: " + pdfSign.getSignerName(sigName));
                    //signInfo.add("Assinado Digitalmente por: " + pdfSign.getSignatureAppearance());
                    signInfo.add("Data da Assinatura: " + pdfSign.getDateTime(sigName));
                    signInfo.add("Motivo: " + pdfSign.getReason(sigName));
                    signInfo.add("Localização: " + pdfSign.getLocation(sigName));
                    signInfo.add("Contato: " + pdfSign.getContactInfo(sigName));
                //}
    return signInfo;
}

@Leecastro

It looks like the signatures in your PDF does not contain details to be retrieved. We also requested for sample PFX file and code snippet that you used to sign the PDF. OR are you just getting this signed PDF from somewhere and wants to process it?

Good Morning,

I received some PDF file. I would like to extract the signature information. For example, issuer, subject, etc.

When I open this file in Adobe Reader, I see signature details in the PDF. These are the details I would like to extract.

atestado_de_capacidade_t__cnica_-_cca_assinado.pdf (180.2 KB)

image.png (19.7 KB)
image.png (22.7 KB)

@Leecastro

An investigation ticket as PDFJAVA-42031 has been logged in our issue tracking system to further analyze this case. We will look into its details and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thanks. I will wait.

In short, I need to print (extract) other fields from the Digital ID, which the ASPOSE library is not showing.

1497506817596245.png (13.2 KB)

@Leecastro

We will surely let you know in case we make some significant progress towards ticket resolution.