feat(printer): add v0.8.0 support (#3225)

Migrated interface to v0.8.0
Tested locally ok
This commit is contained in:
domschmidt 2019-11-19 09:32:07 +01:00 committed by Daniel Sogl
parent f4b03bcce4
commit 7d756394dd

View File

@ -1,6 +1,25 @@
import { Injectable } from '@angular/core';
import { Cordova, CordovaCheck, IonicNativePlugin, Plugin, getPromise } from '@ionic-native/core';
interface FontOptions {
name: string; // The name of the font family. Only supported on iOS
size: number; // The size of the font. Only supported on iOS, Android
italic: boolean; // Set to true to enable these font traits. Only supported on iOS
bold: boolean; // Set to true to enable these font traits. Only supported on iOS
align: 'left' | 'right' | 'center' | 'justified'; // Possible alignments are left, right, center and justified. Only supported on iOS
color: string; // The color of the font in hexa-decimal RGB format - "FF0000" means red. Only supported on iOS
}
interface HeaderFooterLabelOptions {
text: string; // The plain text to display. Use %ld to indicate where to insert the page index. For example "Page %ld" would result into "Page 1", "Page 2", .... Only supported on iOS
top: string; // The relative position where to place the label within the footer or header area. Only supported on iOS
right: string; // The relative position where to place the label within the footer or header area. Only supported on iOS
left: string; // The relative position where to place the label within the footer or header area. Only supported on iOS
bottom: string; // The relative position where to place the label within the footer or header area. Only supported on iOS
font: FontOptions; // The font attributes for the label. Only supported on iOS
showPageIndex: boolean; // Set to true if you want to display the page index. Only supported on iOS
}
export interface PrintOptions {
/**
* The name of the print job and the document
@ -8,16 +27,22 @@ export interface PrintOptions {
name?: string;
/**
* The network URL of the printer.
* Only supported on iOS.
* The number of copies for the print task.
* Only supported on iOS, Windows
*/
printerId?: string;
copies?: number;
/**
* Limits the pages to print even the document contains more.
* To skip the last n pages you can assign a negative value on iOS.
* Only supported on iOS, Android
*/
pageCount?: number;
/**
* Specifies the duplex mode to use for the print job.
* Either double-sided (duplex:true) or single-sided (duplex:false).
* Double-sided by default.
* Only supported on iOS
* Either double-sided on short site (duplex:'short'),
* double-sided on long site (duplex:'long') or single-sided (duplex:'none').
*/
duplex?: boolean;
@ -25,18 +50,85 @@ export interface PrintOptions {
* The orientation of the printed content, portrait or landscape
* Portrait by default.
*/
landscape?: boolean;
orientation?: 'landscape' | 'portrait';
/**
* If your application only prints black text, setting this property to true can result in better performance in many cases.
* False by default.
*/
grayscale?: boolean;
monochrome?: boolean;
/**
* The Size and position of the print view
* If your application only prints black text, setting this property to true can result in better performance in many cases.
* False by default.
* Only supported on iOS, Windows
*/
bounds?: number[] | any;
photo?: boolean;
/**
* Set to false to disable downscaling the image to fit into the content aread.
* Only supported on Android
*/
autoFit?: boolean;
/**
* The network URL to the printer.
* Only supported on iOS
*/
printer?: string;
/**
* Defines the maximum size of the content area.
* Only supported on iOS
*/
maxHeight?: string;
/**
* Defines the maximum size of the content area.
* Only supported on iOS
*/
maxWidth?: string;
/**
* Set to false to avoid margins.
* The margins for each printed page. Each printer might have its own minimum margins depends on media type and paper format.
*/
margin?: boolean | {
top?: string;
left?: string;
right?: string;
bottom?: string;
};
ui?: {
hideNumberOfCopies?: string; // Set to true to hide the control for the number of copies. Only supported on iOS
hidePaperFormat?: string; // Set to true to hide the control for the paper format. Only supported on iOS
top?: number; // The position of the printer picker. Only supported on iPad
left?: number; // The position of the printer picker. Only supported on iPad
height?: number; // The size of the printer picker. Only supported on iPad
width?: number; // The size of the printer picker. Only supported on iPad
};
paper?: {
width: string; // The dimensions of the paper iOS will will try to choose a format which fits bests. Only supported on iOS
height: string; // The dimensions of the paper iOS will will try to choose a format which fits bests. Only supported on iOS
name: string; // The name of the format like IsoA4 or Roll22Inch. https://docs.microsoft.com/en-us/uwp/api/windows.graphics.printing.printmediasize. Only supported on Windows
length: string; // On roll-fed printers you can decide when the printer cuts the paper. https://docs.microsoft.com/en-us/uwp/api/windows.graphics.printing.printmediasize. Only supported on iOs
};
font?: FontOptions;
header?: {
height: string; // The height of the header or footer on each page. Only supported on iOS
labels: string[]; // An array of labels to display. Only use if there are more then one. Only supported on iOS
label: HeaderFooterLabelOptions;
};
footer?: {
height: string; // The height of the header or footer on each page. Only supported on iOS
labels: string[]; // An array of labels to display. Only use if there are more then one. Only supported on iOS
label: HeaderFooterLabelOptions;
};
}
/**
@ -54,11 +146,10 @@ export interface PrintOptions {
*
* let options: PrintOptions = {
* name: 'MyDocument',
* printerId: 'printer007',
* duplex: true,
* landscape: true,
* grayscale: true
* }
* orientation: 'landscape',
* monochrome: true
* }
*
* this.printer.print(content, options).then(onSuccess, onError);
* ```
@ -85,14 +176,14 @@ export class Printer extends IonicNativePlugin {
}
/**
* Checks if the printer service is available (iOS) or if printer services are installed and enabled (Android).
* @return {Promise<any>} returns a promise that resolve with an object indicating whether printing is available, and providing the number of printers available
* Checks To check if printing is supported in general
* @return {Promise<any>} returns a promise that resolve with an object indicating whether printing is available
*/
@CordovaCheck()
check(): Promise<any> {
return getPromise<any>((resolve: Function) => {
Printer.getPlugin()
.check((avail: boolean, count: any) => {
.canPrintItem((avail: boolean, count: any) => {
resolve({ avail, count });
});
});
@ -117,7 +208,7 @@ export class Printer extends IonicNativePlugin {
successIndex: 2,
errorIndex: 4
})
print(content: string | HTMLElement, options?: PrintOptions): Promise<any> {
print(content?: string | HTMLElement, options?: PrintOptions): Promise<any> {
return;
}