我使用AsyncTask类使用PDFBox从pdf文件中获取文本。但问题是,如果pdf文件的大小非常大,那么加载需要花费大量时间。是否还有其他解决方案可以从大型pdf文件中获取文本或内容。这是我的课程:
public class AsyncTaskClass extends AsyncTask<Void,Void,Void>{
@Override
protected void onPreExecute(){
super.onPreExecute();
pd.setMessage("Loading...");
pd.show();
}
@Override
protected Void doInBackground(Void... voids) {
String root = Environment.getExternalStorageDirectory().getAbsolutePath();
final File file = new File(root+"/download/half-girlfriend-chetan-bhagat.pdf");
try {
PDDocument document = PDDocument.load(file);
PDFTextStripper stripper = new PDFTextStripper();
text = stripper.getText(document);
}catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
pd.dismiss();
getcontent.setText(text);
}
}