6

I have an app where I've button on a webpage that is rendered inside a webview.

Now on click of button , a pdf file gets downloaded , and the same would then need to be opened inside the same webview.

4 Answers 4

30

attach a download listener to the web view and change the url as follows..

"https://docs.google.com/gview?embedded=true&url=https://www.example.com/xxxxxyyyyyxz.pdf"

example

https://docs.google.com/gview?embedded=true&url=https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf

it's a link used to open pdf without downloading it...

I hope it solves your problem..

Sign up to request clarification or add additional context in comments.

3 Comments

This is bad solution, because if google changes link, you will be forced to make application update. But after research, I guess this is the only one way :(
The URL no longer exists.
Please mark this as correct answer if solves your problem
10

I've found that the google viewer seems to work within the android browser for viewing online PDF files. You could build a link to your pdf so that it is displayed in the viewer. I've not tried doing that within a WebView though.

UPDATE

The link is dead, there is an explanation of how to get the functionality to still work at this link.
In case this link also dies, here is the relevant section:

While the page is no longer available as it redirects to Google Docs/Drive, you can still use the Google Docs Viewer. Paste this URL in a new tab:

https://docs.google.com/viewer?url=

and then paste the address of the document you want to view online. Here's an example:

https://docs.google.com/viewer?url=http://research.google.com/archive/bigtable-osdi06.pdf

2 Comments

i tried using the google viewer with link something like below:-
the link is dead unfortunately
1

I do not think that the present android chrome based browser can support pdf. There are discussion about the same in android forums ( ex: link1 link2)

Your best bet to show pdf is to have adobe pdf reader for android installed.(or concisely put, not possible in web view)

2 Comments

thanks.so are you saying that the only possible solution is to open the pdf url contents , save the file on sdcard/phone memory as a .pdf file and then open inside a separate activity?
Yes. Of course you can decorate the activity window to look like a web view, but at least according to me, its an unnecessary hack.
1

I don't think any browser other than Chrome supports rendering PDFs without a plugin or third party tool. It's probably easier to let the user use his own app to open PDFs.

I used the IText PDF library mentioned in this thread Android : Is there any free PDF library for Android for a sample project. You could try getting using this API to get the PDF page as an image. I am not familiar with every aspect of Itext so it might have better way to do this.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.