https://kotlinlang.org logo
#compose
Title
# compose
d

dorche

06/21/2022, 3:34 PM
Has anyone done a PDF Viewer type of component in Compose? Would people generally just wrap existing libraries that were build for the old view system? Looking for the correct/good way of doing this, in a full compose app (don’t mind wrapping an android view tho if that’s what we have to do).
j

Joseph Hawkes-Cates

06/21/2022, 7:32 PM
Are you wanting to view the pdf inside of your app or is opening it with another app sufficient? We did this in our app which is fully Compose but we just fired an Intent to open the app after downloading it so nothing really Compose specific for our usecase.
d

dorche

06/21/2022, 7:46 PM
I want it to be shown in-app. When you say "we did this" do you mean you open it in another app?
I'm thinking of wrapping https://github.com/voghDev/PdfViewPager or similar in Compose
j

Joseph Hawkes-Cates

06/21/2022, 7:50 PM
Yeah, we create a View Action intent and do startActivity on that, so it’ll show the PDF in whatever app they have that can read PDFs. For our testing that’s typically Google drive, but could be adobe or whatever.
d

dorche

06/21/2022, 7:51 PM
Yeah unfortunately our requirements are to show the PDF in-app :/
j

Joseph Hawkes-Cates

06/21/2022, 7:52 PM
I haven’t heard of any Compose specific things that’ll do that. I think wrapping an existing view-based library in a Compose AndroidView should work fine.
We used the WebView from Accompanist to do something similar with a WebView in our app so you can look at Google’s impl there for a good example of using AndroidView to do something like that
d

dorche

06/21/2022, 7:55 PM
Yeah we've done it before too for other components like you said, I was just wondering if there is a better way to do it fully in Compose
j

Joseph Hawkes-Cates

06/21/2022, 7:59 PM
Yeah, hopefully someone else has something good for you 🤞 , but I haven’t seen anything like that so far.
🤞 1
169 Views