React PWA cannot open external PDF in Chrome (Android) - android

I have a React progressive web app which contains a link to a PDF file. The app has been added to the home screen using the Google banner (https://developers.google.com/web/updates/images/2015/12/getting-started-pwa/pwa-general-2-#1x.jpg), so it is treated as an app, not a shortcut.
The problem is I cannot open the PDF file from the installed PWA on Android. I get an error saying: Cannot open PDF (pdf_name.pdf cannot be opened).
Opening the PDF from a regular browser (desktop or mobile) works. Opening from home screen app on iOS also works.
My PWA is hosted at app.domain.com, while the PDF is hosted at api.domain.com.
The link to the PDF file looks like this:
<a rel="noopener" href="https://api.domain.com/pdf_name.pdf"
target="_blank">View PDF</a>
External links that go to regular pages (not files) work.
Any ideas what might prevent Chrome from being opened from within the app?

I fixed this by simply removing the target attribute. It opens up in a new tab anyway. For PWA's on Android, specifying a new tab with the target attribute causes an error. It seems that when you manually specify a new tab the browser reacts as if there are 2 pages to download, the pdf and an empty web page (0 kb). Oddly, the Samsung Internet Browser also does this but just downloads both. The PWA Chrome Browser errors instead.

Related

Open PDFs in WebView

I am trying to build an app using Flutter that uses the Webview to open a website. Within this website there are a number of pdfs and I want to open them inside the app as well, instead of redirecting to a browser or an acrobat viewer. Is there any way to do this?

Android URL Scheme To Open File From Browser Link?

On Android (8.0), I'm trying to create a local html file that includes links to some local files that can't be viewed directly by Chrome, like <a href="relative_path_to_file/file.docx">. In a normal web browser (i.e. on a PC), I can click the link and it will open the file in its default viewer. On Android, if I open one of the local html files in Chrome and click one of those links, it directs me to content://nextapp.fx.FileProvider/path_to_file/file.docx, showing "Your file was not found." I do have an appropriate app installed to view the file (I can open it via a file explorer app). I would like to understand how I can structure the URLs such that docs of various types (i.e. docx, xlsx, pdf, etc) can be accessed via the links that refer to them - clicking the link should offer to open the file, as it does when accessing the file from a file manager.
I tried rewriting the links to an absolute path, i.e. "/storage/emulated/0/path/file.docx." The result is the same.
I tried rewriting the links to "file:///storage/emulated/0/path/file.docx." Chrome just redirects to about:blank.
I tried opening the html doc with "HTML Viewer" rather than Chrome. The behavior is more or less the same (in the first case it redirects to about:blank, in the second it says "No app available to open link.")
How can I structure the link so it can be clicked & open the referred-to file in appropriate viewer?
Finally figured it out. A working link to open the local file in its default viewer looks like:
"intent:///abs/path/to/file.docx#Intent;scheme=file;action=android.intent.action.VIEW;end;"
...With one important caveat: it breaks if there are any "dots" in the path (i.e. I had the files in a .hiddenFolder, which apparently causes Chrome to be unable to figure out the intent link).
Reference: https://developer.chrome.com/multidevice/android/intents

Opening an Android Application from a PDF possible?

I was wondering how to open an android APP from a PDF. I wanted to make a PDF document for kids that would automatically open the application when the child pressed on the apps button on the PDF document. I can generate links in the PDf that will make it open videos and go to web pages, but not that could open an application already installed on the tablet.

Desktop web site can't open pdf file on mobile devices - how to

VS2010 VB.NET ASP.NET
I have a simple site where the user clicks a button and a pdf file is displayed in a new broswer window.
To do the this a button launches a new browser window with the following code in the page load event:
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1))
Response.Buffer = True
Response.ContentType = "application/pdf"
'Response.ContentType = "text/plain"
If Download_Flag Then
'force SaveAs (this is the download option)
Response.AppendHeader("Content-Disposition", "attachment; filename=" & "myfile" & ".pdf")
Else
'open in borwser
Response.AddHeader("Content-Disposition", "inline")
End If
Response.OutputStream.Write(PdfBuffer, 0, PdfBuffer.Length)
Response.OutputStream.Flush()
Response.OutputStream.Close()
Response.End()
PDFBuffer is a byte array containing the pdf document
This code displays the pdf file in the browser (ie, chrome, mozilla, safari?) using whatever pdf plugin is installed.
if download_flag is true then the pdf is not opened in the viewer but instead browser prompts with the save file dialog
As I said, this code works in desktop borwsers, but it does not work on an ipad or an android phone, and propably other devices as well.
The site is not mobile aware, but if need be it could, I suppose.
I know that apple does not allow downloads, and android may not be able to open open an additional window, so how can I open a pdf file on a button click on these devices? I know he ipad and the android can both open pdf files, I've done it on other sites.
My solution was to open the pdf file in the same window as the site. On android this causes a file download to which the user can go to the downloads folder and view the pdf. On ipad this opens the default pdf viewer. If ipad user download the adobe pdf viewer they can switch over to the adobe reader from the default ipad reader; the adobe reader allows print and email of document. On desktop browser this solution shows the pdf in the same window and user can use the browser's back button to get back to the site when they are done with the pdf. A more robust solution would be to detect the client and act appropriately, but with this common implementation is workable.
Speaking for Android, Content-Disposition is tricky to get working properly:
Avoiding content type issues when downloading a file via browser on Android
http://www.digiblog.de/2011/04/android-and-the-download-file-headers/
http://winzter143.blogspot.com/2012/03/android-handling-of-content-disposition.html

How to open pdf file with in our app android+phonegap+JQM?

I am developing an web+cross platform app using Jquery Mobile+PhoneGap+Android. In web app, I am able to open pdf file links within my app page using iframe. But, in Phonegap generated Android build, iframe is unable to render pdf content,it is showing that iframe area as empty.How can I display the pdf file/content, whose src I know at runtime, within android webview. Thanks In Advance.
I've just published my plugin, which can open almost any type of file, which is stored locally on Android device.
Please take a look at: https://github.com/markeeftb/FileOpener
Plugin opens external application which handles the preview of the document.

Categories

Resources