We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

NullPointerException when using PdfFileSignature

In our Java application we found a problem using Aspose.PDF.Kit, in concrete the last version before merging 4.7.0.

The error is produced in this code after some time of use, in the method save() of PdfFileSignature. This is the stackTrace:

java.lang.NullPointerException
at com.aspose.pdf.kit.op.(Unknown Source)
at com.aspose.pdf.kit.oo.(Unknown Source)
at com.aspose.pdf.kit.pj.a(Unknown Source)
at com.aspose.pdf.kit.pl.a(Unknown Source)
at com.aspose.pdf.kit.pl.q(Unknown Source)
at com.aspose.pdf.kit.pn.b(Unknown Source)
at com.aspose.pdf.kit.PdfFileSignature.a(Unknown Source)
at com.aspose.pdf.kit.PdfFileSignature.save(Unknown Source)
at com.aspose.pdf.kit.PdfFileSignature.save(Unknown Source)
at idiada.zeus.services.documentsimpl.DocumentOperationsImpl.protectPdf(DocumentOperationsImpl.java:1399)
And this is the code snippet:
public void protectPdf(String inputName, String outputName,
String inFolder, String outFolder) {
try {
log.info(“Protecting doc using ASPOSE”);
// FILE PATH
PdfFileSignature pdfSignature = new PdfFileSignature(inFolder+inputName, outFolder+outputName);
// CERTIFICATE
Pkcs7Signature certificate = new Pkcs7Signature(licenseKeyFolder+pdf_certificate, pdf_certificate_password); //
java.awt.Rectangle rect = new java.awt.Rectangle(240, 740, 70, 70);
certificate.setRect(rect);
pdfSignature.setVisible(false);
pdfSignature.setSignature(certificate);
//pdfSignature.setKeyStoreType(“pkcs12”);
pdfSignature.setPageNumber(1);
pdfSignature.setSignModel(PdfFileSignature.WINDOWCERTIFICATE);
pdfSignature.setCertificationLevel(PdfFileSignature.CERTIFIED_NO_CHANGES_ALLOWED);
pdfSignature.save();
}
catch (Exception e) {
log.error(e.getMessage(),e);
}
}

Regards.

Hi CRISTINA GAROS,


Thanks for contacting support.

Can you please share the source PDF file and digital signature, so that we can test the scenario at our end. We are sorry for this inconvenience.


PS, during our testing, where we have used one of our sample PDF and signature files, we are unable to notice any issue.

[quote user=“codewarior”]Hi CRISTINA GAROS,


Thanks for contacting support.

Can you please share the source PDF file and digital signature, so that we can test the scenario at our end. We are sorry for this inconvenience.


PS, during our testing, where we have used one of our sample PDF and signature files, we are unable to notice any issue.
[/quote]

I think it is obvious I can’t send you the digital signature…it is the private key. So can you post your test code or a snippet for signing a pdf digitally to compare?

Or check the source code of Apsose.pdf.kit where the method fails, because it is ofuscated and is very difficult to discover where the error is produced:
at com.aspose.pdf.kit.op.(Unknown Source)

Regards.

Hi CRISTINA GAROS,


Thanks for sharing the details.

In order to test the scenario, I have used the same code snippet which you have shared earlier post and I did not notice any issue. Meanwhile, can you please share the source PDF file and we can again try using one of our sample Signatures to test the scenario. We are sorry for your inconvenience.

I forgot to reply and close this post. At the end we found the error, it was caused when running multiple applications within the same Tomcat server.

The problem was that another application was using BouncyCastle (bcprov…, used for digital signatures) and there was a problem in classloading. It was also almost impossible to trace the error because your Aspose products have the code offuscated…So we finally moved to iText opensource version to find the error.

Thankyou anyway.

Hi Cristina,


Thanks for your feedback. It is good to know that you have managed to resolve your issue.

Please feel free to contact us for any further assistance, we will be more than happy to extend our support.

Best Regards,