2013-10-28 38 views
0

事實上,我有大約20的Form Fields的PDF,其中一個表單字段的類型爲「PDSignatureField」。現在我需要的值設置爲這個PDSignatureField如何使用PDFBox API設置PDF表格字段中的簽名

這裏是什麼,我試過一塊代碼(IM能夠得到簽名值,但是當我嘗試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); 
     } 

任何一個可以幫我請 感謝

回答

0

我有一個類似的問題,我幾乎沒有加入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」,我還沒有找到原因。

希望得到這個幫助。

+0

感謝您的補充信息。我遇到了同樣的問題,現在它適用於我,它只是在pdf中顯示一個簽名。當我將簽名添加到文檔時,我得到了Signature1字段。現在它消失了。 – ssindelar

相關問題