sap.setVisibleSignature(new Rectangle(0,0,0,0), 1, "CertificationSignature");
Paulo On Fri, May 18, 2012 at 11:47 AM, Julian Janssens <[email protected]> wrote: > Hello, > > I'm quite new with iText. I need to certify a PDF with an invisible > signature field. I am using the following code, as documented in the book > and in the examples : > > KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); > > ks.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(KEYSTORE_FILE), > KEYSTORE_PASSWORD.toCharArray()); > PrivateKey key = (PrivateKey) ks.getKey(KEYSTORE_ALIAS, > ALIAS_PASSWORD.toCharArray()); > Certificate[] chain = ks.getCertificateChain(KEYSTORE_ALIAS); > > PdfReader reader = new PdfReader(os.toByteArray()); > PdfStamper stp = PdfStamper.createSignature(reader, > response.getOutputStream(), '\0', null, false); > PdfSignatureAppearance sap = stp.getSignatureAppearance(); > sap.setCrypto(key, chain, null, > PdfSignatureAppearance.SELF_SIGNED); > sap.setReason("I'm the author"); > sap.setLocation("Lisbon"); > > sap.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED); > // comment next line to have an invisible signature > sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, > "CertificationSignature"); > stp.close(); > > This works pretty well, but of course the signature is visible. If I comment > the line sap.setVisi.... the signature is invisible, but its name is > Signature1. > How can I change the name of the signature field, if it is invisible ? I > tried the following, but it does not work (Exception "The field > CertificationSignature does not exists"). > > sap.setVisibleSignature("CertificationSignature"); > > I looked into iText source-code and as suggested by its name/javadoc this > method needs an existing signature field. Is there a way to only change the > signature field name ? I was expecting something like : > > sap.setSignatureFieldName("CertificationSignature"); > > The body of the method would be the first par of > setVisibleSignature(Rect.... ) : > if (fieldName != null) { > if (fieldName.indexOf('.') >= 0) > throw new > IllegalArgumentException(MessageLocalization.getComposedMessage("field.names.cannot.contain.a.dot")); > AcroFields af = writer.getAcroFields(); > AcroFields.Item item = af.getFieldItem(fieldName); > if (item != null) > throw new > IllegalArgumentException(MessageLocalization.getComposedMessage("the.field.1.already.exists", > fieldName)); > this.fieldName = fieldName; > } > > Kind regards, > > Julian > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > > iText(R) is a registered trademark of 1T3XT BVBA. > Many questions posted to this list can (and will) be answered with a > reference to the iText book: http://www.itextpdf.com/book/ > Please check the keywords list before you ask for examples: > http://itextpdf.com/themes/keywords.php ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
