Search code examples
pdftimestampdigital-signaturesignature

How to show Creator in Detail of Signature in PdfBox


I want to display the Creator in Signature Detail. In "Signature was created using Not available."

enter image description here

This is my code for add sign info:

private void signDetached(SignatureInterface signature, PDDocument document, OutputStream output) throws IOException {
    PDSignature pdSignature = new PDSignature();
    pdSignature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
    pdSignature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
    pdSignature.setName("jvmfy");
    pdSignature.setReason("Learn how to sign pdf with jvmfy.com!");

    // the signing date, needed for valid signature
    pdSignature.setSignDate(Calendar.getInstance());

    // register signature dictionary and sign interface
    document.addSignature(pdSignature, signature);

    // write incremental (only for signing purpose)
    // use saveIncremental to add signature, using plain save method may break up a document
    document.saveIncremental(output);
}

Solution

  • I looked in the PDF 32000 specification for Prop_Build. This isn't implemented in the PDFBox example, and after searching for "PDF Signature Build Dictionary Specification" I think it's confusing. But this attempt works, based on what I saw in an existing signed PDF:

    COSDictionary pbDict = new COSDictionary();
    COSDictionary appDict = new COSDictionary();
    appDict.setName(COSName.NAME, "PDFBox");
    pbDict.setItem(COSName.getPDFName("App"), appDict);
    pdSignature.getCOSObject().setItem(COSName.getPDFName("Prop_Build"), pbDict);