GRizzi91 / bouquet

PDF reader Android library based on Jetpack Compose
Apache License 2.0
151 stars 32 forks source link

When PDF file is about 50 MB it doesn't work #26

Closed 10zgurr closed 1 year ago

10zgurr commented 1 year ago

Hi,

thank you for the library first of all. I have this issue that when I try with a 50 MB file's URL (https://www.learningcontainer.com/sample-pdf-files-for-testing) it doesn't work :/

ncubes-dev commented 1 year ago

I also have this problem but overally the library is awesome

GRizzi91 commented 1 year ago

@10zgurr @ncubes-dev i don't understand, i try to upload the 50mp pdf file to my host and i can open it whitout problem. Can you try to load this url pls? https://myreport.altervista.org/sample-50-MB-pdf-file.pdf Also what url you try to open? And can you give me more info, like the behavior or if the lib throw an exception?

10zgurr commented 1 year ago

this is the url im using -> https://www.learningcontainer.com/sample-pdf-files-for-testing even with your URL it still doesn't work, it stucks with the background color and there is no info or error logs in the logcat

Screenshot_20230511_092859

GRizzi91 commented 1 year ago

This url (https://www.learningcontainer.com/sample-pdf-files-for-testing) is not a pdf resource so it's normal that you cant open the pdf. All in all can you share your code? If you prefer you can upload your project on a private repo and add me has a contributor @10zgurr

10zgurr commented 1 year ago
val pdfState = rememberVerticalPdfReaderState(
        resource = ResourceType.Remote("https://myreport.altervista.org/sample-50-MB-pdf-file.pdf"),
        isZoomEnable = true
    )
    Box {
        VerticalPDFReader(
            state = pdfState,
            modifier = Modifier
                .fillMaxSize()
                .background(color = Color.Gray)
        )
        pdfState.file?.let { file ->
            Button(
                modifier = Modifier.size(60.dp),
                onClick = {
                    // save file
                    share(context = context, pdfFile = file)
                }
            ) {
                Icon(
                    modifier = Modifier.size(60.dp),
                    painter = painterResource(id = android.R.drawable.ic_menu_share),
                    contentDescription = "share"
                )
            }
        }
    }
10zgurr commented 1 year ago

this is the code blocks that im using with implementation 'io.github.grizzi91:bouquet:1.0.2' lib version

GRizzi91 commented 1 year ago

50mbpdf.webm I just add a linear progress bar to show download progress and work well, it toke some time but ehi it's a 50mb pdf.

val pdfState = rememberVerticalPdfReaderState(
                            resource = ResourceType.Remote("https://myreport.altervista.org/sample-50-MB-pdf-file.pdf"),
                            isZoomEnable = true
                        )
                        Box {
                            VerticalPDFReader(
                                state = pdfState,
                                modifier = Modifier
                                    .fillMaxSize()
                                    .background(color = Color.Gray)
                                    .padding(padding)
                            )
                            pdfState.file?.let { file ->
                                Button(
                                    modifier = Modifier.size(60.dp),
                                    onClick = {
                                        // save file

                                    }
                                ) {
                                    Icon(
                                        modifier = Modifier.size(60.dp),
                                        painter = painterResource(id = android.R.drawable.ic_menu_share),
                                        contentDescription = "share"
                                    )
                                }
                            }
                            LinearProgressIndicator(
                                progress = pdfState.loadPercent / 100f,
                                color = Color.Red,
                                backgroundColor = Color.Green,
                                modifier = Modifier.fillMaxWidth()
                            )
                        }
10zgurr commented 1 year ago

it stucks in this screen forever even though I believe the download is finished :/ there is no log in the logcat and I'm testing on pixel5 device android 11 (same issue for android emulator with android 13)

pixel5: Screenshot_20230511_144514

emulator android 13: Screenshot_1683809346

ihor-bezeka commented 1 year ago

Hello @GRizzi91, your lib looks awesome and works fine with PDF files for 2-5 pages, but with bigger files, I have a problem:

On some devices, I have an OutOfMemoryError. (Sony Xperia Z5 Compact)

On a virtual device, Google Pixel 2 (with default memory settings), when I try to load a huge PDF file, it looks like nothing happened, and the loading is stuck.

GRizzi91 commented 1 year ago

@ihor-bezeka this sounds me strange, in demo app the remote file is a pdf with more thant 5 page and work well. I also tested with bigger and heavy pdf and i never get OOM. Can you let me have the pdf that you are talking abount?

ihor-bezeka commented 1 year ago

@GRizzi91, sorry for the late response. Here it is: https://www.thebookcollector.co.uk/sites/default/files/the-book-collector-example-2018-04.pdf

I guess the problem is with the page count and not just the size of the file.

GRizzi91 commented 1 year ago

@ihor-bezeka can you try to run a build from this branch pls? Test branch i have uploaded the pdf on my space and replaced the url in the test app so you can try to open the pdf by selecting the "Remote resource" section i cannot reproduce the problem.

ihor-bezeka commented 1 year ago

@GRizzi91 The same problem with the assets pdf file (raw/lorem_ipsum.pdf). On Pixel 2 API v.23

I have tested on Samsung s10, s22, and emulators Resizable (Experimental) API v.33 everything works fine. But on Pixel 2 API v.23, OOM throws at the start of loading, and on Pixel 2 API v.29, OOM throws near the end of the loading even if the memory settings of these emulators are the same.

Maybe setting these memory settings will help with catching the OOM:

Screenshot 2023-05-16 at 15 26 22
GRizzi91 commented 1 year ago

Ok i found the problem, ill fix the issue as soon as possible

GRizzi91 commented 1 year ago

@ihor-bezeka @10zgurr New version is out 1.1.2, now the lib will require only 1/8 of the memory required by the 1.1.1

ihor-bezeka commented 1 year ago

@GRizzi91, it works much better! But now I have OOM when trying to scroll through a PDF document. When the document scrolled to the 3-5 page, I got OOM.

Should I open a new Issue, or can this bug be solved in the scope of this issue?

ncubes-dev commented 1 year ago

When I open local documents that have many pages or bigger size

On Mon, 22 May, 2023, 14:19 ihor-bezeka, @.***> wrote:

@GRizzi91 https://github.com/GRizzi91, it works much better! But now I have OOM when trying to scroll through a PDF document. When the document scrolled to the 3-5 page, I got OOM.

Should I open a new Issue, or can this bug be solved in the scope of this issue?

— Reply to this email directly, view it on GitHub https://github.com/GRizzi91/bouquet/issues/26#issuecomment-1557122608, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5IKK7W3EVKVKDDBN3UXZLTXHNKVFANCNFSM6AAAAAAX43BTS4 . You are receiving this because you were mentioned.Message ID: @.***>