DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.18k stars 1.91k forks source link

When I use onRender(new OnRenderListener(), the PDF is not displayed #1018

Open AlejandroGomz opened 3 years ago

AlejandroGomz commented 3 years ago

Hi,

when I use onRender(new OnRenderListener(), the PDF is not displayed. If I don't use the RenderListener, the PDF document is displayed. What am I doing wrong?

Android API 30 implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'

    pdfView=findViewById(R.id.pdfv);
    pdfView.useBestQuality(true);
    pdfView.fromUri(uri)
            .onError(e -> Log.e(TAG, "openPDFFile Error: "+e))
            .nightMode(false)
            .onLoad(nbPages -> {
                Log.d(TAG, "openPDFFile..load completed");
            })
            .onRender(new OnRenderListener() {
                @Override
                public void onInitiallyRendered(int nbPages) {
                    Log.d(TAG, "openPDFFile..render completed nbPages: "+nbPages);
                    pdfView.fitToWidth(nbPages);
                }
            })
            .load();

It seems, that fitToWidth() makes some troubles, because onLoad() is faster then onRender()?

Basti189 commented 2 years ago

Do not use the param nbPages, you have to use the page number that is visible at this moment