5

I'm building a web app for internal use of a company that uses Samsung tablets (Android 9 and Chrome latest versions). I have a page with a list of links to PDF documents and the problem is that when I click any of them, they do not open automatically but instead show an Open button asking to open the document. If I click Open, the document opens as expected with the default viewer (Google PDF Viewer). When I go back, the Open button is still there. If the document has already been downloaded, the browser asks whether to download it again. These images show the situation:

http://www.maresme.net/stackoverflow/chrome_android_pdf/open_button.jpg http://www.maresme.net/stackoverflow/chrome_android_pdf/allow_auto_downloads.jpg

Is it possible to bypass this step and have the docs open automatically without showing this button? I want to avoid this button and that when users go back from reading the doc they find again the list of links to other PDFs.

I've tried different methods of embedding PDFs (embed, object and iframe) without success. Also, I considered using pdf.js with the canvas tag but my webapp must also work offline and this solution uses too much resources.

Searching the net I found references about an option in Chrome under "Privacy and security" to allow automatic opening of the PDFs but this option does not appear in the tablets I'm using. Is it a security restriction that can't be bypassed?

I will really thank any help with this, it's driving me nuts.

  • Hey @Llorenc if you could include some code that shows what you are doing that would be extremely helpful. Also include what technology stack you are using to create this webpage. – yams Jan 02 '20 at 18:49
  • Hi. This is a vanilla javascript webapp, I'm only using jquery to help me with selectors and other bits. The html links have an onclick handler that feed an embed tag. It works OK except from this Open button I can't get rid of. – Llorenc Sole Jan 02 '20 at 19:17

1 Answers1

3

I'm going to answer myself: the problem with Chrome mobile is that it has no support for extensions, so there is no PDF plugin that allows to view this kind of files within the browser. When you intend to open a PDF file the browser has to open it in an external app, be the default viewer (if defined) or any other which is capable (a list will be presented). This is why it asks permission, which I suppose it's a security measure and don't know how/if it can be circumvented.

With pdf.js (and other commercial kits) you can parse the PDF file using JavaScript in the browser, so no plugins are required. However, you must include all this code in your PWA for offline use (and there is some). Another approach that has worked for me is to use the Kiwi browser which supports extensions (I have a closed group of users and I can force this) and then use a plugin, for instance, the plugin version of pdf.js.

Hope this helps someone.

lsole
  • 75
  • 5