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?
If you have a document you want to open on your computer, click on the 'File' and from the drop-down menu, select 'Open. ' Then select the 'Upload' tab and click on 'Select a file from your device' option. Once you select the file, it will automatically open in Google Docs.
The very first and the easiest way of displaying the PDF file is to display it in the WebView. All you need to do is just put WebView in your layout and load the desired URL by using the webView. loadUrl() function. Now, run the application on your mobile phone and the PDF will be displayed on the screen.
Once your file has uploaded to Google Drive, click on the file and you'll see an 'Open with' option. Select 'Google Docs' to open the PDF as an editable file.
We can load PDF in android easily using WebView. We will be using the simplest way for displaying PDF file in android. Using the Google Docs PDF viewer we could do this easily.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With