GRizzi91 / bouquet

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

open PDF from assets #23

Closed MBahramiGitMit closed 1 year ago

MBahramiGitMit commented 1 year ago

Hi How can I open a file from the assets folder by this library? thanks

GRizzi91 commented 1 year ago

Actually i'm not sure, now i don't have free time to try but i can add support for local assets in future release. I think you can try somethings like this

                    val assetName = "pdfname"
                    val inFile = context.assets.open(assetName)
                    val outFile = File(context.cacheDir,"newPdfFileName.pdf")
                    inFile.readBytes().let {
                        outFile.outputStream().apply {
                            write(it)
                            flush()
                            close()
                        }
                    }
                    inFile.close()
                    val uri = Uri.fromFile(outFile)
                    ResourceType.Local(uri = uri)
GRizzi91 commented 1 year ago

Asset support added in 1.1.1

Matej-Hlatky commented 9 months ago

Hi,

Asset support added in 1.1.1

So how was the support for Assets added and where? In v1.1.2, there are 4 ResourceTypes: Local, Remote, Base64 and Asset; however the last one should be better named Resource rather than Asset, since it requires @RawRes and not String / URI.