我在尝试对 PDF 文档进行数字签名时遇到此错误。传递两个 pdf SOURCEPDF 名称和 DESTINATIONPDF 名称(数字签名)pdf 名称。在 SOURCEPDF 上进行第一次数字签名后,我得到了 DESTINATIONPDF 。对于第二次数字签名,我使用 DESTINATIONPDF 作为源 pdf 和目标 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();
}
请帮我修复这个错误。