我已尝试使用各种版本的itext,包括带试用许可证的itextgoogle,当我尝试运行代码时,我一直收到以下错误:
InputStream object = this.getResources().openRawResource(R.raw.itextkey);
LicenseKey.loadLicenseFile(object);
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + java.io.File.separator + "testPDF.pdf"));
document.open();
document.add(new Paragraph("testing"));
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
document.close();
错误是:
04-26 20:18:12.761: E/dalvikvm(1927): Could not find class 'org.spongycastle.cert.X509CertificateHolder', referenced from method com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj
04-26 20:18:12.761: W/dalvikvm(1927): VFY: unable to resolve new-instance 2251 (Lorg/spongycastle/cert/X509CertificateHolder;) in Lcom/itextpdf/text/pdf/PdfReader;
我听说我需要自己构建iText,但我不知道从哪里开始/如何做到这一点。我发现的罐子的文件名不是很具描述性。
答案 0 :(得分:5)
SpongyCastle是Android中可用的BouncyCastle加密库的替代品。查看此主题 - How to include the Spongy Castle JAR in Android?,其中包含有关如何将SpongyCastle库包含到项目中的详细信息。