cordova-plugin-printer/README.md

135 lines
4.8 KiB
Markdown
Raw Normal View History

2013-08-10 18:05:56 +08:00
Cordova Printer-Plugin
2013-08-10 00:44:19 +08:00
======================
2013-08-10 18:05:56 +08:00
A bunch of printing plugins for Cordova 3.x.x
2013-08-10 18:44:28 +08:00
by Sebastián Katzer ([github.com/katzer](https://github.com/katzer))
2013-08-25 02:28:11 +08:00
## Supported Platforms
2013-08-13 22:38:07 +08:00
- **iOS** *(Print from iOS devices to AirPrint compatible printers)*<br>
See [Drawing and Printing Guide for iOS](http://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/Printing/Printing.html) for detailed informations and screenshots.
2013-09-08 01:00:14 +08:00
2013-12-11 22:49:00 +08:00
- **Android** *(Print through 3rd party printing apps on SDK <= 18)*
2013-08-10 18:44:28 +08:00
2013-08-25 02:28:11 +08:00
## Adding the Plugin to your project
2013-08-10 18:44:28 +08:00
Through the [Command-line Interface](http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface):
```bash
cordova plugin add https://github.com/katzer/cordova-plugin-printer.git
```
## Removing the Plugin from your project
Through the [Command-line Interface](http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface):
```
cordova plugin rm de.appplant.cordova.plugin.printer
```
2013-08-25 02:28:11 +08:00
## Release Notes
#### Version 0.5.0 (not yet released)
2013-12-11 20:00:16 +08:00
- Release under the Apache 2.0 license.
- [***change:***] Removed the `callback` property from the `print` interface.
2013-12-11 22:49:00 +08:00
- [enhancement:] Added Android KitKat support<br>
*Based on the Print Android plugin made by* ***Eion Robb***
2013-08-25 02:28:11 +08:00
#### Version 0.4.0 (24.08.2013)
- [feature]: Added Android support<br>
*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.
2013-08-13 22:05:24 +08:00
2013-08-25 02:28:11 +08:00
#### Version 0.2.1 (13.08.2013)
- [feature]: Support for callback scopes.
#### Version 0.2.0 (11.08.2013)
- [feature]: Added iOS support<br>
*Based on the Print iOS plugin made by* ***Randy McMillan***
2013-08-10 18:44:28 +08:00
2013-08-25 02:28:11 +08:00
## Using the plugin
2013-08-10 18:44:28 +08:00
The plugin creates the object ```window.plugin.printer``` with two methods:
2013-08-25 02:28:11 +08:00
### isServiceAvailable()
2013-08-13 22:05:24 +08:00
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.<br>
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*).
2013-08-10 18:44:28 +08:00
```javascript
/*
2013-08-10 18:53:29 +08:00
* Find out if printing is available. Use this for showing/hiding print buttons.
2013-08-10 18:44:28 +08:00
*/
window.plugin.printer.isServiceAvailable(
function (isAvailable) {
2013-12-01 21:32:16 +08:00
alert(isAvailable ? 'Service is available' : 'Service NOT available');
2013-08-10 18:44:28 +08:00
}
);
```
2013-08-25 02:28:11 +08:00
### print()
Function takes an html string.
**Note:** All required CSS rules needs to be included as well.
2013-08-10 18:44:28 +08:00
```javascript
// Get HTML string
var page = document.body.innerHTML;
// Pass the HTML
window.plugin.printer.print(page);
2013-08-10 18:44:28 +08:00
```
2013-12-01 21:38:17 +08:00
## Platform specifics
2013-08-25 02:28:11 +08:00
2013-12-11 22:49:00 +08:00
### Get all available printing apps on Android <= 4.3
2013-12-01 21:38:17 +08:00
The callback function will be called with a second argument which is an array, indicating which printer apps are available for printing.
```javascript
window.plugin.printer.isServiceAvailable(
function (isAvailable, installedAppIds) {
alert('The following print apps are installed on your device: ' + installedAppIds.join(', '));
}
);
```
2013-12-11 22:49:00 +08:00
### Specify printing app on Android <= 4.3
2013-12-01 21:38:17 +08:00
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.
2013-08-25 02:28:11 +08:00
```javascript
window.plugin.printer.print(page, { appId: 'epson.print' });
2013-08-25 02:28:11 +08:00
```
## Quirks
### Testing in the iOS Simulator
2013-08-10 18:44:28 +08:00
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).
2013-08-25 02:28:11 +08:00
### Adding Page Breaks to Printouts
2013-08-10 18:44:28 +08:00
Use the 'page-break-before' property to specify a page break, e.g.
```html
<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.
2013-08-25 02:28:11 +08:00
### Printing on Real Printers (iOS)
2013-08-10 18:44:28 +08:00
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/
2013-12-01 21:33:10 +08:00
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
## License
2013-12-11 20:00:16 +08:00
This software is released under the [Apache 2.0 License](http://opensource.org/licenses/Apache-2.0).