Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot load page error #183

Open
elviss116 opened this issue Apr 21, 2021 · 2 comments
Open

cannot load page error #183

elviss116 opened this issue Apr 21, 2021 · 2 comments

Comments

@elviss116
Copy link

elviss116 commented Apr 21, 2021

hi, i have problem when load some pdfs

i have recyclerview with multiple viewtypes, when i have 5 pdf view, the app crashed

java.lang.IllegalStateException: cannot load page
at android.graphics.pdf.PdfRenderer.nativeOpenPageAndGetSize(Native Method)
at android.graphics.pdf.PdfRenderer.access$300(PdfRenderer.java:105)
at android.graphics.pdf.PdfRenderer$Page.(PdfRenderer.java:312)
at android.graphics.pdf.PdfRenderer$Page.(PdfRenderer.java:289)
at android.graphics.pdf.PdfRenderer.openPage(PdfRenderer.java:230)
at es.voghdev.pdfviewpager.library.adapter.BasePDFPagerAdapter.getPDFPage(BasePDFPagerAdapter.java:162)
at es.voghdev.pdfviewpager.library.adapter.PDFPagerAdapter.instantiateItem(PDFPagerAdapter.java:56)
at androidx.viewpager.widget.ViewPager.addNewItem(ViewPager.java:1010)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1224)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager$3.run(ViewPager.java:273)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1031)
at android.view.Choreographer.doCallbacks(Choreographer.java:854)
at android.view.Choreographer.doFrame(Choreographer.java:785)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1016)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7562)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

this is my android code

class ReleasePdfViewHolder(binding: ItemPublishReleasePdfBinding) : BaseViewHolder(binding), DownloadFile.Listener {

private lateinit var remotePDFViewPager: RemotePDFViewPager
private lateinit var adapterPdf: PDFPagerAdapter
private var listenerPdf : DownloadFile.Listener = this

fun bind(item: PublishView, listener: (publish: PublishView, viewType: PublishAdapter.InnerView) -> Unit){
    binding.publish = item
    binding.executePendingBindings()


    if (item.file_type.equals("C", ignoreCase = true) && item.generic.equals("S", ignoreCase = true) && item.subtypePub.equals("P", ignoreCase = true)){
        println("### LANZAR HOLDER VIEW PDF")
        remotePDFViewPager = RemotePDFViewPager(binding.root.context,item.firstUrlImg,listenerPdf)
    }
}

//TODO: CONFIG LAYOUT PDF
private fun setLayoutToPdf(){
    binding.layoutPdfRoot.removeAllViews()
    binding.layoutPdfRoot.addView(remotePDFViewPager)
}

override fun onSuccess(url: String?, destinationPath: String?) {
    println("## ON SUCCESS PDF RUN")
    adapterPdf = PDFPagerAdapter(binding.root.context, FileUtil.extractFileNameFromURL(url))
    remotePDFViewPager.adapter = adapterPdf
    setLayoutToPdf()
}

override fun onFailure(e: Exception?) {
    e?.let {
        it.printStackTrace()
    }
}

override fun onProgressUpdate(progress: Int, total: Int) {

}

}

@voghDev
Copy link
Owner

voghDev commented Apr 22, 2021

Hi!

it seems you have a RecyclerView with Pdf documents on each row. This can potentially lead to memory issues, as some Pdf documents are quite heavy to load in memory. If you load/unload them as the user scrolls, you may get OutOfMemory exceptions.

Anyway, it seems the PdfRenderer original component is failing to open one of your Pdfs.

  • Have you tried opening such Pdf document in a single PdfViewPager, in an empty Activity?
  • Have you tried opening a small, light Pdf document in every row of your RecyclerView?

@elviss116
Copy link
Author

elviss116 commented Apr 22, 2021

when i load one by one , the pdf open perfect. one way to prevent the app crashing is add a try catch in PDFPageAdapter

try {
PdfRenderer.Page page = getPDFPage(renderer, position);
Bitmap bitmap = bitmapContainer.get(position);
ssiv.setImage(ImageSource.bitmap(bitmap));

        ssiv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pageClickListener.onClick(v);
            }
        });

        page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
        page.close();

        container.addView(v, 0);
    }catch (Exception e){
        System.out.println("### ERROR ### ");
    }

``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants