Open local PDF file in WebView using Google Docs

2020-06-04 08:49发布

问题:

There are a million similar questions/answers, all addressing how to open a remote PDF file using Google Docs + webview.

None address how to open a local PDF file.

Given these strings:

String remotePath = "https://myserver.com/data/files/organization/4/pdf/kalinka1369-1374847709-55.pdf";

String localPath = "file:///storage/emulated/0/Droid Noid/com.story.chapters/kalinka1369-1374847709-55.pdf";

String googleDocsURL = "https://docs.google.com/gview?embedded=true&url=";

This works:

webview.loadUrl(googleDocsURL + remotePath);

Whereas this does not:

webview.loadUrl(googleDocsURL + localPath);

I realize there is a space in localPath and I have tried encoding it to no avail:

String encodedLocalPath = "file:///storage/emulated/0/Droid+Noid/com.story.chapters/kalinka1369-1374847709-55.pdf";

Is it possible to open a local PDF file using Google Docs + webview? If so, how?

回答1:

Is it possible to open a local PDF file using Google Docs + webview?

Only if you upload the PDF somewhere on the Internet where Google Docs can access it, or perhaps arrange for somebody else to upload the PDF somewhere on the Internet where Google Docs can access it (e.g., Google Drive).