1

I'm going in trouble using PDFBox 2.0.0-RC3 and producing a digital signature field into a PDF.

This is the piece of code i use:

public static void main(String[] args) throws IOException, URISyntaxException
{
    PDDocument document;

    document = new PDDocument();

    PDPage page = new PDPage(PDRectangle.A4);

    document.addPage(page);

    PDAcroForm acroForm = new PDAcroForm(document);
    document.getDocumentCatalog().setAcroForm(acroForm);   

    PDSignatureField signatureBox = new PDSignatureField(acroForm);

    signatureBox.setPartialName("ENSGN-MY_SIGNATURE_FIELD-001");

    acroForm.getFields().add(signatureBox);

    PDAnnotationWidget widget = signatureBox.getWidgets().get(0);
    PDRectangle rect = new PDRectangle();
    rect.setLowerLeftX(50);
    rect.setLowerLeftY(750);
    rect.setUpperRightX(250);
    rect.setUpperRightY(800);
    widget.setRectangle(rect);

    page.getAnnotations().add(widget);

    try {

        document.save("/tmp/mySignatureFieldGEN_PDFBOX.pdf");
        document.close();

    } catch (Exception io) {

        System.out.println(io);

    }        
}

The code generates a pdf document, i open it with Acrobat Reader and this is the result:

PDF BOX Generated

As you can see, the signature panel on the left is void but the signature field on the left is present and works.

I generate the same PDF with PDFTron. This is the result:

PDF Tron Generated

In this case the signature panel on the left show correctly the presence of the signature field.

I would like to obtain this second case (correct) but i don't understand why PDF Box can do this.

Many thanks

ain
  • 22,394
  • 3
  • 54
  • 74

1 Answers1

1

add this:

widget.setPage(page);

This sets the /P entry.

Now the panel on the left appears. How did I get the idea? I got a document with such an empty signature field (from here), and compared it with yours with PDFDebugger.

Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97
  • Interesting. According to ISO 32000-1 that entry is optional here. It might be in anticipation of ISO 32000-2 where signature fields will be required to have no more than one visualization in the document. – mkl Feb 17 '16 at 10:24