简体   繁体   中英

How to add a field at the end of the pdf in Java (PDFBox)

I have documents of different number of pages. My requirement is to add a Signature field at the bottom of the document. It should be something like below. The page number is dynamic so it can be any number from 1 to 15.

Signature: ______________________

I am going to add DocuSign tabs here.

Any help is appreciated.

You can use an anchor string to place a SignHere tab anywhere that a certain string appears in your document. You could use the word "Signature" or use another unique string in white text where you want the Signature to appear. We have a few resources on anchor tagging:

Blog post: https://www.docusign.com/blog/developers/tabs-deep-dive-placing-tabs-documents

Developer Center guide: https://developers.docusign.com/docs/esign-rest-api/esign101/concepts/tabs/auto-place/

How-to guide using anchor tagging: https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-in-app-embedded/

Paige gave a very good answer, let me just add a few things. You can determine how many pages are in the document, and then use this number to place one in the last page. See this blog post on how to do this - https://www.docusign.com/blog/developers/common-api-tasks-adding-initials-each-page-each-document-your-envelope The java code is this: (note this uses a different tab, but you get the idea)

    // You need to obtain an access token using your chosen authentication flow 
    Configuration config = new Configuration(new ApiClient(basePath));
    config.addDefaultHeader("Authorization", "Bearer " + accessToken);
    EnvelopesApi envelopesApi = new EnvelopesApi(config);
    
        EnvelopesApi.GetEnvelopeOptions options = 

envelopesApi.new GetEnvelopeOptions();
    options.setInclude("documents,recipients");
    Envelope env = envelopesApi.getEnvelope(accountId, envelopeId, options);
    for (Signer signer : env.getRecipients().getSigners())
      {
      signer.setTabs(new Tabs());
      signer.getTabs().setInitialHereTabs(new java.util.List<InitialHere>());
      for (EnvelopeDocument doc : env.getEnvelopeDocuments())
        {
          for (Page page : doc.getPages())
          {
          int width = Integer.parseInt(page.getWidth());
          int height = Integer.parseInt(page.getHeight());
          InitialHere initial = new InitialHere();
          // 100 pixels higher and to the left from the top bottom corner
          int x = width - 100;
          int y = height - 100;
          initial.setXPosition(x.toString());
          initial.setYPosition(y.toString());
          initial.setPageNumber(page.getSequence());
          initial.setDocumentId(doc.getDocumentId());
          initial.setRecipientId(signer.getRecipientId());
          signer.getTabs().getInitialHereTabs().Add(initial);
          }
        }
      envelopesApi.createTabs(accountId, env.getEnvelopeId(), signer.getRecipientId(), signer.getTabs());
      }

Another option is to add an additional document which would only have one page. This would be the "Signing page" and would reference the other pages.

You can include more than one document in your signature request. The documents are sent in an array, the documents will be presented in the array's order.

Example JSON fragment:

...
    "documents": [
      {
        "name": "Example document",
        "fileExtension": "pdf",
        "documentId": "1",
        "documentBase64": "<base64 encoded doc contents>"
      },
      {
        "name": "Signature page",
        "fileExtension": "pdf",
        "documentId": "2",
        "documentBase64": "<base64 encoded doc contents>"
      }
    ],
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM