我正在尝试在我的 Android 应用程序中使用 pdfbox lib,但我得到了
java.lang.NoClassDefFoundError: org.pdfbox.pdmodel.PDDocument
这个错误。因为我正在开发商业应用程序,所以我不能使用其他库,例如itext。所以我的问题是我们可以在android中使用PDfBox。
这是我的代码:-
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);
使用 PDFBox 0.7.3 jar
最佳答案
PDFBox 似乎依赖于 Android 设备上不可用的 awt 和 swing 类。
因此您无法在 Android 上使用 PDFBox。
关于android - PDFBox用于在android中处理pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9696157/