简体   繁体   English

如何在 Java 中的 pdf 末尾添加字段(PDFBox)

[英]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.页码是动态的,因此它可以是从 1 到 15 的任何数字。

Signature: ______________________签名: ______________________

I am going to add DocuSign tabs here.我将在此处添加 DocuSign 选项卡。

Any help is appreciated.任何帮助表示赞赏。

You can use an anchor string to place a SignHere tab anywhere that a certain string appears in your document.您可以使用锚字符串将 SignHere 选项卡放置在文档中出现特定字符串的任何位置。 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博客文章: 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/开发者中心指南: 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/使用锚标记的指南: 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. Paige 给了一个很好的答案,让我补充一些东西。 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)请参阅此博客文章以了解如何执行此操作 - https://www.docusign.com/blog/developers/common-api-tasks-adding-initials-each-page-each-document-your-envelope java 代码是这个: (请注意,这使用了不同的选项卡,但您明白了)

    // 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:示例 JSON 片段:

...
    "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>"
      }
    ],
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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