Well, I think you copies the wrong array into your pdf. You should
copy 'out' into the contents field and not the 'sg' array.

Your code:
dic2.put(PdfName.CONTENTS, new PdfString(sg).setHexWriting(true));

Correct code:
dic2.put(PdfName.CONTENTS, new PdfString(out).setHexWriting(true));

Regards,
Tamas


2005/11/10, Sivakumar Balakrishnan <[EMAIL PROTECTED]>:
> Hi,
>
>        The code snippet is below,
>
>                As I mentioned in my previous mail, the hash would be sent to
> an external entity and the signature would come back, which has to be
> embedded into the original pdf.
>
>          public static void fillSignature(String[] args) {
>   try {
>    log("reading the input...");
>    PdfReader reader = new PdfReader(args[0]);
>    FileOutputStream fout = new FileOutputStream(args[1]);
>    PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0');
>    Calendar now = Calendar.getInstance();
>    PdfSignatureAppearance sap = stp.getSignatureAppearance();
>    log("creating visible signature ...");
>    sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null);
>    sap.setLayer2Text("This is some custom made text.\n\nDate: some date");
>    PdfDictionary dic = new PdfDictionary();
>    dic.put (PdfName.TYPE, PdfName.SIG);
>    dic.put(PdfName.FILTER, new PdfName("ADOBE.PPKLITE"));
>    dic.put(PdfName.SUBFILTER, new PdfName("adbe.pkcs7.detached"));
>    dic.put(PdfName.M, new PdfDate(now));
>    log("setting the dictionary to the appearance...");
>    sap.setCryptoDictionary(dic);
>    HashMap exc = new HashMap();
>    exc.put(PdfName.CONTENTS, new Integer(0x2802));
>    log("preclosing the signature appearance");
>    sap.preClose(exc);
>    PdfDictionary dic2 = new PdfDictionary();
>    byte sg[] = readFile("signature_pdf.p7s");
>    byte[] out = new byte[(0x2800)/2];
>    log("Sg Length : "+sg.length+" Out Length : "+out.length);
>    System.arraycopy(sg, 0, out, 0, sg.length);
>    dic2.put(PdfName.CONTENTS, new PdfString(sg).setHexWriting(true));
>    sap.close(dic2);
>    log("complete");
>   } catch (Exception e) {
>    log("exception is ..."+e);
>   }
>  }
>
>
>
> regards
> siva.
>
>
> On 11/9/05, Tamas Nemeth <[EMAIL PROTECTED]> wrote:
> > Hi!
> >
> > Yes, I could successfully attach external signature to my pdf file.
> > Have you allocated enough space for your /contets field?
> > Can you send some code snippet, which maybe can help to solve your
> problem?
> >
> > regards,
> > Tamas
> >
> > 2005/11/9, Sivakumar Balakrishnan <[EMAIL PROTECTED]>:
> > > Hi Tamas,
> > >     I saw your posting in the mailing lists, I am also having the same
> > > scenario, but I am getting the error, "Unexpected Byte Range".
> > >
> > >     My scenario is,
> > >              I have to make a hash out of the pdf and send to an
> external
> > > entity, which creates the pkcs7.
> > >              I have to insert the pkcs7 into the original pdf.
> > >
> > >     I've followed the sample "how to sign with external siganture",
> except
> > > for the code, which generates the signature, I've put the generated
> pksc7
> > > bytes. I keep getting the above error, "Byte Range is invalid."
> > >
> > >     Are you able to successfully attach the signature with the original
> pdf.
> > >
> > > regards
> > > siva
> >
>
>


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to