sarahgoldman / cordova-print-pdf-plugin Goto Github PK
View Code? Open in Web Editor NEWPrint a PDF document from a Cordova app on iOS and Android.
License: MIT License
Print a PDF document from a Cordova app on iOS and Android.
License: MIT License
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>
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));
});
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.
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)
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;
}
take look here i describe my issue .. katzer/cordova-plugin-printer#189
can u please help me out
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...
After fixing #6, can you release a new version?
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?
..../Plugins/cordova-plugin-print-pdf/CDVPrintPDF.m:12:9: fatal error: 'CDVFile.h' file not found
^
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?
According to the used UIPrintInteractionController class it should be possible to print multiple items at once.
This would be a very nice feature for me.
Thank you for this plugin.
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.
Pdf is working well but i want print all the documents like excel, ppt and document file. is your plugin print all the files format ?
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?
I'm trying to use the plugin in a Cordova Ionic project, but I have an error:
NoClassDefFound: android.print.PrintManager
Plugin is from master branch.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.