katzer / cordova-plugin-printer Goto Github PK
View Code? Open in Web Editor NEWPrint HTML documents
License: Apache License 2.0
Print HTML documents
License: Apache License 2.0
01-28 07:43:57.617: E/Web Console(785): Uncaught TypeError: Cannot call method 'print' of undefined at file:///android_asset/www/index.html:30
01-28 07:51:14.347: E/Web Console(785): Uncaught TypeError: Cannot call method 'print' of undefined at file:///android_asset/www/index.html:30
First at all, this is a really great plugin!
I know that iOS 8 its very new. But I just want make you know about this bug.
I'm using Phonegap Build to use this plugin. And I've tested in iOS 6, iOS 7 and iOS 8.0.2, and works great, but just in iOS 8 at the end print a blank page. It's not a big deal, but can be fixed.
documentation should be changed from this:
window.plugin.printer.isServiceAvailable(
function (isAvailable, installedAppIds) {
window.alert('The following print apps are installed on your device: ' + installedAppIds.join(', '));
}
);
to this:
window.plugin.printer.isServiceAvailable(
function (isAvailable, installedAppIds) {
window.alert(isAvailable ? 'Service is available' : 'Service NOT available');
if (installedAppIds) {
window.alert('Printers available' + installedAppIds.join(', '));
} else {
window.alert('No printers available');
}
}
);
I have been working on implementing printing in my app on android. Though this plugin helps me in launching third party apps. But they are not able to receive any content to print.
for ex. HP ePrint app gives "SDCard not accessible arror"
Star Print - gives no content etc
Is there any other plugin or permission that I need to give.
I have already given WRITE_EXTERNAL_STORAGE.
Thanks in advance
Calling window.plugin.printer.isServiceAvailable
comes back with isAvailable
as false
and installedAppIds
as []
.
Manually checking the list of "Print Services" available (from Settings > Printing) displays both HP Print Service Plugin and CloudPrint.
Hello,
I have tried using this plugin example and changed the file name to a remote PDF file but there is no print preview and even if i try printing an empty sheet is coming out of my printer ,but instead if I try using an remote XML file its shown in the print preview.
Is there anyway to print remote PDF files using this plugin??
when I use these code in "0.5.3" version by PGB
window.plugin.printer.isServiceAvailable(function(isAvailable, installedAppIds)
{
if(isAvailable == true)
{
alert("true")
}
if(isAvailable == false)
{
alert("false")
}
});
in Android that it will alert "false"
but in iOS that it will trigger nothing (nothing happened,just nothing)
Hi,
I am able to print PDF generated from the app using this plugin but Android print panel not displaying connected WIFI printer.
Hello!
I'm trying to implement the plugin, did the following steps, but still don't print anything.
function setupprinter()
{
try
{
gPrinterIsAvailable = 0;
window.plugin.printer.isServiceAvailable(
function (isAvailable, installedAppIds)
{
//alert('The following print apps are installed on your device: ' + installedAppIds.join(', '));
gPrintingServer = installedAppIds[0];
gPrinterIsAvailable = 1;
}
);
} catch (e) { notify(e.message); }
}
function printinvoice()
{
try
{
var strToPrint = "";
strToPrint = " "
strToPrint = strToPrint + " <style>@media print "
strToPrint = strToPrint + " {h1 {page-break-before:always;}} "
strToPrint = strToPrint + " </style>Hola mundo "
if (gPrinterIsAvailable == 1)
{
alert('going to print...');
window.plugin.printer.print(strToPrint);
} else { notify("ERROR, Printer is unavailable."); }
} catch (e) { notify(e.message); }
}
Will appreciate any light on this.
Since updating my devices to 8.2, this plugin fails to bring up the Printer Options dialog.
Services are available when checking, but no Print Dialog and failure after ~8 seconds of waiting. Still works on 8.1 for me.
Anyone else experiencing this?
When I pre-set the printer-ID I can print the content once, but when I want to print some other content in the same Script the page is empty.
I'm using iOS 8.3, a Brother QL-720NW (it's the same behavior with the printer simulator) and IPP for the connection
Any idea when this version 0.7.0 is released for phonegap build, it now says that this version is not compatible, and I realy need to print an external webpage (pdf) or generated html
Use the native Google Cloud Print App instead of the web version if available on the device.
Description: http://www.doubleencore.com/2013/11/android-gets-a-print-framework/
Android
Everything is installed according to the instructions. The message appears when testing
Uncaught TypeError: Can not read property 'printer'
The statement in the HTML is:
window.plugin.printer.isServiceAvailable (
function (isavailable, installedAppIds) {
alert ('The following print apps are installed on your device:' + installedAppIds.join (','));
}
);
This is the complete html:
<title>Device Properties Example</title><script type="text/javascript" charset="utf-8" src="js/cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="js/device.js"></script>
<script type="text/javascript" charset="utf-8" src="js/printer.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
var element = document.getElementById('deviceProperties');
element.innerHTML = 'Device Model: ' + device.model + '<br />' +
'Device Platform: ' + device.platform + '<br />' +
'Device UUID: ' + device.uuid + '<br />' +
'Device Version: ' + device.version + '<br />';
window.plugin.printer.isServiceAvailable(
function (isAvailable, installedAppIds) {
alert('The following print apps are installed on your device: ' + installedAppIds.join(', '));
}
);
}
function doPrint()
{
alert('Platform:' + device.platform);
/*window.plugin.printer.isServiceAvailable(
function (isAvailable) {
alert(isAvailable ? 'Service is available' : 'Service is NOT Available');
}
);*/
window.plugin.Printer.isServiceAvailable(
function (isAvailable, installedAppIds) {
alert('The following print apps are installed on your device: ' + installedAppIds.join(', '));
}
);
var page = document.body.innerHTML;
window.plugin.printer.print(page);
alert('functie werkt print');
}
function doAlert()
{
var page = document.body.innerHTML;
//window.plugin.printer.print(page);
alert('functie werkt alert');
}
</script>
Loading device properties...
The Device-plugin works!
is there any way to use bluetooth printer ??
Should it be possible to print w/o the airprint dialog (should be possible since IOS 8 from what I've read?) using the options (json object: { printerId: 'printername' } ?
I keep getting the dialog even though I specify the printerId.
hi @katzer
your latest plugin only supported by device 0.2.3 (Dependencies)
https://build.phonegap.com/plugins/360
but the latest is 0.2.8
https://build.phonegap.com/plugins/628
so maybe future will supported by the latest one?
platform: android
Database access is prevented after using the plugin due to a weirdness in WebView. If newly instantiated WebView's don't enable database access then they block database access to other WebViews's. Adding
page.getSettings().setDatabaseEnabled(true);
after
page.getSettings().setJavaScriptEnabled(false);
resolves the problem for me.
What is the correct way to apply CSS to a piece of content? At the moment I have to do inline and that's obviously undesirable :) Thanks!
When you try to open a specific app, for example: window.plugin.printer.print('Hello world', { appId: 'com.dynamixsoftware.printhand.premium' });
It will automatically set "image/png" as the mime type.
It would be great if you could specify your own mime type in the javascript for phonegap build
Hi,
I want to use this plugin only to print a special div.
I'm doing as follow :
Is it the normal behavior of the plugin or an issue of the Kit Kat's one?
Did you plan to support Windows 8 and Ubuntu?
Thanks
Hi ,
i'm trying to use your plugin on IOS and the isServiceAvailable always returns false my test environment is below:
IOS 7
IPhone 4
Cordova 3.4.0-0.1.3
also has the same behaviour in the iOS simulator under IOS7 maybe i'm doing something stupid?
Cheers
Brett
I added the printer plugin to may corodova app. Now, whenever I print from my application on ios the app crashes. The crash log states that this is the problem:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0xa0020010
From stack overflow, the way to debug such an issue is to run the app through xcode and turn on nszombie. However, when I run the app through xcode, even on an iPad, the app does not crash.
Has anyone else had this issue? Does anyone know a solution?
Thanks,
Eli
works in iOS 7. in our app this also works if a remove the <!DOCTYPE HTML>
but I can't reproduce this in a small snippet.
I am trying to print the page via HP ePrint. Illegal ArgumentException: 'width and height must be > 0' is thrown at takeScreenshot method. Am I doing anything wrong?
This is the code I have in the js file...
onDeviceReady: function() {
//app.receivedEvent('deviceready');
window.plugin.printer.print(document.documentElement, { appId: 'com.hp.android.print' });
},
I have a table with borders set in the columns (tr) but the borders are not printed in my document. In the application, the borders are displayed.
Also, the background is not properly printed in the PDF.
In the image htmlGenerated, it is possible to see the correct version, that is shown in the browser and in the mobile application. In the pdfGenerated.png, you can see the printed document with problems.
Is there a way to print the borders in the PDF?
.trHeader {
vertical-align: middle;
text-align: center;
border-style: solid;
border-width: 1px;
background: #DDD9C4;
}
<td class="tdHeader">
<span> EXAMPLE </span>
</td>
<td style="width: 25%">
<img src="img/example2.png">
</td>
</tr>
![]() |
trying to print to Samsung Mobile Print on Android 4.2.2. The Samsung mobile print app launches then displays the error "invalid intent".
Any ideas?
How do I get this plugin to print the values in the input fields as well?
We're trying to use the 0.6.x branch to print some html, it works on emulator (4.4.2 API 19 Google APIs), but crashes the app on LG Flex (4.4.2) and N7 (4.4.4), the log is:
10-16 10:14:23.818: E/AndroidRuntime(6756): FATAL EXCEPTION: pool-1-thread-1
10-16 10:14:23.818: E/AndroidRuntime(6756): Process: <our app id>, PID: 6756
10-16 10:14:23.818: E/AndroidRuntime(6756): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/html flg=0x1 pkg=com.google.android.apps.cloudprint (has clip) (has extras) }
10-16 10:14:23.818: E/AndroidRuntime(6756): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
10-16 10:14:23.818: E/AndroidRuntime(6756): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
10-16 10:14:23.818: E/AndroidRuntime(6756): at android.app.Activity.startActivityForResult(Activity.java:3424)
10-16 10:14:23.818: E/AndroidRuntime(6756): at android.app.Activity.startActivityForResult(Activity.java:3385)
10-16 10:14:23.818: E/AndroidRuntime(6756): at org.apache.cordova.CordovaActivity.startActivityForResult(CordovaActivity.java:859)
10-16 10:14:23.818: E/AndroidRuntime(6756): at de.appplant.cordova.plugin.printer.Printer.printViaGoogleCloudPrintApp(Printer.java:198)
10-16 10:14:23.818: E/AndroidRuntime(6756): at de.appplant.cordova.plugin.printer.Printer.access$300(Printer.java:46)
10-16 10:14:23.818: E/AndroidRuntime(6756): at de.appplant.cordova.plugin.printer.Printer$2$1.onContentReady(Printer.java:133)
10-16 10:14:23.818: E/AndroidRuntime(6756): at de.appplant.cordova.plugin.printer.Printer$ContentClient$1.run(Printer.java:337)
10-16 10:14:23.818: E/AndroidRuntime(6756): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-16 10:14:23.818: E/AndroidRuntime(6756): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-16 10:14:23.818: E/AndroidRuntime(6756): at java.lang.Thread.run(Thread.java:841)
10-16 10:14:23.818: W/ActivityManager(503): Force finishing activity <our app id>
10-16 10:14:23.838: D/CordovaActivity(6756): Paused the application!
10-16 10:14:23.838: D/CordovaWebView(6756): Handle the pause
We tried this using the latest code in google-cloud-print branch and 0.6.1, both produces this crash, but 0.6.0 and 0.7.0 works.
Looks like the latest changes to branch google-cloud-print is incorrect, CloudPrintDialog.java has "public class Printer" in it, which breaks the build.
Google web fonts used in the app display correctly inside the cordova app. However when the app page (or a div on the page) is printed using this cordova print plugin , the web fonts do not display and revert to the browser default font. Is there a solution or workaround to this problem? Thanks in advance.
All the prints came out with borders in the simulator (I don't mean the yellow borders).
Is it possible to include a way to choose borderless papers.
For example when you print on mac directly, you can choose DIN A4 (ohne Rand)/(Borderless).
Is there an ETA for when the Build version of this plugin will be updated to 0.6 or later? The deprecated 0.5 branch is still the latest that Build detects.
Update the plugin to support Android.
A custom version of the PrintPlugin plugin can be used.
Through the web version of Google Cloud Print - equivalent to Android.
Hello
I am using this plugin jquerymobile+phonegap. I have all html in a single page. when i use it always print the tree structure of html. can anybody please tell me how can i add css for that.
Thanks
Avneet
It seems that the print method is not capable of printing an image that has a src attribute as base 64 data. A normal window.print method from browser prints perfect this kind of content.
Here some sample code.
var qr = document.getElementById("printable-card-qr").getElementsByTagName("canvas")[0];;
var qrURL = qr.toDataURL();
var doc = "<html><body>A little qr image";
doc = doc + '<img src="'+qrURL+'"/>';
doc = doc + "</body></html>";
if(window.cordova){
// WHILE THIS DO NOT PRINTS THE IMAGE
$cordovaPrinter.print(doc);
}else{
var printWin = window.open("","processPrint");
printWin.document.open();
printWin.document.write(doc);
printWin.document.close();
// THIS PERFECTLY DOES
printWin.print();
}
This may be a limitation of Android Printing framework itself, I'd like for a user to be able to specify their default printer for X type of content and when they print X type of content it uses printer A, content Y can be set as default printer for printer B.
It appears this is possible w/ iOS using Printer ID function but I need NFC functionality too so iOS isn't an option for me.
So is there a way to accomplish what I want or does Android limit this functionality?
On my Nexus 4 with Android 4.4.4 my generated app crash until the print
function was called. ServiceIsAvailable
does not crash. App was created with Intel XDK.
Q | A |
---|---|
OS | Android |
OS Version | 4.4.4 |
Device | Nexus 4 |
Builder | Intel XDK |
Cordova Version | 3.3 |
Enabled Cordova Plugins | Device, Splashscreen |
Enabled Intel XDK Plugins | Base |
Third Party Plugins | Cordova Print Plugin |
Third Party Plugins Include way | by PluginId (de.appplant.cordova.plugin.printer) over Apache Cordova Plugins Registry |
Extra Added Permissons | none |
Test Environments | Tested with Crosswalk and without |
Enabled Print Services | Google Cloud Print, HP Print Plugin, Epson Print |
cordova.plugins.printer.isAvailable(
function (isAvailable) {
if (isAvailable) {
$('.print-btn').show();
$('.print-btn').click(function() {
var page = document.body;
// crash when call print
cordova.plugins.printer.print(page, 'index.html', function () {
});
});
}
}
);
any ideas how I can fix it to get it work with Intel XDK?
The plugin worked nicely before. Now upgraded all of our build systems (cordova, plugins, Xcode version upgrade). Since the upgrade the plugin works only on iPone/iPod but not on iPad. The Xcode log says
WARNING: Calling -[UIPrintInteractionController presentAnimated:completionHandler:] on iPad
Which seems to be correct as making the call device type aware and calling presentFromRect for iPad it is working again. I have tested it with the code below.
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[controller presentFromRect:CGRectMake(10, 10, 0, 0) inView:self.webView animated:YES completionHandler:
^(UIPrintInteractionController *ctrl, BOOL ok, NSError *e) {
CDVPluginResult* pluginResult =
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult
callbackId:_callbackId];
}];
}
else {
[controller presentAnimated:YES completionHandler:
^(UIPrintInteractionController *ctrl, BOOL ok, NSError *e) {
CDVPluginResult* pluginResult =
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult
callbackId:_callbackId];
}];
}
I didn't for it and add this change because the fix positioning isn't really nice. So posted here hoping someone got better solution for this.
PGB and Intel XDK keep crashing every time I try to build my app using this plugin, I tried using all the versions but no luck
Would be great to be able to set the position via coordinates of the print popup on the iPad running iOS 8. Currently it sits in the top-left corner.
Thanks!
Hi there,
I tried your example and it is working great. But when I tried to install this plugin in my app it fails to install the plugin.
-Suraj
when I add this plugin to my phonegap build 3.1
https://build.phonegap.com/plugins/352
but only the android platform will build failure
you can try it~
I have attached a screenshot from my logcat.
var page = '
cordova.plugins.printer.print(page, 'index.html', function () {
alert('printing finished or canceled')
});
I'm using this code to print. index.html is the page that I have in my application but I couldn't see any reason for this name to be required even though I'm just trying to print a string. Can you help?
Thanks
Hello everybody , I am new to phone gap development and plugin.
I have follow the instruction of cordova-plugin-printer ,
After install plugin by CLI and add <gap:plugin name="de.appplant.cordova.plugin.printer" />
to my file config xml. after that
I have add method
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("ready");
cordova.plugins.printer.isAvailable(function (available) {
alert(available);
});
}
to my index page.
I noted that document.addEventListener is work normally.
but
cordova.plugins.printer.isAvailable method seem not work.
I think I have follow all step of instruction
But still can not print page or just alert message
So anybody can tell me what I am doing wrong?
and So for my bad English.
Hi there,
I am able to print PDF generated from the app using this plugin but When user click on the Print Button app automatically defaults the name of pdf to 'Webview.pdf".
Is there any way to rename the PDF file name ? Coz I am not able to print directly from within app.
I must save as a pdf then print from the manufacturer's app.
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.