Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open local PDF file in WebView using Google Docs

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?

like image 526
Alfie Hanssen Avatar asked Oct 01 '13 14:10

Alfie Hanssen


People also ask

How do I open a local PDF in Google Docs?

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.

How can I display a PDF document into a WebView?

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.

Can PDF files be opened in Google Docs?

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.

Can we show PDF in a WebView Android?

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.


1 Answers

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).

like image 134
CommonsWare Avatar answered Sep 23 '22 05:09

CommonsWare