pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrei Pritulescu <andrei.pritule...@yahoo.com>
Subject Visible signature with PDFBox
Date Fri, 14 Dec 2012 13:48:33 GMT
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 = 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.setName("signer name");
    signature.setLocation("signer location");
    signature.setReason("reason for signature");
    // the signing date, needed for valid signature

    // 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();

Any help would be much appreciated.

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