Coder Social home page Coder Social logo

polarcape / polarcape-cordova-plugin-document-handler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ti8m/documenthandler

10.0 7.0 19.0 120 KB

Polar Cape Cordova Plugin Document Handler

License: MIT License

Java 15.83% Objective-C 6.30% JavaScript 6.56% Rich Text Format 71.30%

polarcape-cordova-plugin-document-handler's Introduction

Polar Cape Cordova Plugin Document Handler

A PhoneGap plugin to handle documents (e.g. PDFs) loaded from a URL.

Plugin dependencies

This plugin depends on cordova-plugin-file. If you want to install this plugin you must install first cordova-plugin-file.

cordova plugin add cordova-plugin-file

Install

npm install -g polarcape-cordova-plugin-document-handler
npm install polarcape-cordova-plugin-document-handler --save-dev
cordova plugin add polarcape-cordova-plugin-document-handler

Usage

The plugin exposes two methods on the window object:

 DocumentViewer.previewFileFromUrlOrPath(successHandler, failureHandler, url, fileName, mimeType)

 DocumentViewer.saveAndPreviewBase64File(successHandler, failureHandler, data, type, path, fileName)

The parameters:

  • successHandler: Should be a function. Is called when the file download is done and the file is shown to the user.
  • failureHandler: Should be a function. Is called when there was a problem with downloading the file. The function takes an argument which is usually 1 (undefined error). Also see Android section.
  • url: A URL to a document. Any cookies the system has for this server are passed along. This ensures that authenticated downloads also work.
  • mimeType: This is optional argument. You should provide it if mimeType cannot be detected by the file itself.
  • data: Base64 string that represents the document
  • type: Type of the document (Ex. application/pdf )
  • path: Should be a path to phone's directory (Android/IOS) where you want to be saved the document before preview. Better use cordova-file-plugin constant to provide correct path.
  • fileName: filename is parametar which must contain file extension too. (Ex. 'fileExample.pdf')

Android

The plugin downloads a document and starts an intent, so that other installed applications can open it.

There is a special failure condition on Android, if the system doesn't have any application that can handle the given MIME type. In this case failureHandler will be called with the error code 53 or if link is invalid error code 2.

iOS

The plugin downloads the document and provides a preview of the document using the Quick Look framework, including the corresponding actions such as copy, print, etc.

##Important note

If you are using saveAndPreviewBase64File for Android OS must be provided public path, because third part application cannot access the file. Choose one from the following:

Device Path cordova.file.* AndroidExtraFileSystems r/w? persistent? OS clears private
<sdcard>/ externalRootDirectory sdcard r/w Yes No No
   Android/data/<app-id>/ externalApplicationStorageDirectory - r/w Yes No No
      cache externalCacheDirectry cache-external r/w Yes No** No
      files externalDataDirectory files-external r/w Yes No No

Example 1

DocumentViewer.previewFileFromUrlOrPath(
    function () {
    console.log('success');
    }, function (error) {
    if (error == 53) {
        console.log('No app that handles this file type.');
    }else if (error == 2){
        console.log('Invalid link');
    }
},
'http://www.axmag.com/download/pdfurl-guide.pdf', 'pdf-sample', 'application/pdf');

Example 2

DocumentViewer.saveAndPreviewBase64File(
    function (success) {},
    function (error) {
        if (error == 53) {
            console.log('No app that handles this file type.');
        }
    }, 
    'JVBERi0xLjMKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZwovT3V0bGluZXMgMiAwIFIKL1BhZ2VzIDMgMCBSID4+CmVuZG9iagoyIDAgb2JqCjw8IC9UeXBlIC9PdXRsaW5lcyAvQ291bnQgMCA+PgplbmRvYmoKMyAwIG9iago8PCAvVHlwZSAvUGFnZXMKL0tpZHMgWzYgMCBSCl0KL0NvdW50IDEKL1Jlc291cmNlcyA8PAovUHJvY1NldCA0IDAgUgovRm9udCA8PCAKL0YxIDggMCBSCj4+Cj4+Ci9NZWRpYUJveCBbMC4wMDAgMC4wMDAgNjEyLjAwMCA3OTIuMDAwXQogPj4KZW5kb2JqCjQgMCBvYmoKWy9QREYgL1RleHQgXQplbmRvYmoKNSAwIG9iago8PAovQ3JlYXRvciAoRE9NUERGKQovQ3JlYXRpb25EYXRlIChEOjIwMTUwNzIwMTMzMzIzKzAyJzAwJykKL01vZERhdGUgKEQ6MjAxNTA3MjAxMzMzMjMrMDInMDAnKQo+PgplbmRvYmoKNiAwIG9iago8PCAvVHlwZSAvUGFnZQovUGFyZW50IDMgMCBSCi9Db250ZW50cyA3IDAgUgo+PgplbmRvYmoKNyAwIG9iago8PCAvRmlsdGVyIC9GbGF0ZURlY29kZQovTGVuZ3RoIDY2ID4+CnN0cmVhbQp4nOMy0DMwMFBAJovSuZxCFIxN9AwMzRTMDS31DCxNFUJSFPTdDBWMgKIKIWkKCtEaIanFJZqxCiFeCq4hAO4PD0MKZW5kc3RyZWFtCmVuZG9iago4IDAgb2JqCjw8IC9UeXBlIC9Gb250Ci9TdWJ0eXBlIC9UeXBlMQovTmFtZSAvRjEKL0Jhc2VGb250IC9UaW1lcy1Cb2xkCi9FbmNvZGluZyAvV2luQW5zaUVuY29kaW5nCj4+CmVuZG9iagp4cmVmCjAgOQowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDggMDAwMDAgbiAKMDAwMDAwMDA3MyAwMDAwMCBuIAowMDAwMDAwMTE5IDAwMDAwIG4gCjAwMDAwMDAyNzMgMDAwMDAgbiAKMDAwMDAwMDMwMiAwMDAwMCBuIAowMDAwMDAwNDE2IDAwMDAwIG4gCjAwMDAwMDA0NzkgMDAwMDAgbiAKMDAwMDAwMDYxNiAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDkKL1Jvb3QgMSAwIFIKL0luZm8gNSAwIFIKPj4Kc3RhcnR4cmVmCjcyNQolJUVPRgo=',
    'application/pdf', 
    cordova.file.dataDirectory, 
    'test.pdf'
);

RELEASE NOTES

1.0.13 (27/06/2018)
* Handle files with spaces in their filename on IOS
1.0.14 (30/08/2018)
* Document handler js error fix
1.1.0 (23/06/2019)
* Added optional parameter (mime type) to the previewFileFromUrlOrPath
1.1.1 (30/08/2019)
* fileName parameter implementation (IOS)

polarcape-cordova-plugin-document-handler's People

Contributors

eddyverbruggen avatar gdvsbp avatar ingmarstein avatar micky2be avatar mwchambers avatar saspes avatar syonip avatar vkajtazov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

polarcape-cordova-plugin-document-handler's Issues

Does not work with Android 7.0

I tried in most of the devices, they are working fine, but does not work with Android 7.0.
App simply stops and user get thrown out of App.
Does it tested with OS 7.0

In my project Android manifest I have set the target as 25

<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />

Can some one help me out in this?

FileUriExposedException

Hello,

we use your plugin to handle links in our web app in our web app to download/open pdf documents.

This has worked fine for as long as we were on Android SDK target version 23. However, starting on the first of this month, Google imposed that all apps have to target Android SDK version 26. This is what we did, but unfortunately since then we get the following exception, when a user tries to open that link

android.os.FileUriExposedException: file:///data/user/0/$app-identifier/cache/$fileName.pdf exposed beyond app through Intent.getData()

According to this article, since Android 24 exposing file Uris via Intents is not supported. The article suggests a fix using the FileProvider API. Do you think it would be possible to change the way your library builds the Intent to use the FileProvider API?

Thanks!

provider_paths.xml conflicts with other plugins.

Hello,

When installing this plugin, cordova fails with the following error:
Failed to install 'polarcape-cordova-plugin-document-handler': CordovaError: Uh oh! "[...] /platforms/android/res/xml/provider_paths.xml" already exists!

I found that both this plugin and cordova-plugin-camera use this file.
Could you please prefix the file, if possible, to avoid collisions of this kind?

best regards

DocumentHandler.saveAndPreviewBase64File does not work with Kitkat 4.4.2

I want to open PDF document in Android Device.
I am using polarcape cordova pugin. My App am receiving Base64 string from the Server API, and I want to open the PDF intent using saveAndPreviewBase64File method of the plugin to achieve this.
I have set the target as Android-23, as suggested earlier, by the plugin development team.
It works for Android, 5.0 onwards.
But it is not working for device having Kitkat (Android 4.4.2)

Can someone help me in working for 4.4.2 Kitkat?

Doesn't work if filename has spaces?

The plugin is working amazing as long as the filename of the document doesnt have spaces.

1DOC.doc - good
2DOCX.docx - good
word test.docx - nothing happens at all

"JSON error" loading PDF

I'm trying to open a PDF and getting "JSON error" passed back to the error function. Not sure why this would happen. I checked the response headers and the content type is application/pdf.

I/chromium(29878): [INFO:CONSOLE(1685)] "Failed to open http://www.theoomf.com/docs/oomf_privacy_policy.pdf with error JSON error", source: file:///android_asset/www/js/oomf-app.98d867481b6592d8.js (1685)

Unable to install Plugin

screenshot 172

Hi i am unable to add plugin getting warning as in attached document file.
+-- UNMET PEER DEPENDENCY cordova-plugin-file@^3.0.0
`-- [email protected]

npm WARN [email protected] requires a peer of cordova-plugin-file@^3.0.0 but none was installed.

Kindly do the needful to help me

Thanks

Opening multiple pdfs

I'm seeing the issue of when multiple open requests are fired, it only opens the first one.
e.g.
_.forEach(requests, function(request){
DocumentHandler.saveAndPreviewBase64File(...)//different filenames are passed in
})

Any help is appreciated!

Nothing happened when tried to use the plug-in with local PDF files.

Hi,

Sorry, this is not actually pulg-ins issue, may be what I require is a way to use the plug-in as

<gap:plugin name="polarcape.cordova.plugin.document.handlerOR_THE_ACTUAL_NAME" version="SOMEVERSION" />

I followed the steps mentioned and created a test view with sample PDF files on device (SD Card)
I have the <gap:plugin name="org.apache.cordova.file" version="1.3.1" /> included in application's config.xml with couple of other plug-ins which depend on cordova.js.

Those things work as intended but the Document handler, what I see is a white blank view nothing happens. Tried with DxButton to load it in another view but same thing. What am I doing wrong?

May I request you to provide the gap build/version number or a way to use it in my Hybrid mobile app.
(FYI I am trying to use it with DevExtreme 15.2 - MVVM- KnockOut Approch)

Thank you guys.

saveAndPreviewBase64File( ) method is not working for Android

I want to open PDF document in Android Device.
I am using polarcape cordova pugin. My App am receiving Base64 string from the Server API, and I want to open the PDF intent using saveAndPreviewBase64File method of the plugin to achieve this.
I have set the target as Android-23, as suggested earlier, by the plugin development team.
But it is not working.
i have taken the same example which has been published in the github portal, only put alert statements for debugging purpose.
Can someone help me in running this...

PFB code

` function PDFBase64()
{
alert("PDFBase64() is called...");

	try
	{
	
		window.DocumentHandler.saveAndPreviewBase64File(
			function (success) {
				alert("Inside Success");
				alert(JSON.stringify(success));
			},
			function (error) {
				alert("Inside error");
				alert(JSON.stringify(error));
				
				if (error == 53) {
					console.log('No app that handles this file type.');
				}
			}, 
			
			'JVBERi0xLjMKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZwovT3V0bGluZXMgMiAwIFIKL1BhZ2VzIDMgMCBSID4+CmVuZG9iagoyIDAgb2JqCjw8IC9UeXBlIC9PdXRsaW5lcyAvQ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MDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDkKL1Jvb3QgMSAwIFIKL0luZm8gNSAwIFIKPj4Kc3RhcnR4cmVmCjcyNQolJUVPRgo='
			,
			'application/pdf', 
			cordova.file.externalApplicationStorageDirectory, 
			'test.pdf'
		);
	}
	catch(e)
	{
		alert("Inside catch");
		alert(JSON.stringify(e));
	}
	
}`

how show loading..

if the file at remote url
how show loading.. message until file downloaded

1.0.14 has breaking changes, but is versioned as a patch

1.0.14 changes the window object name from DocumentHandler to DocumentViewer.

readme #28
code that changed #26

But it is only versioned as a patch upgrade from 1.0.13 semver, meaning everyone that did a default install of this plugin, when reinstalling, got the 1.0.14 update, with the breaking changes.

I dont know if the change was intentional, as the plugin.xml still references DocumentHandler

<js-module src="www/DocumentHandler.js" name="DocumentHandler"> <clobbers target="DocumentHandler" /> </js-module>

This actually fooled me as window.DocumentHandler still exists, when trying to debug this.

My recommendation would be to remove 1.0.14.
Then if the codechanges really are needed, create a 1.0.15 which uses window.DocumentHandler or republish 1.0.14 as 2.0.0, so the plugin follows semver.

success handler not running angular scope functions

angularJS v1.*
Ionic v1
built on iOS

The following code will successfully hit the alert but not set the $scope.loading variable to null.

Seems as if $scope is not accessible while viewing the Document Handler. Any ideas around this would be appreciated!

app.controller('CatalogController', function($scope, $firebaseArray, $firebaseObject, CatalogService, $localStorage, $window) {
  $scope.$on('$ionicView.beforeEnter', function () {
  	$scope.loading = true;
		$scope.screen = $window.innerWidth;
  	var issues = CatalogService.getIssues();
		  issues.$loaded().then(function(){
		  	$scope.issues = issues;
		  	$scope.loading = null;  	
	  	});
  	});

  	$scope.viewIssue = function(issue) {
		$scope.loading = true;
                
	  	DocumentHandler.previewFileFromUrlOrPath(function() {
	  		//success
                     alert('success');
		    $scope.loading = null;

	    }, function (error) {
	    	//error
	    	$scope.loading = null;
		    if (error) {
		    	alert('There was a problem loading this issue. Please try again shortly or contact support at *[email protected].');
		    }
			},
			issue.content, issue.name + '-' + issue.serial);
	  };
});

update dependency on cordova file to latest/6.0.1

package json define cordova-pungin-file as : "cordova-plugin-file": "^4.0.0". Can that but updated to 6.0.1. This will help the plugin mingle well with other updated plugins that depend on current releases of cordova-plugin-file

I've tested locally by changed the dependency, and it works with the examples in the README

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.