6

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?

Alfie Hanssen
  • 16,964
  • 12
  • 68
  • 74
  • If it is acceptable to use something as adobe reader instead, I have code for that. I behaves nicely, going to fullscreen and returns to your app on backpress, though I can understand the value of having it embedded on the device. On the other hand it is ready immediately no matter the availability of internet access – cYrixmorten Oct 01 '13 at 15:03

1 Answers1

9

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

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Ha, okay well sounds like it's definitively not possible unless I make it a remote file. Thanks! – Alfie Hanssen Oct 01 '13 at 18:17
  • i was breaking my head over it..how to have a reliable url for my pdf files. Google drive is a damn good idea. ty :) – Prabs Aug 22 '16 at 16:54
  • @commonsWare I've uploads my '.pdf' doc to google drive. It's link is something like this `https://drive.google.com/file/d/0B0ecHy3Xov6tT0hINUZ5djRNZkk/view` which is not of format `http://www.abcd.com/sample.pdf`. Now how should I open it in web view using google docs? If the general format is used then it would be `https://docs.google.com/gview?embedded=true&url=https://drive.google.com/open?id=0B0ecHy3Xov6tT0hINUZ5djRNZkk` – Prabs Aug 29 '16 at 17:56
  • @Prabs: I have not used Google Drive for this. I would assume that you just replace the `url` parameter with your URL. There is nothing in the Drive URL that should be a problem as a query parameter value. – CommonsWare Aug 29 '16 at 18:03
  • I'm sorry but I didn't understand what you are trying to say. could you kindly give an example with the above link if possible. what should be in `loadurl`. is it `loadurl(myUrl)` or anything else – Prabs Aug 29 '16 at 18:42