如何一一加载pdf页面?

use*_*408 5 java pdf performance android

在我的应用程序中,我想加载 pdf 文件并向用户显示,一些 pdf 文件超过 20mb,有很多页。有时加载pdf需要很长时间。所以,我想知道是否有可能一页一页地加载,

就像加载第一页,然后在加载第二页时向用户显示..

我正在使用这个库:

'com.github.barteksc:android-pdf-viewer:2.8.2


public class FlyerActivity extends AppCompatActivity {

    private PDFView mPDFview;

    private String mStoreId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flyer);

        mPDFview = (PDFView) findViewById(R.id.flyer_pdfView);
        showPdf(mStoreId);
    }

    private void showPdf(String storeId) {
        mReference.child(storeId).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Store storeChain = dataSnapshot.getValue(Store.class);
                String pdfUrl = storeChain.getFlyerPDF().toString();

                ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar2);
                progressBar.setVisibility(View.VISIBLE);

                new RetrievePDFStream().execute(pdfUrl);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });
    }

    class RetrievePDFStream extends AsyncTask<String, Void, InputStream>
    {
        @Override
        protected InputStream doInBackground(String... strings)
        {
            InputStream inputStream = null;
            try{
                URL url = new URL(strings[0]);
                HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();

                if (urlConnection.getResponseCode()==200)
                {
                    inputStream = new BufferedInputStream(urlConnection.getInputStream());
                }
            }
            catch (IOException e)
            {
                return null;
            }

            return inputStream;
        }

        @Override
        protected void onPostExecute(InputStream inputStream) {

            mPDFview.fromStream(inputStream).load();
            ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar2);
            progressBar.setVisibility(View.GONE);

        }
    }

}
Run Code Online (Sandbox Code Playgroud)

小尺寸的 pdf 文件加载得很好,但大尺寸的 pdf,即使是 10 页的 5mb 也需要一些时间来加载。

只加载一页也不起作用.. 看起来这会加载完整的 pdf 文件,然后只显示一页。

mPDFview.fromStream(inputStream).pages(0).load();
Run Code Online (Sandbox Code Playgroud)