hello All,

can you people please guide me to how to add a signtaure on an adobe9 form 
using itext. i used the two codes that are working fine for a form filled 
in adobe 7 but for a form filled in adobe 9 not any signature is being 
added to the existing pdf.

This code was used to add the signature.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.AcroFields;
import com.lowagie.text.pdf.PRAcroForm;
import com.lowagie.text.pdf.PdfAcroForm;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfFormField;
import com.lowagie.text.pdf.PdfName;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfSignatureAppearance;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfString;
import com.lowagie.text.pdf.PdfWriter;

public class DSOnPdf {

        /**
         * @param args
         */
        public static void main(String[] args) 
        {
                try
                {
                //String strInputFileName 
="C:\\sign\\1049-Form1BSigned9.pdf";
                String strInputFileName =
"C:\\sign\\Form23_Adobe9_1.1_2sign.pdf";
                String strOutPutFileName ="C:\\sign\\Form 20 BRRNEW.pdf";
                PdfReader reader = new PdfReader(strInputFileName);
 
                FileOutputStream fout = new FileOutputStream(
"C:\\sign\\Form23_Adobe9_1.1_2signnew.pdf");
                PdfStamper stp = new PdfStamper(reader, fout);
                PdfWriter pdfStamperImp = stp.getWriter();
                PdfAcroForm acroForm = pdfStamperImp.getAcroForm();
                PdfFormField signature = PdfFormField.createSignature
(pdfStamperImp); 
                acroForm.setSignatureParams(signature, "Signature1",  73, 
173, 123, 132); 
                acroForm.drawSignatureAppearences(signature, 73, 173, 123, 
132);
                stp.addSignature("Signature1", 1,73, 173, 123, 132);
                //acroForm.addFormField(signature);
                //stp.addAnnotation(signature, 4324);
                //PdfFormField sig = addSignature(stp, 1, "signature", 73, 
73, 23, 32); 
 
                //stp.setFormFlattening(true);
 
                //sig.setFieldFlags(PdfAnnotation.FLAGS_PRINT);
     //   sig.setFlags(PdfAnnotation.FLAGS_PRINT);
 
                stp.close();
                }
                catch(Exception ex)
                {
                        ex.printStackTrace();
                }
        }


        static PdfFormField addSignature(PdfStamper pdfStamper, int page, 
String name, float llx, float lly, float urx, float ury) 
    { 
        PdfWriter pdfStamperImp = pdfStamper.getWriter(); 
        PdfAcroForm acroForm = pdfStamperImp.getAcroForm(); 

        PdfFormField signature = PdfFormField.createSignature
(pdfStamperImp); 
 
        acroForm.setSignatureParams(signature, name, llx, lly, urx, ury); 
        acroForm.drawSignatureAppearences(signature, llx, lly, urx, ury); 
        pdfStamper.addAnnotation(signature, page); 
        signature.setFieldFlags(PdfAnnotation.FLAGS_PRINT);
        return signature; 
    } 

 
}

And this code was used to sign that signature field generated.


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.AcroFields;
import com.lowagie.text.pdf.PRAcroForm;
import com.lowagie.text.pdf.PdfAcroForm;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfFormField;
import com.lowagie.text.pdf.PdfName;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfSignatureAppearance;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfString;
import com.lowagie.text.pdf.PdfWriter;

public class DigitalSignatureOnPdf2 {

        /**
         * @param args
         */
        public static void main(String[] args) 
        {
                try
                {
                KeyStore ks = KeyStore.getInstance("pkcs12");
                ks.load(new FileInputStream(
"D:\\Util\\certs\\AXISBANKDEMO.p12"),"AXISBANK".toCharArray());
                String alias = (String)(ks.aliases().nextElement());
                PrivateKey key = (PrivateKey)ks.getKey(alias,"AXISBANK"
.toCharArray());
                Certificate[] chain = ks.getCertificateChain(alias);
                String strInputFileName ="C:\\sign\\Form 20 BNEW23123.pdf"
;
                //String strInputFileName ="C:\\sign\\DocumentRR.pdf";
                String strOutPutFileName ="C:\\sign\\Form 20 
BNEW23123new.pdf";
                PdfReader reader = new PdfReader(strInputFileName);
                int n = reader.getNumberOfPages();
 
                //FileOutputStream fout = new 
FileOutputStream("C:\\sign\\1049-Form1BSigned9new.pdf");
                FileOutputStream fout = new FileOutputStream(
"C:\\sign\\Form 20 BNEW23123new.pdf");
                //For single signature on pdf
                        //PdfStamper stp = 
PdfStamper.createSignature(reader, fout, '\6');
                //for multiple signature
                File f=new File("C:\\sign\\gaurav.pdf");
                PdfStamper  stp = PdfStamper.createSignature(reader, fout,
'\0',null,true);
                PdfSignatureAppearance sap = stp.getSignatureAppearance();
                sap.setCrypto(key, chain, null, PdfSignatureAppearance.
WINCER_SIGNED);
                //sap.setVisibleSignature(new Rectangle(500, 200, 550, 
230), 1, null);
                //sap.setVisibleSignature(new Rectangle(200, 200, 250, 
230), 1, null);
                
//sap.setVisibleSignature("form1_DTLs[0].page1[0].Sign2[0]");
                sap.setVisibleSignature("Signature1");
                //stp.setFormFlattening(true);
                stp.close();
                }
                catch(Exception ex)
                {
                        ex.printStackTrace();
                }
        }

These both are working for adobe 7 forms but not for adobe 9 forms.and the 
forms are XFA based .
Gaurav Kumar Tyagi
Asst. System Engineer Trainee
Tata Consultancy Services
154, B Block A,
Sector 63, Phase III, Noida Distt
Gautam Buddha Nagar
Noida - 201301,Up
India
Cell:- 09990013398
Mailto: gauravk.ty...@tcs.com
Website: http://www.tcs.com
____________________________________________
Experience certainty.   IT Services
                        Business Solutions
                        Outsourcing
____________________________________________
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to