How to load a local PDF into webView?

81 Views Asked by At

I am using ActivityResultContracts.OpenDocument() to open a PDF. I get its uri.

But how can I load it into a webView component? I'm using SDK 33.

Code

2

There are 2 best solutions below

0
Gabe Sechan On BEST ANSWER

You don't. It's a webview, it displays HTML, not PDF. It doesn't have a PDF viewing mode. There are some hacks out there where you upload the file to google docs or similar sites then open a webview to that site, but the webview won't be able to display a local pdf.

0
MexiCano On

Try this:

webView?.loadUrl(uri.patch!!);

this example works for me Load Pdf webview