0

I am using AsyncTask class to fetch text from a pdf file using PDFBox. But the problem is that if the size of pdf file is very large then it takes a huge amount of time to load. Is there are any other solutions to fetch text or content from large pdf file.This is my class:

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);
    }
}
Itava
  • 45
  • 8
  • Please refer this link [enter link description here](https://stackoverflow.com/questions/10299839/how-to-read-pdf-in-my-android-application) i think it is use full for you. – Kunjeti Aswarthamaiah Gupta Jul 19 '17 at 13:03
  • If the text extraction is what takes so long, you might want to do each page separately and display a progress animation. – Tilman Hausherr Jul 20 '17 at 09:52
  • You may want to parallize it - use several asynctask task and up to one per page if your have the CPU power to do that. – Lonzak Jul 20 '17 at 13:08

1 Answers1

0

By using BackgroundTask this problem is solved for me, Because loading is happening on background.

I am using this answer to solve my problem.

Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39