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.

RobinHood
  • 10,897
  • 4
  • 48
  • 97

4 Answers4

28

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

K J
  • 8,045
  • 3
  • 14
  • 36
Alok Gupta
  • 1,806
  • 22
  • 21
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

dave.c
  • 10,910
  • 5
  • 39
  • 62
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)

uncaught_exceptions
  • 21,712
  • 4
  • 41
  • 48
  • 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? – eatSleepDrinkJava.repeat Feb 09 '11 at 16:36
  • 2
    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. – uncaught_exceptions Feb 09 '11 at 16:46
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.

Community
  • 1
  • 1
SidJ
  • 669
  • 12
  • 29