gpt4 book ai didi

android - 用于在 android 中处理 pdf 的 PDFBox

转载 作者:行者123 更新时间:2023-11-29 00:40:30 25 4
gpt4 key购买 nike

我正在尝试将 pdfbox lib 用于我的 android 应用程序,但我正在获取

 java.lang.NoClassDefFoundError: org.pdfbox.pdmodel.PDDocument 

这个错误。因为我正在开发商业应用程序,所以我不能使用像 itext 这样的其他 Lib。所以我的问题是我们可以在 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 - 用于在 android 中处理 pdf 的 PDFBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9696157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com