1

I have to display a pdf from URL. When i directly open the url in a webview then it asks me to download the pdf and then view based on the app that i want to use to view it. But I do not want to download the pdf, it must be just displayed directly.

Some answers that I went through on SO recommended to make use of docs.google.com

like here: How to display a PDF via Android web browser without "downloading" first

But this doesnt seem to be working anymore.

Community
  • 1
  • 1
frgr
  • 65
  • 2
  • 11
  • 'Doesnt seem to work' is not a very accurate description of your problem. – fweigl Dec 20 '15 at 11:18
  • I think you are getting something wrong. To display the content of a .pdf, it always has to be downloaded first. What you want to achieve is to only temporarily download it, and delete it again after the user exited the .pdf viewer. – PKlumpp Dec 20 '15 at 11:20
  • It just displays that preview not available. Even the older examples that I went through, at the time when google had introduced this, even those examples are now showing that preview not available. – frgr Dec 20 '15 at 11:20
  • @ZerO What i want is that the pdf must not be downloaded on the device. Earlier there have been solutions using google docs url, similar to the answer that I have shared in my question, but now that is not working. – frgr Dec 20 '15 at 11:22
  • The pdf is always loaded into a cache, and therefore downloaded. – PKlumpp Dec 20 '15 at 11:26
  • how can we do that in cache, coz currently when I access the direct link in my webview of the app or even in the browser using intents, it is downloading it in the main memory i.e downloads. – frgr Dec 20 '15 at 11:31

2 Answers2

1

Use this one:

https://docs.google.com/viewer?url=[url_pdf]

eg. webview.loadUrl("https://docs.google.com/viewer?url=https://www.unipg.it/files/pagine/410/4-PDF-A.pdf");

carlol
  • 2,220
  • 1
  • 16
  • 11
  • 2
    Thanks for the answer, but I already tried this, and this is not working for me, I get the same output, "Preview not available". – frgr Dec 20 '15 at 11:54
0

use this inside your body tags

    <iframe src="http://example.com/yourpdf" width="100%" height="100%" style="border: none;">This browser does not support PDFs. Please download the PDF to view it: <a href="http://example.com/yourpdf">Download PDF</a></iframe>
IAmJason
  • 1
  • 2