PDFBox的在Android的处理PDF格式 [英] PDFBox for processing pdf in android
本文介绍了PDFBox的在Android的处理PDF格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用PDFBOX lib放到我的Android应用程序,但即时得到
i am trying to use pdfbox lib into my android app but im getting
java.lang.NoClassDefFoundError: org.pdfbox.pdmodel.PDDocument
此错误。至于我正在开发的商业应用。所以我的问题是,我们能在Android中使用PDFBOX我不能使用其他库的iText像
this error .as i'm developing commercial app i can not use other Lib like itext .So my question is can we use PDfBox in android.
这是我的code: -
here is my code:-
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罐子
using PDFBox 0.7.3 jar
推荐答案
似乎PDFBox的是依赖于不可用的Android设备上的AWT和Swing类。
It seems that PDFBox is depending on awt and swing classes that are not available on Android devices.
因此,你不能在Android上使用PDFBox的。
Therefor you can not use PDFBox on Android.
这篇关于PDFBox的在Android的处理PDF格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文