A bunch of printing plugins for Cordova 3.x.x
by Sebastián Katzer (github.com/katzer)
-
iOS (Print from iOS devices to AirPrint compatible printers)
See Drawing and Printing Guide for iOS for detailed informations and screenshots. -
Android (Print through 3rd party printing apps)
Through the Command-line Interface:
# from master:
cordova plugin add https://github.com/katzer/cordova-plugin-printer.git
cordova build
# stable version:
cordova de.appplant.cordova.plugin.printer
cordova build
Through the Command-line Interface:
cordova plugin rm de.appplant.cordova.plugin.printer
Add the following xml to your config.xml to always use the latest version of this plugin:
<gap:plugin name="de.appplant.cordova.plugin.printer" />
or to use this exact version:
<gap:plugin name="de.appplant.cordova.plugin.printer" version="0.5.1" />
More informations can be found here.
- [feature]: Added Windows8 support
Thanks to pirvudoru
- [bugfix:]
isServiceAvailable
on Android did not return a list of available printing apps.
- Removed Android KitKat support (See kitkat branch)
- Release under the Apache 2.0 license.
- [change:] Removed the
callback
property from theprint
interface. - [enhancement:] Added Android KitKat support
Based on the Print Android plugin made by Eion Robb
- [feature]: Added Android support
Based on the Print Android plugin made by Eion Robb - [feature]:
print()
accepts a 4th arguments for platform specific properties. - [change]: the callback of
print()
will be called with a result code about the user action.
- [feature]: Support for callback scopes.
- [feature]: Added iOS support
Based on the Print iOS plugin made by Randy McMillan
The plugin creates the object window.plugin.printer
with two methods:
Printing is only available on devices capable of multi-tasking (iPhone 3GS, iPhone 4 etc.) running iOS 4.2 or later. You can use this function to hide print functionality from users who will be unable to use it.
Function takes a callback function, passed to which is a boolean property. Optionally you can assign the scope in which the callback will be executed as a second parameter (default to window).
/*
* Find out if printing is available. Use this for showing/hiding print buttons.
*/
window.plugin.printer.isServiceAvailable(
function (isAvailable) {
alert(isAvailable ? 'Service is available' : 'Service NOT available');
}
);
Function takes an html string.
Note: All required CSS rules needs to be included as well.
// Get HTML string
var page = document.body.innerHTML;
// Pass the HTML
window.plugin.printer.print(page);
The callback function will be called with a second argument which is an array, indicating which printer apps are available for printing.
window.plugin.printer.isServiceAvailable(
function (isAvailable, installedAppIds) {
alert('The following print apps are installed on your device: ' + installedAppIds.join(', '));
}
);
An App-ID can be assigned as a platform configuration to indicate which 3rd party printing app shall be used. Otherwise the first found application will be used.
window.plugin.printer.print(page, { appId: 'epson.print' });
There's no need to waste lots of paper when testing - if you're using the iOS simulator, select File->Open Printer Simulator to open some dummy printers (print outs will appear as PDF files).
Use the 'page-break-before' property to specify a page break, e.g.
<p>
First page.
</p>
<p style="page-break-before: always">
Second page.
</p>
See W3Schools for more more information: http://www.w3schools.com/cssref/pr_print_pagebb.asp
Note: you will need to add an extra top margin to new pages.
Printing is only supported on AirPrint-enabled printers or with the use of third-party software on your computer. The following pages contain more information:
- AirPrint-enabled printers: http://www.apple.com/ipad/features/airprint.html
- Enabling AirPrint on your computer: http://reviews.cnet.com/8301-19512_7-20023976-233.html, or http://www.ecamm.com/mac/printopia/
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
This software is released under the Apache 2.0 License.