I'm thinking about buying Spire PDF for Java but before that I'm using the free 5.1.0 version to see how works, then the following happened:
I followed steps from the e-iceblue guide and everything seemed to work wonderfully right, the PDF was "visually" signed, but then trying to validate the PDF in Adobe Reader I got a few errors, you can see it in SS1:
In addition to it, when I click in "Certificate Details" , nothing happens, while it works fine when I use the same certificate but another lib for pdf sign (like aspose)
I could not found any reason to justify errors in formatting, but exploring the lib methods I found something that seemed oddly to me, it does look like a encoding problem, you can see it in SS2:
The same occurs even with the 5.4.2 evaluation version.
Would like to know what you guys can tell me about it, will be glad for any help.
My code:
- Code: Select all
byte[] bytes = //Receive a PDF
PdfDocument doc = new PdfDocument();
doc.loadFromBytes(bytes);
PdfCertificate certificado = new PdfCertificate("certificate.pfx", "password");
PdfSignature signature = new PdfSignature(doc, doc.getPages().get(0), certificado, "Jones");
Rectangle2D rect = new Rectangle2D.Float();
rect.setFrame(new Point2D.Float(new Float(10.00), new Float(10.00)), new Dimension(600, 50));
signature.setBounds(rect);
signature.setGraphicMode(GraphicMode.Sign_Detail);
signature.setNameLabel("Signer:");
signature.setName("Gary");
signature.setContactInfoLabel("ContactInfo:");
signature.setContactInfo("02881705109");
signature.setLocationInfoLabel("Location:");
signature.setLocationInfo("Brazil");
signature.setReasonLabel("Reason: ");
signature.setReason("The certificate of this document");
signature.setDateLabel("Date");
signature.setDate(new java.util.Date());
signature.setSignDetailsFont(new PdfFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular));
signature.setDocumentPermissions(PdfCertificationFlags.Forbid_Changes);
signature.setCertificated(true);
doc.saveToFile("test.pdf");
doc.close();