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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] IOException: file not in PDF format or corrupted #114

Closed
dookki opened this issue Mar 13, 2024 · 9 comments
Closed

[BUG] IOException: file not in PDF format or corrupted #114

dookki opened this issue Mar 13, 2024 · 9 comments
Labels
Awaiting response bug Something isn't working Fixed Scheduled to release

Comments

@dookki
Copy link

dookki commented Mar 13, 2024

馃摑 Describe the Bug

Recently I encountered some problems with the app crash IOException, about malformed links or broken links (404)..., this case does not fall into the onError function in PdfRendererView.StatusCallBack, even though I catch the exception with try, catch but it still happens

馃摉 Library Version

  • PDF Viewer Version: Any...

image

@dookki dookki added the bug Something isn't working label Mar 13, 2024
Copy link

Thank you for creating your first issue. We appreciate your help in making this project better. We will look into it, and get back to you soon. Need help or want to discuss this issue? Join our Discord community here to ask questions and discuss this issue live!

@afreakyelf
Copy link
Owner

Hey @dookki, do you mind sharing the URL of the pdf and your implementation if possible.

@houkhan
Copy link

houkhan commented Mar 26, 2024

Hey The url I'm using is https://css4.pub/2015/textbook/somatosensory.pdf
I have also encountered related problems. When opening a relatively large pdf, when the PDF is still loading, that is, the loading animation has not disappeared, closing the page at this time will have this problem when rewriting and opening. When following the crash log.

************* Crash Head ****************
Time Of Crash      : 2024_03_26-10_14_45
Rom Info           : RomInfo{name=xiaomi, version=V12.5.1.0.QEECNXM}
Device Manufacturer: Xiaomi
Device Model       : MIX 3
Android Version    : 10
Android SDK        : 29
App VersionName    : 1.1
App VersionCode    : 2
************* Crash Head ****************

java.io.IOException: file not in PDF format or corrupted
	at android.graphics.pdf.PdfRenderer.nativeCreate(Native Method)
	at android.graphics.pdf.PdfRenderer.<init>(PdfRenderer.java:169)
	at com.rajat.pdfviewer.PdfRendererCore.openPdfFile(PdfRendererCore.kt:142)
	at com.rajat.pdfviewer.PdfRendererCore.<init>(PdfRendererCore.kt:76)
	at com.rajat.pdfviewer.PdfRendererView.init(PdfRendererView.kt:148)
	at com.rajat.pdfviewer.PdfRendererView.init(PdfRendererView.kt:143)
	at com.rajat.pdfviewer.PdfRendererView.initWithFile(PdfRendererView.kt:107)
	at com.rajat.pdfviewer.PdfRendererView$initWithUrl$1.onDownloadSuccess(PdfRendererView.kt:96)
	at com.rajat.pdfviewer.PdfDownloader.checkAndDownload(PdfDownloader.kt:54)
	at com.rajat.pdfviewer.PdfDownloader.access$checkAndDownload(PdfDownloader.kt:13)
	at com.rajat.pdfviewer.PdfDownloader$1.invokeSuspend(PdfDownloader.kt:31)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
	at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
	at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
	at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
	at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
	at com.rajat.pdfviewer.PdfDownloader.<init>(PdfDownloader.kt:31)
	at com.rajat.pdfviewer.PdfRendererView.initWithUrl(PdfRendererView.kt:84)
	at com.rajat.pdfviewer.PdfViewerActivity.initPdfViewer(PdfViewerActivity.kt:360)
	at com.rajat.pdfviewer.PdfViewerActivity.loadFileFromNetwork(PdfViewerActivity.kt:351)
	at com.rajat.pdfviewer.PdfViewerActivity.init(PdfViewerActivity.kt:254)
	at com.rajat.pdfviewer.PdfViewerActivity.onCreate(PdfViewerActivity.kt:243)
	at android.app.Activity.performCreate(Activity.java:7893)
	at android.app.Activity.performCreate(Activity.java:7880)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3283)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3457)
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
	at android.os.Handler.dispatchMessage(Handler.java:107)
	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)

@houkhan
Copy link

houkhan commented Mar 26, 2024

If it cannot be reproduced, you can replace a relatively large pdf, then close it when it is loaded again, and then reopen it. It should be the problem that the resource is not released when the loading is not successful.

@houkhan
Copy link

houkhan commented Mar 26, 2024

After checking, it is found that it is caused by the if (cachedFile.exists()) of the PdfDownloader checkAndDownload. If it is closed without downloading successfully, the file is damaged and tries to modify it. However, this will trigger a re-download every time.

        if (cachedFile.exists()) {
            cachedFile.deleteRecursively()
        }
        download(downloadUrl, cachedFileName)

@houkhan
Copy link

houkhan commented Mar 26, 2024

Or modify it like this.
This will try to download again after the pdf fails to open.

        if (cachedFile.exists()) {
            try {
                listener.onDownloadSuccess(cachedFile.absolutePath)
            } catch (e: Exception) {
                download(downloadUrl, cachedFileName)
            }

        } else {
            download(downloadUrl, cachedFileName)
        }

@afreakyelf
Copy link
Owner

Hi, The Above issue has been fixed in new release. https://github.com/afreakyelf/Pdf-Viewer/releases/tag/v2.1.0

Please migrate to Maven central. More here: https://github.com/afreakyelf/Pdf-Viewer/releases/tag/v2.1.0

Thank you for using the library. Please reopen/raise a new issue if you still face this error.

Join our discord for more updates!

@dookki
Copy link
Author

dookki commented Apr 1, 2024

I apologize for the delayed response. Thank you for fixing this error.

@susi021
Copy link

susi021 commented Apr 12, 2024

I'm still facing the same issue when I try to open a random txt file as a PDF using PdfRendererViewCompose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting response bug Something isn't working Fixed Scheduled to release
Projects
None yet
Development

No branches or pull requests

4 participants