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

Time:09-08

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.

CodePudding user response:

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/

CodePudding user response:

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());
      }
  • Related