我想使用PDFBOX lib放到我的Android应用程序处理的PDF,但即时得到PDFBox的在Android电子
java.lang.NoClassDefFoundError: org.pdfbox.pdmodel.PDDocument
此错误。至于我正在开发的商业应用程序我不能使用其他库像iText的。所以我的问题是我们可以在android中使用PDfBox。
这里是我的代码: - 使用PDFBox的0.7.3罐子当JVM不能加载类
我想使用PDFBOX lib放到我的Android应用程序处理的PDF,但即时得到PDFBox的在Android电子
java.lang.NoClassDefFoundError: org.pdfbox.pdmodel.PDDocument
此错误。至于我正在开发的商业应用程序我不能使用其他库像iText的。所以我的问题是我们可以在android中使用PDfBox。
这里是我的代码: - 使用PDFBox的0.7.3罐子当JVM不能加载类
NoClassDefFoundError的抛出
PDFParser parser = null;
String parsedText = null;
PDFTextStripper pdfStripper;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
PDDocumentInformation pdDocInfo;
try {
f =new File(Environment.getExternalStorageDirectory()+File.separator+"Download"+File.separator+"Services.pdf");
if(f.exists()){
System.out.println("---------exists-----------");
}else{
System.out.println("------NOT----exists----------");
}
parser = new PDFParser(new FileInputStream(f));
} catch (Exception e) {
System.out.println("Unable to open PDF Parser.");
System.out.println("-----------------------error|"+e.toString());
}
try {
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);//here i'm getting exception
//pdDoc = PDDocument.load(f, false);
parsedText = pdfStripper.getText(pdDoc);
} catch (Exception e) {
System.out.println("-----------------------error|"+e.toString());
System.out.println("An exception occured in parsing the PDF Document.");
e.printStackTrace();
try {
if (cosDoc != null) cosDoc.close();
if (pdDoc != null) pdDoc.close();
} catch (Exception e1) {
e.printStackTrace();
}
}
System.out.println("Done.");
System.out.println("-----------------------parsedText|"+parsedText);
。
As the javadoc says
编译期间,您是否在类路径中包含pdfbox库?
似乎PDFBox取决于Android设备上不可用的awt和swing类。
因此,您无法在Android上使用PDFBox。
如果您只需要从Android中的PDF文档提取文本,然后使用此https://github.com/RatheeshRavindran/PDFBoxLight 我最近做了PDFBox移植到Android,但请注意,这仍然在测试版。
好的,我会试试这个:) – Prachi 2014-06-06 07:08:43
我们可以看到你的代码.... – 2012-03-14 07:43:38
@Vincent我已经发布的代码只是检查 – Prachi 2012-03-14 08:20:44