Update docs

This commit is contained in:
Sebastián Katzer 2019-02-12 12:22:33 +01:00
parent ee38edb616
commit fe2f72ff1a
3 changed files with 81 additions and 48 deletions

126
README.md
View File

@ -30,54 +30,35 @@ Plugin for [Cordova][cordova] to print documents or photos from iOS, Android and
- Windows 10 UWP - Windows 10 UWP
## Installation
The plugin can be installed via [CLI][CLI] and is publicly available on [NPM][npm].
Execute from the projects root folder:
$ cordova plugin add cordova-plugin-printer
Or install a specific version:
$ cordova plugin add cordova-plugin-printer@VERSION
Or install the latest head version:
$ cordova plugin add https://github.com/katzer/cordova-plugin-printer.git
Or install from local source:
$ cordova plugin add <path> --nofetch --nosave
And then execute:
cordova build
## Basics ## Basics
The plugin creates the object `cordova.plugins.printer` and is accessible after the *deviceready* event has been fired. The plugin creates the object `cordova.plugins.printer` and is accessible after the *deviceready* event has been fired.
To print plain text: To print plain text:
```javascript
cordova.plugins.printer.print();
```
Plain text:
```javascript ```javascript
cordova.plugins.printer.print("Hello\nWorld!"); cordova.plugins.printer.print("Hello\nWorld!");
``` ```
Or HTML+CSS: HTML & CSS:
```javascript ```javascript
cordova.plugins.printer.print('<h1>Hello World!</h1>'); cordova.plugins.printer.print('<h1>Hello World!</h1>');
``` ```
Or images or documents: Images, PDF and other documents:
```javascript ```javascript
cordova.plugins.printer.print('file://img/logo.png'); cordova.plugins.printer.print('file://img/logo.png');
``` ```
Or Base64 content: Base64 encoded content:
```javascript ```javascript
cordova.plugins.printer.print('base64://...'); cordova.plugins.printer.print('base64://...');
@ -85,34 +66,56 @@ cordova.plugins.printer.print('base64://...');
## Formatting ## Formatting
It's possible to pass by additional format options. The list of possible options depend on the platform and the content type: It's possible to pass format options to the print method that overrides the defaults:
```javascript ```javascript
cordova.plugins.printer.print(content, options); cordova.plugins.printer.print(content, options, callback);
``` ```
TODO The defaults are defined as follows:
The method accepts a list of attributes. Not all are supported on each platform and by each printer! ```javascript
cordova.plugins.printer.setDefaults({ monochrome: true });
```
The list of possible options depend on the platform, the content type and the capabilities of the printer.
| Name | Description | Type | Platform | | Name | Description | Type | Platform |
|:---- |:----------- |:----:| --------:| |:---- |:----------- |:----:| --------:|
| name | The name of the print job and of the document | String | all | | name | The name of the print job and of the document. | String | all |
| duplex | Specifies the duplex mode to use for the print job.<br>Either double-sided on short site (duplex:'short'), double-sided on long site (duplex:'long') or single-sided (duplex:'none').<br>Defaults to: 'none' | String | all | | copies | The number of copies for the print task. | Number | iOS<br>Windows |
| landscape| The orientation of the printed content, portrait or landscape.<br>Defaults to: false | Boolean | all | | pageCount | Limits the pages to print even the document contains more.<br>To skip the last n pages you can assign a negative value on iOS. | Number | iOS<br>Android |
| graystyle | If your application only prints black text, setting this property to _true_ can result in better performance in many cases.<br>Defaults to: false | Boolean | all | | duplex | Either double-sided on short site (duplex:'short'), double-sided on long site (duplex:'long') or single-sided (duplex:'none'). | String | all |
| printerId | The network URL to the printer. | String | iOS | | landscape| The orientation of the printed content, portrait or landscape. | Boolean | all |
| border | Set to _false_ to skip any border. Useful for fullscreen images.<br>Defaults to: true | Boolean | iOS | | monochrome | If your application only prints black text, setting this property to _true_ can result in better performance in many cases. | Boolean | all |
| hidePageRange | Set to _true_ to hide the control for the page range.<br>Defaults to: false | Boolean | iOS | | photo | Set to _true_ to change the media type to photography for higher quality. | Boolean | iOS<br>Windows |
| hideNumberOfCopies | Set to _true_ to hide the control for the number of copies.<br>Defaults to: false | Boolean | iOS | | printer | The network URL to the printer. | String | iOS |
| hidePaperFormat | Set to _true_ to hide the control for the paper format.<br>Defaults to: false | Boolean | iOS | | maxHeight<br>maxWidth | Defines the maximum size of the content area. | Unit | iOS |
| paperWidth | Ability to hint width of the paper iOS will get a printer supported paperformat which fits the best to this width. Only works when `paperHeight` is given. Width in millimeters. | Number | iOS | | margin.top<br>margin.left<br>margin.right<br>margin.bottom | The margins for each printed page. Each printer might have its own minimum margins depends on media type and paper format. | Unit | iOS |
| paperHeight | Ability to hint height of the paper iOS will get a printer paperformat which fits the best to this heigth. Only works when `paperWidth` is given. Height in millimeters. | Number | iOS | | ui.hideNumberOfCopies | Set to _true_ to hide the control for the number of copies. | Boolean | iOS |
| paperCutLength | On roll-fed printers you can decide after how many milimeters the printer cuts the paper. | Number | iOS | | ui.hidePaperFormat | Set to _true_ to hide the control for the paper format. | Boolean | iOS |
| bounds | The Size and position of the print view<br>Defaults to: [40, 30, 0, 0] | Array | iPad | | ui.top<br>ui.left | The position of the printer picker. | Number | iPad |
| ui.height<br>ui.width | The size of the printer picker. | Number | iPad |
| paper.width<br>paper.height | The dimensions of the paper iOS will will try to choose a format which fits bests. | Unit | iOS |
| paper.name | The name of the format like `IsoA4` or `Roll22Inch`.<br>https://docs.microsoft.com/en-us/uwp/api/windows.graphics.printing.printmediasize | String | Windows |
| paper.length | On roll-fed printers you can decide when the printer cuts the paper. | Unit | iOS |
| font.name | The name of the font family | String | iOS |
| font.size | The size of the font | Number | iOS<br>Android |
| font.italic<br>font.bold | Set to _true_ to enable these font traits. | Boolean | iOS |
| font.align | Possible alignments are `left`, `right`, `center` and `justified`. | String | iOS |
| font.color | The color of the font in hexa-decimal RGB format - `"FF0000"` means red. | String | iOS |
| header.height<br>footer.height | The height of the header or footer on each page. | Unit | iOS |
| header.labels<br>footer.labels | An array of labels to display. Only use if there are more then one. | Array | iOS |
| header.label.text<br>footer.label.text | The plain text to display. Use `%ld` to indicate where to insert the page index.<br>For example `"Page %ld"` would result into `"Page 1"`, `"Page 2"`, ... | String | iOS |
| header.label.top<br>header.label.right<br>header.label.left<br>header.label.bottom<br>footer.label.* | The relative position where to place the label within the footer or header area. | Unit | iOS |
| header.label.font<br>footer.label.font | The font attributes for the label. | Object | iOS |
| header.label.showPageIndex<br>footer.label.showPageIndex | Set to _true_ if you want to display the page index.<br> | Boolean | iOS |
Use `getDefaults()` or `setDefaults()` to specify default options. The `Unit` type can be either a (float) number or a string with a special suffix.
- Supported unit suffixes are `in` for inches, `mm` for millimeters, `cm` for centimeters and `pt` for points
- `"2in"` are two inches whereas `2.0` or `"2.0pt"` are identical for two points
- One inch are 72.0 points
## Direct Print ## Direct Print
@ -128,6 +131,12 @@ To let the user pick an available printer:
cordova.plugins.printer.pick(function (url) {}); cordova.plugins.printer.pick(function (url) {});
``` ```
It's possible to specify the position of the picker:
```javascript
cordova.plugins.printer.pick({ top: 40, left: 30 }, callback);
```
__Note:__ By passing an invalid URL, the application will throw an `Unable to connect to (null)` exception and possibly crash. __Note:__ By passing an invalid URL, the application will throw an `Unable to connect to (null)` exception and possibly crash.
@ -154,6 +163,31 @@ cordova.plugins.printer.canPrintItem('file://css/index.css', callback);
``` ```
## Installation
The plugin can be installed via [CLI][CLI] and is publicly available on [NPM][npm].
Execute from the projects root folder:
$ cordova plugin add cordova-plugin-printer
Or install a specific version:
$ cordova plugin add cordova-plugin-printer@VERSION
Or install the latest head version:
$ cordova plugin add https://github.com/katzer/cordova-plugin-printer.git
Or install from local source:
$ cordova plugin add <path> --nofetch --nosave
Then execute:
cordova build
## Contributing ## Contributing
1. Fork it 1. Fork it

View File

@ -84,7 +84,6 @@
<header-file src="src/ios/UIPrintInteractionController+APPPrinter.h" /> <header-file src="src/ios/UIPrintInteractionController+APPPrinter.h" />
<source-file src="src/ios/UIPrintInteractionController+APPPrinter.m" /> <source-file src="src/ios/UIPrintInteractionController+APPPrinter.m" />
</platform> </platform>
<!-- android --> <!-- android -->

View File

@ -30,11 +30,11 @@ exports._defaults = {
// duplex: 'none', // duplex: 'none',
// landscape: false, // landscape: false,
// monochrome: false, // monochrome: false,
// photo: false,
// copies: 1, // copies: 1,
// pageCount: 1, // pageCount: 1,
// border: true,
// maxHeight: '10cm', // maxHeight: '10cm',
// maxWidth: '10cm', // maxWidth: '10cm',