pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Muhammad Ijaz Khan <aija...@gmail.com>
Subject Re: Visible signature with PDFBox
Date Sat, 22 Dec 2012 02:22:29 GMT
did you try options.setVisualSignature?

On Fri, Dec 14, 2012 at 3:48 PM, Andrei Pritulescu <
andrei.pritulescu@yahoo.com> wrote:

> Hello all,
>
> My name is Andrei Pritulescu and I am trying to add a visible signature to
> an existing PDF. So far, I was able only to add an invisible signature,
> based on a provided .PFX file.
>
> The code doing the signing is the following:
>
>  public File signPdfEngine(File document, String filePath) throws
> IOException, COSVisitorException, SignatureException {
>     byte[] buffer = new byte[8 * 1024];
>     if (!(document != null && document.exists())) {
>         new RuntimeException("");
>     }
>     File outputDocument = new File(filePath);
>     FileInputStream fis = new FileInputStream(document);
>     FileOutputStream fos = new FileOutputStream(outputDocument);
>     int c;
>     while ((c = fis.read(buffer)) != -1) {
>         fos.write(buffer, 0, c);
>     }
>     fis.close();
>     fis = new FileInputStream(outputDocument);
>     // load document
>     PDDocument doc = PDDocument.load(document);
>     // create signature dictionary
>     PDSignature signature = new PDSignature();
>     signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE); // default
> filter
>     // subfilter for basic and PAdES Part 2 signatures
>     signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
>     signature.setName("signer name");
>     signature.setLocation("signer location");
>     signature.setReason("reason for signature");
>     // the signing date, needed for valid signature
>     signature.setSignDate(Calendar.getInstance());
>
>     // SignatureOptions options = new SignatureOptions();
>     // options.setPage(1);
>     // options.setPreferedSignatureSize(700);
>
>     // register signature dictionary and sign interface
>     doc.addSignature(signature, this);
>     // write incremental (only for signing purpose)
>     doc.saveIncremental(fis, fos);
>     return outputDocument;
>     }
>
>
> What code should I write in order to add a visible signature, also? I
> tried creating a "SignatureOptions" object, setting the page and signature
> size, but to no effect.
>
> SignatureOptions options = new SignatureOptions();
> options.setPage(1);
> options.setPreferedSignatureSize(700);
>
>
> Any help would be much appreciated.
>
> Best regards,
> Andrei

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message