签署大PDF文件时出现iText错误:SigDict / Contents非法数据

时间:2012-06-08 14:39:39

标签: java pdf itext signature

我正在尝试使用iText(最新版本)为Java签署大量PDF文件。但我有大问题。对于大小超过30 MByte(直到120 MByte)的文件,我在Acrobat Reader(和其他读者)中收到一条签名无效错误: SigDict / Contents非法数据

相同的代码适用于大小<的其他文件。 30 MByte。这是我使用的代码:

KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(keystore_path), keystore_password.toCharArray());
String alias = prop.getProperty("key.alias");
PrivateKey pk = (PrivateKey)ks.getKey(alias , key_password.toCharArray());
Certificate[] chain = ks.getCertificateChain(alias);

PdfReader reader = new PdfReader(fileIn.getPath(), ownerpassword);          
PdfStamper stamper = PdfStamper.createSignature(reader, new FileOutputStream(fileOut),  '\0', null , true);                         
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setCrypto(pk, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
Rectangle rect = new Rectangle(Integer.parseInt(prop.getProperty("sign.field.start.x")),
                    Integer.parseInt(prop.getProperty("sign.field.start.y")),
                    Integer.parseInt(prop.getProperty("sign.field.end.x")), 
                    Integer.parseInt(prop.getProperty("sign.field.end.y")));
appearance.setReason(prop.getProperty("sign.field.reason"));
appearance.setLocation(prop.getProperty("sign.field.location"));
appearance.setVisibleSignature(rect, Integer.parseInt(prop.getProperty("sign.field.page")), "SignField");            

stamper.close();

----更新----

这似乎与Java的iText(至少5.2.1)的错误有关。

请参阅此帖子:http://itext-general.2136553.n4.nabble.com/iText-error-in-signing-big-PDF-files-SigDict-Contents-illegal-data-td4655309.html#none

我为所有遇到此类问题的人打开了帖子。

0 个答案:

没有答案