簡體   English   中英

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

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

我有不同頁數的文件。 我的要求是在文檔底部添加一個簽名字段。 它應該如下所示。 頁碼是動態的,因此它可以是從 1 到 15 的任何數字。

簽名: ______________________

我將在此處添加 DocuSign 選項卡。

任何幫助表示贊賞。

您可以使用錨字符串將 SignHere 選項卡放置在文檔中出現特定字符串的任何位置。 您可以使用“簽名”一詞或在您希望簽名出現的白色文本中使用另一個唯一字符串。 我們有一些關於錨標記的資源:

博客文章: https://www.docusign.com/blog/developers/tabs-deep-dive-placing-tabs-documents

開發者中心指南: https://developers.docusign.com/docs/esign-rest-api/esign101/concepts/tabs/auto-place/

使用錨標記的指南: https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-in-app-embedded/

Paige 給了一個很好的答案,讓我補充一些東西。 您可以確定文檔中有多少頁,然后使用此數字將一頁放在最后一頁中。 請參閱此博客文章以了解如何執行此操作 - 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());
      }

另一種選擇是添加一個只有一頁的附加文檔。 這將是“簽名頁面”,並將引用其他頁面。

您可以在簽名請求中包含多個文檔。 文檔以數組的形式發送,文檔將按照數組的順序呈現。

示例 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