Open PDF in PhoneGap application, which is made in HTML and CSS

I have a strange problem with my iPad application on my phone. The problem is that I have to open the PDF document in my application using the links, and when I click on the link that opens the PDF file, it shows me the PDF document without a backlink.

Therefore, when I open a PDF document in my application by reference, it leads me into a dead end, and I can not return to the main page of my application.

My question is, how can I get Top-Bar when I open a PDF file that can return me to my home page? Any internal element for the iPad can be?

Many thanks.

+8
css html5 cordova
source share
5 answers

Try using the In App Browser plugin.

If you are using a later version of Phonegap / Cordova (2.8.0, 2.9.0, etc.), it should appear with it - nothing else needs to be installed.

http://docs.phonegap.com/en/2.9.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser

This will allow you to open the PDF file in a new window that overlays your application. It has a Finish button that users can use to close it and return to their application when they are complete.

You will open the PDF file using the In-App browser using something like this:

window.open('http://whitelisted-url.com/pdftoopen.pdf', '_blank'); 

those. the _blank option launches the In-App Browser plugin. If you used _system , he could open it in iBooks instead (just guess there - not 100% sure if he will use iBooks).

+12
source share

Try the https://docs.google.com/viewer?url= URL prefix

like, window.open('https://docs.google.com/viewer?url=http://www.example.com/example.pdf&embedded=true', '_blank', 'location=yes');

+4
source share

Try opening any documents from the URL using the following steps:

It works for me on both Android and iOS. I used it for open images and PDF files.

Android It opens files using system applications, if available, otherwise they give an error that you can handle.

IOS It opens files in the form of pop-ups with the "Finish" button and the "Option" button.

It does not show the URL of your document.

The source is available here: https://github.com/ti8m/DocumentHandler

+1
source share

Thanks asgeo1,

I solved this using window.open() .

 <a href="#" onclick="window.open('http://12example.pdf', '_blank', 'location=no');"><img src="images/samplens.jpg" border="0" /></a> 

Hope this helps.

0
source share

I ended up using WebIntent

as described here . The hard part was to modify WebIntent.java to correctly determine the file type:

 String type = obj.has("type") ? obj.getString("type") : null; // New code starts Uri uri = obj.has("url") ? Uri.parse(obj.getString("url")) : null; String extension = MimeTypeMap.getFileExtensionFromUrl(obj.getString("url")); if(extension != null){ MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); type = mimeTypeMap.getMimeTypeFromExtension(extension); } // New code ends JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null; 
0
source share

All Articles