wheels53
wheels53

Reputation: 739

Android WebView shows html instead of the pdf or document

I have a webview with javascript enabled and I'm attempting to display pdf, docs, etc... using google docs view url. The problem is that the webview is rendering html instead of the doc. I should mention that this also occurs with a url to a pdf or doc from my dropbox account.

string pdf = "https://docs.google.com/document/d/1SGFAxaYSA2wBvKCKL89rYG4yEZIJVIJ2lY-1G7IF6g4/edit?usp=sharing";
webViewcontent.LoadUrl("https://docs.google.com/gview?embedded=true&url=" + pdf);

This is what is showing: enter image description here

Upvotes: 2

Views: 1351

Answers (2)

Jake
Jake

Reputation: 356

I think the url you are looking for is...

 string url = "https://docs.google.com/document/d/1SGFAxaYSA2wBvKCKL89rYG4yEZIJVIJ2lY-1G7IF6g4/edit?usp=sharing";
 string myUrl = string.Format("https://docs.google.com/viewer?url={0}", url);
 webViewcontent.LoadUrl(myUrl);

This will work without the user having a google account.

However, since your url is using https it may require authentication.

Upvotes: 1

Ryan S
Ryan S

Reputation: 4567

string pdf = "https://docs.google.com/document/d/1SGFAxaYSA2wBvKCKL89rYG4yEZIJVIJ2lY-1G7IF6g4/edit?usp=sharing";
webViewcontent.LoadUrl("https://docs.google.com/gview?embedded=true&url=" + pdf);

the final url of this will be https://docs.google.com/gview?embedded=true&url=**https://docs.google.com/document/d/**1SGFAxaYSA2wBvKCKL89rYG4yEZIJVIJ2lY-1G7IF6g4/edit?usp=sharing, I think you want to remove everything except for the document id.

Upvotes: 0

Related Questions