GRizzi91 / bouquet

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

Crash when loading password-protected file #37

Closed benedict-lim closed 1 year ago

benedict-lim commented 1 year ago

Hi again! I'm just wondering if you have any plans to support password-protected files? When I tried opening such a file, my application crashes with the following error.

If there are no such immediate plans, I would have to consider a workaround to the problem. Please kindly let me know.

java.lang.SecurityException: password required or incorrect password
  at android.graphics.pdf.PdfRenderer.nativeCreate(Native Method)
  at android.graphics.pdf.PdfRenderer.<init>(PdfRenderer.java:172)
  at com.rizzi.bouquet.BouquetPdfRender.<init>(BouquetPdfRender.kt:20)
  at com.rizzi.bouquet.BouquetKt$load$1$2.invokeSuspend(Bouquet.kt:254)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
  at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
  at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
  Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@1bd0da2, androidx.compose.runtime.BroadcastFrameClock@4f25a33, StandaloneCoroutine{Cancelling}@91e21f0, Dispatchers.IO]
benedict-lim commented 1 year ago

I just researched online and it seems that supporting password-protected PDF files is difficult by conventional means. In that case, if you would kindly catch the SecurityException and set it to PdfReaderState's error, I can display a message to the user without the app crashing. Please kindly consider!

benedict-lim commented 1 year ago

I updated the library from 1.0.2 to 1.1.2 and it seems that the exceptions are being caught in the latest version. Thanks for the updates and sorry for creating an issue that is already solved. 🙇