PDF in the iframe triggering download automatically - android

I have below iframe in one of the page in my website.
<iframe src="http://www.pdf995.com/samples/pdf.pdf" id="iframe1">
But when I open same page in android mobiles chrome browser it is automatically triggering download of file which is mentioned in the iframe. How can I prevent auto triggering of download in mobile devices?

You can use this format:
https://docs.google.com/viewerng/viewer?url=http://yourfile.pdf
Just replace http://yourfile.pdf with the link you use.

Ideally, it is important to think on the availability to use the convert/viewer in offline mode!
Why and Because...
If you use an iframe for a stored document on your server and you would made an webapp, you will must play over HTTPS/SSL. (Offline is over https).
It is not sure that the PDF viewer provides a secure url (1), you will probably problems with CORS and others with the « Same origine » to embed the iframe src (2), and finally, it service must delivers online and offline ! So it recommended to embed in application cache all the resources needed to convert the PDF in canvas.
An all in one solution is strongly recommended I think.
Using PDF.js and its worker with a runtime script is a good way...

Related

Mobile Application based on the website

Im new with Android. My task is to create a mobile application based on a responsive WordPress website. I would like to be able to download some of the content of this site. Website uses HTTPS. In the first, most primitive version, I tried to use WebView. I wanted to use the following: WebView load website when online, load local file when offline. Unfortunately, only the white page appeared and nothing more. In the case of "Google.com link" a page has been loaded in an external browser (Oreo Android).
Any suggestion how should I start? The easiest way would be to download an HTML page or have access to files on the server. Unfortunately, I do not have that access.
As always -1 without even trying to help....
As I said load from cache when Internet is disabled not working. Work only WebView (without login, because CORS). So how should I face it?

how to get a pdf document to automatically open when webpage is accessed?

I'm a bit new to this so bear with me. What I am trying to do is to get a pdf document to open automatically as soon as a webpage is launched. This webpage will be hosted locally and the pdf document(S) will be stored locally as well.
Essentially we are using an external platform that allows buttons to link to exterior webpages, but does not allow for opening documents. What we are trying to do is to bypass this limitation by having a webpage that is locally hosted that will automatically open up a pdf file which will be stored on the device.
If the webpage just contained the code <a href"link-to-pdf-doc"></a> will this suffice?
If you are wanting to embed the pdf in the web page rather than download it, a simple way is to use just a plain html object tag:
<object data="link-to-pdf-doc" type="application/pdf" width="100%" height="100%">
I am not sure how much support there is in browsers all across the board, but it will work for the majority of modern browsers.
There are also many libraries available which use browser detection to normalise the code and maybe have wider browser support:
https://github.com/mozilla/pdf.js
http://pdfobject.com

Download videos then play the local copy in Android Webview

I'm building a thin native wrapper for a web application on Android. I want to keep my HTML & Javascript on the web, as it'll reduce the frequency with which the App needs to be updated.
However, I want to take advantage of SD card storage for storing videos -- my application has several videos that are likely to be played multiple times, so I'd rather download them and play them from the local copy.
What I have already done successfully:
Written a #JavascriptInterface that gets called when the page is being viewed through the app that downloads the videos and saves them to getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath()
Written a script that replaces the src of the html element with a file:// Url once the download is complete.
The Problem
I'm getting a javascript error in the console:
"Not allowed to load local resource: file:///storage/emulated/0/Android/data/path/to/video.mp4"
I presume this is because I have a video element
<video src="file:///......."/>
Which is being served by a different (non local) domain, so webview's security is saying no.
There are several WebSettings methods like setAllowFileAccess(), but they specifically state this only enables JavaScript access to files and not HTML elements such as <img> or (in this case) <video>
Is there any way around this?
If not, what should my alternative approach be?
EDIT:
Could I just use the built in browser cache for this?

How to play local video files in a browser

Am looking for the way to play video inside my android browser locally. There may be two or more video's in a local page (like facebook contains video's).
Can anyone please help me out..
Without actually reading about the specifics of the Android built in browser I would safely say, you can't. Well, if you run a local html file it might work, but if you intend to have an external page from which you can play local videos it shouldn't work. I say shouldn't because in the early days of browsers some of them actually did give you access to the local file system. Javascript for example could use file://, something I used myself for image previewing before upload. But this was a major security concern and all modern browsers prevent this.
The difference is if you run a local file or a file on your own local web server. Since then, your local file system is actually part of the web servers file system and the web server can serve your local files.

Open a pdf file inside a webview.

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

Categories

Resources