我在嘗試對PDF文檔進行數字簽名時出現此錯誤。 傳遞兩個pdf SOURCEPDF名稱和DESTINATIONPDF名稱(數字SIGNED)pdf名稱。 在SOURCEPDF首次數字簽名後,我得到DESTINATIONPDF。 第二次數字簽名使用DESTINATIONPDF作爲源pdf以及目的地pdf。com.itextpdf.text.exceptions.InvalidPdfException:找不到PDF頭標籤
這裏是我的代碼
try
{
for(int i=1;i<=signature_Count;i++)
{
if(i==1)
{
tmpPdfSource=sourcePdfPath;
}else{
this.tmpPdfSource=destinationPdfPath;
}
int pageNo=Integer.parseInt(ad.readXML(xmlString, rootName,"PageNo-"+i));
String imageSource=ad.readXML(xmlString, rootName,"ImageSource-"+i);
float llx=Float.parseFloat(ad.readXML(xmlString, rootName,"llx-"+i));
float lly=Float.parseFloat(ad.readXML(xmlString, rootName,"lly-"+i));
float urx=Float.parseFloat(ad.readXML(xmlString, rootName,"urx-"+i));
float ury=Float.parseFloat(ad.readXML(xmlString, rootName,"ury-"+i));
String signature=ad.readXML(xmlString, rootName,"SignatureName-"+i);
File dest = new File(destinationPdfPath);
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new Fil eInputStream(certificatePath), keystore_password.toCharArray());
String alias = (String) ks.aliases().nextElement();
PrivateKey pk = (PrivateKey) ks.getKey(alias,key_password.toCharArray());
java.security.cert.Certificate[] chain = ks.getCertificateChain(alias);
PdfReader reader = new PdfReader(tmpPdfSource);
stamper = PdfStamper.createSignature(reader,new FileOutputStream(dest), '\0', null, true);
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setCrypto(pk, chain, null,PdfSignatureAppearance.SELF_SIGNED);
if (true)
{
appearance.setAcro6Layers(true);
Image img=Image.getInstance(imageSource);
appearance.setImage(img);
appearance.setVisibleSignature(new com.itextpdf.text.Rectangle(llx, lly, urx, ury), pageNo, signature);
}
}//for
stamper.close();
} catch (Exception e) {
GenericLog gl=new GenericLog();
gl.writeWarning("Error Occured in SignPdfDocument ");
gl.writeError(e);
e.printStackTrace();
}
請幫我解決這個錯誤。
謝謝布魯諾非常幫助完整的文檔。 – naveed 2013-02-14 08:21:03