Giter Club home page Giter Club logo

cordova-print-pdf-plugin's Introduction

Print PDF plugin for Cordova / PhoneGap

This plugin brings up a native overlay to print a PDF document using AirPrint for iOS and Android Printing APIs on Android devices running 4.4 (API 19) or later. For Android devices running 4.3 or less, it will open a Google Cloud Print dialog.

Usage

print(options)

Use the print function to print an encoded document via a native printing interface.

window.plugins.PrintPDF.print(options);

The default options object

var options = {

	data: null, 				// content, either base64 string or file uri (required)
								// (omit "data:application/pdf;base64," part from base64 string) 

	type: 'Data',				// type of content, use either 'Data' or 'File'

	title: 'Print Document', 	// title of document

	dialogX: -1,				// if a dialog coord is not set, it defaults to -1.
								// the iOS method will fall back to center if it gets
	dialogY: -1,				// a dialog coord less than 0. (iPad only)

	success: null,				// success callback function, argument is a json string.
	 							// parsed json format:
								// {success: true}

	error: null					// error callback function, argument is a json string.
	 							// parsed json format:
								// {success: [boolean], available: [boolean], error: [string], dismissed: [boolean]}

};

Example:

var encodedString = 'base64encodedStringHere';
window.plugins.PrintPDF.print({
	data: encodedString,
	type: 'Data',
	title: 'Print Document',
	success: function(){
		console.log('success');
	},
	error: function(data){
		data = JSON.parse(data);
		console.log('failed: ' + data.error);
	}
});

dismiss()

Use the dismiss function to programmatically dismiss the print dialog (iOS only). There are no options that can be passed in. When the dialog is dismissed it will trigger the error callback that was set for the print() function with the dismissed parameter set to true.

window.plugins.PrintPDF.dismiss();

isPrintingAvailable(callback)

Use the isPrintingAvailable function to check if native printing is supported and available.

window.plugins.PrintPDF.isPrintingAvailable(callback);

Example:

window.plugins.PrintPDF.isPrintingAvailable( function(isAvailable) {
	console.log('printing is available: '+ isAvailable);
});

cordova-print-pdf-plugin's People

Contributors

ffournier avatar sarahgoldman avatar thop7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cordova-print-pdf-plugin's Issues

Can Not Print Malformed PDF

I am trying to take a pdf created using jsPDF and print it. So far I've tested it on a Nexus 6 with Android 6, and an ASUS K10 tablet running 4.4.

var print = function(){
      window.plugins.PrintPDF.isPrintingAvailable(function(dataPDF){
        window.plugins.PrintPDF.print({
          data: dataPDF,
          type: 'data',
          title: 'Voter Registration Application',
          dialogX: -1,
          DialogY: -1,
          success:function(result){
            console.log(result);
          },
          error:function(result){
            console.log(result);
          }
        });
      });
    };
    setTimeout(print(pdf),2000);

Both cases I am running into the following error. I thought it was something wrong with my pdf that was being generated so I Base64 encoded a pdf i downloaded from the internet and am getting the same result.

On Device I am getting an error that the Print Spooler Service has stopped.

01-20 15:33:05.215: E/PdfManipulationService(16834):    at com.android.printspooler.renderer.PdfManipulationService$PdfRendererImpl.openDocument(PdfManipulationService.java:90)
01-20 15:33:05.215: E/PdfManipulationService(16834):    at com.android.printspooler.renderer.IPdfRenderer$Stub.onTransact(IPdfRenderer.java:58)
01-20 15:33:05.240: E/AndroidRuntime(16312): java.lang.RuntimeException: Cannot print a malformed PDF file
01-20 15:33:05.240: E/AndroidRuntime(16312):    at android.print.PrintManager$PrintDocumentAdapterDelegate$MyHandler.handleMessage(PrintManager.java:815)

cordova app crashes when calling the print method

Hello Sarah,

thanks on the good work on this project! I have an issue with this and hope you could help me out. I try to use this in the easiest way i could think of, but the app crashed (stops).

I use cordova 6.1.1 with android 5.1.0 and print-pdf 4.0.0

Pls find next some short snippet. The vars not in the code are filled (e.g. winTitle), so this is not the problem.

I have downloaded the file using file-transfer 1.5.0 into the cordova.file.externalDataDirectory + "myapp/" + filename.toInternalURL(). A test i use is e.g. filename = "cdvfile://localhost/files-external/myApp/File.PDF";

Can you help me with this?

Thanks in advance!
John

        if ( window.plugins.PrintPDF.isPrintingAvailable ) {

            window.plugins.PrintPDF.print({

                data: filename,
                type: 'File',
                title: winTitle,
                success: function(){

                    return true;

                },
                error: function(data){

                    data = JSON.parse(data);
                    helper.debug("Error", "printing failed:" + data.error);
                    return false;
                }
            });

        } else {
            return false;
        }

Support file:// URIs

It seems the plugin only supports cdvfile:// URIs. My typical flow is to download a file through the Cordova File Transfer plugin, then use that resulting FileEntry object to get the full path of the file. However, it returns something like:

file:///var/mobile/my/file/path/document.pdf

I have to hack up a cdvfile:// URL to pass in to the plugin.

printer show, but it keep loading preview

As title, ios show a printer pop up, but the content is keep loading preview. firstly i try to use URI but not work. then i change the way to use base64. from file pdf on local. i use cordovafile.readAsDataURL to convert file pdf to base64. but it still not work. please help me.

below is my code. could you take a look at it
success is returned base64string
$cordovaFile.readAsDataURL(pathDirectory, fileName)
.then(function (success) {
window.plugins.PrintPDF.isPrintingAvailable( function(isAvailable) {

                    alert('printing is success: '+ success.substring(0,200));                        
                    if(isAvailable){                         
                        window.plugins.PrintPDF.print({
                            data: success,
                            type: 'Data',
                            title: fileName,
                            success: function(){
                                alert('success');
                            },
                            error: function(data){
                                data = JSON.parse(data);
                                alert('failed: ' + data.error);
                            }
                        });
                    }
                });  
                //alert(JSON.stringify(success));
            }, function (error) {
                alert(JSON.stringify(error));
            });

Print multiple items at once

According to the used UIPrintInteractionController class it should be possible to print multiple items at once.

  • printingItem takes a single print-ready object.
  • printingItems takes an array of print-ready objects.

This would be a very nice feature for me.
Thank you for this plugin.

Changes for different android versions in one branch

It is proposed to combine the printing methods for different versions of Android in the master branch, because the application can be are designed for different versions of Android. For example, in my application using Ionic Framework and should be supported by devices with Android 4.3+. The file package.json is not possible to specify the install plugin from two branches.

Broken cordova-plugin-file dependency

I had to manually run cordova plugin add cordova-plugin-file --save and then run the install command for your plugin afterwards. If I don't have cordova-plugin-file yet, your install fails since your dependency is pointing to the GitHub repo which appears to be empty at the moment...

don't work in android 4.2.2

I use the plugin from the branch "google-cloud-print". But my app crashes with an error:

1105-1122/com.App.Tablet E/AndroidRuntime﹕ FATAL EXCEPTION: pool-1-thread-1
java.lang.NoClassDefFoundError: android.print.PrintManager
at com.sgoldm.plugin.printPDF.PrintPDF$2.run(PrintPDF.java:111)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)

Help, please, what am I doing wrong?

Issue cordova-print-pdf-plugin : PrintPDF undefined

Hello !

I'm trying to use the plugin in a ionic project, but I have an error
In Browser it display : Cannot read property 'PrintPDF' of undefined
I don't know what I am doing wrong, it seems that the plugin is not found

This is my app.js :
`(function(){
angular
.module('app',['ionic'])
.controller('printController', printController);

    function printController(){
        alert("HELLO");
        window.plugins.PrintPDF.isPrintingAvailable(function(isAvailable){
            alert('printing is available ' + isAvailable);
        });
    }

})();`

And this is my index.html:

`

<title></title>
<link rel="manifest" href="manifest.json">

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>


<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/PrintPDF.js"></script>
<script src="js/app.js"></script>
<ion-pane ng-controller="printController">
  <ion-header-bar class="bar-stable">
    <h1 class="title">Ionic Blank Starter</h1>
  </ion-header-bar>
  <ion-content>
  </ion-content>
</ion-pane>
` I need some help please, thanks you !

Installation error

I'm getting this error.

$ cordova plugin add https://github.com/sarahgoldman/cordova-print-pdf-plugin.git
Error: Failed to fetch plugin https://github.com/sarahgoldman/cordova-print-pdf-plugin.git via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Failed to get absolute path to installed module

Any idea what I'm doing wrong?

CDVFile.h file not found

..../Plugins/cordova-plugin-print-pdf/CDVPrintPDF.m:12:9: fatal error: 'CDVFile.h' file not found

import "CDVFile.h"

    ^

1 error generated.

I see the above error when I try to deploy an ios app with this plugin. The src folder does not have CDVFile.h. Am I missing something?

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.