md sohan
md sohan

Reputation: 73

Barteksc Android PDFView library not handling incomplete or corrupted PDF files correctly

I'm currently using the (com.github.barteksc:android-pdf-viewer:2.8.2) PDFView library in my Android application to display PDF files. The problem is that when the PDF file is incomplete or corrupted, the library still attempts to open it, resulting in a white view. No Exception is being thrown So I have no idea how to handle it.

void loadFile(){
        try {
            myPDFViewer.fromFile(pdfFileName)
                    .defaultPage(2)
                    .scrollHandle(new DefaultScrollHandle(this))
                    .load();
        } catch (Exception e){
            Intent start = new Intent(getApplicationContext(), Downloader.class);
            start.putExtra("pdfFileName", pdfFileName);
            startActivity(start);
            finish();
        }
    }

Can someone guide me on how to handle incomplete or corrupted PDF files using the PDFView library So that it don't show blank page? How can I ensure that the file is a valid PDF before attempting to load it? Any help or suggestions would be greatly appreciated.

Upvotes: 0

Views: 234

Answers (0)

Related Questions