Research on Open PDF inside Android App or Browser Issue

Issue and Testing

By default, Android’s browsers (includes default browser, Chrome and Firefox) do not support open PDF files inside browser. This also applies to WebView we are using inside app.
This brings up a issue that in our app, when user click Windows Sticker, the pop up windows asks user to choose a browsers to open the link. However, no matter which browsers user use, the file will be downloaded, instead of opened.
I have tested these issue by:
  1. Open windows sticker’s link inside our app.
  2. Open windows sticker’s link from email or notes.
  3. Open normal http links point to a pdf file inside our app
  4. Open normal http link point to a pdf file from email or notes.
All test result shows that for now, we can not achieve the same behavior that we want at beginning, that is, open pdf inside a external browser.

Possible Solutions

There are couple of work around about this problem.

Using PDF reader app to open the link

This solution comes to be the most intuitive one. However there are two risks we need to consider:
  1. The link of Windows Sticker is not a direct link to the pdf file, but a redirection. We need to manually override this behavior to let it open by another app.
  2. The user is very possible doesn’t have a PDF reader app install on the phone!

Using Google Docs embed inside Webview.

Google has provide a google docs web version. Basicly, you just assemble a new url points to the Google’s services, then the Google Docs will open the file inside google drive. This approach also has some risks:
  1. Google constantly changing their services configuration. The embed code has changed in the past and is very likely be changed in the future.
  2. Using this services require user already installed Google Drive and on some phone, asking user to be registered their phone with Google Services.
  3. During testing, this services not coop very well with WebView, though it could display the pdf, the navigation and render speed is very limited.

Intergated PDF render and viewer function inside our app.

This could be the most stable and once for all solution. We could write in our own pdf viewer function inside our app. However, this approach also has some drawback.
  1. There isn’t many good open source PDF rendering libraries available. Unlike other functions such as praise data or UI component, PDF handling market are mainly ruled by commercial or non-business use libraries. The best libraries we could use for now for free is Mozilla’s PDF.js project, which using javascript and node.js to rendering and displaying PDF file inside webview.
  2. PDF standard are constantly update and changes. We need to keep maintenance our library if we decide to write our own.
  3. There possibly will be some performance issue with our app, though very unlikely, but still a risk to consider at start.

Leave a Reply

Your email address will not be published. Required fields are marked *