簡體   English   中英

如何使用PDFBox API在PDF表單字段中設置Signature

[英]How to setSignature in PDF Form Field using PDFBox api

實際上,我有大約20個表單字段的PDF,其中一個表單字段的類型為'PDSignatureField'。 現在,我需要為此PDSignatureField設置一個值

這是我嘗試過的部分代碼(我可以獲取Signature值,但是當我嘗試設置setSignature時,在保存文檔后無法查看它)

GetSignature->運行正常

        document = PDDocument.load(documents);
        PDAcroForm form = document.getDocumentCatalog().getAcroForm();
        PDField pdfFields;
        pdfFields = form.getField("EMPLOYEE SIGNATURE");
        if (pdfFields instanceof PDSignatureField)
        {
            PDSignatureField f3 = (PDSignatureField)form.getField("EMPLOYEE SIGNATURE");
            System.out.println(f3.getSignature().getName());
        }

SetSignature->無法查看特定表單字段中的簽名值
在這里,“ sigObject”被聲明為PDSignature對象

        document = PDDocument.load(documents);
        PDAcroForm form = document.getDocumentCatalog().getAcroForm();
        PDField pdfFields;
        pdfFields = form.getField("EMPLOYEE SIGNATURE");
        if (pdfFields instanceof PDSignatureField)
        {
            PDSignatureField f3 = (PDSignatureField)form.getField("EMPLOYEE SIGNATURE");
            sigObject.setName("Test");
            sigObject.setLocation("Test");
            sigObject.setReason("Test"); 
            sigObject.setSignDate(Calendar.getInstance());
            f3.setSignature(sigObject);
        }

有人可以幫我嗎,謝謝

我有一個類似的問題,並且在f3.setSignature(sigObject)之后添加以下代碼片段,我快到了:

/* f3.setSignature(sigObject) only sets the V attribute of the signature field. You still
   need to call document.addSignature() to register the signature interface and call
   saveIncremental() to call the sign() method and generate the actual Signature Dictionary object       
*/

f3.getCOSObject().setNeedToBeUpdate(true);
document.addSignature(sigObject, this);
document.saveIncremental(fis, fos); /* as in pdfbox examples */

但是,我仍然有一個不希望看到的結果,其中兩次顯示了簽名,一次是簽名字段的值,另一次是另一個幻影字段“ Signature1”,但我還沒有找到原因。

希望能有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM