From 48ffcaeb61088b7c86f5ebb001d7de74d9e94a08 Mon Sep 17 00:00:00 2001 From: Zachary Keeton Date: Wed, 15 Jun 2016 11:39:01 -0400 Subject: [PATCH] feat(printer): add printer plugin (#225) * feat(printer): add printer plugin * Fixed function implementations. Removed unnecessary reference. --- src/index.ts | 3 ++ src/plugins/printer.ts | 64 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/plugins/printer.ts diff --git a/src/index.ts b/src/index.ts index a02384e66..1ed439447 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,6 +52,7 @@ import {LaunchNavigator} from './plugins/launchnavigator'; import {LocalNotifications} from './plugins/localnotifications'; import {MediaPlugin} from './plugins/media'; import {Network, Connection} from './plugins/network'; +import {Printer} from './plugins/printer'; import {Push} from './plugins/push'; import {SafariViewController} from './plugins/safari-view-controller'; import {Screenshot} from './plugins/screenshot'; @@ -85,6 +86,7 @@ export * from './plugins/inappbrowser'; export * from './plugins/launchnavigator'; export * from './plugins/localnotifications'; export * from './plugins/media'; +export * from './plugins/printer'; export * from './plugins/push'; export * from './plugins/safari-view-controller'; export * from './plugins/sms'; @@ -183,6 +185,7 @@ window['IonicNative'] = { LocalNotifications: LocalNotifications, MediaPlugin: MediaPlugin, Network: Network, + Printer: Printer, Push: Push, SafariViewController: SafariViewController, Screenshot: Screenshot, diff --git a/src/plugins/printer.ts b/src/plugins/printer.ts new file mode 100644 index 000000000..cfa35ef19 --- /dev/null +++ b/src/plugins/printer.ts @@ -0,0 +1,64 @@ +import {Plugin, Cordova} from './plugin'; +declare var cordova: any; + +export interface PrintOptions { + /** + * The name of the print job and the document + */ + name?: string; + + /** + * The network URL of the printer. + * Only supported on iOS. + */ + printerId?: string; + + /** + * 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 + */ + duplex?: boolean; + + /** + * The orientation of the printed content, portrait or landscape + * Portrait by default. + */ + landscape?: boolean; + + /** + * 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; + + /** + * The Size and position of the print view + */ + bounds?: number[] | any; +} + + +@Plugin({ + plugin: 'de.appplant.cordova.plugin.printer', + pluginRef: 'cordova.plugins.printer', + repo: 'https://github.com/katzer/cordova-plugin-printer.git', + platforms: ['Android', 'iOS'] +}) +export class Printer { + + /** + * Checks whether to device is capable of printing. + */ + @Cordova() + static isAvailable(): Promise { return; } + + /** + * Sends content to the printer. + * @param {content} The content to print. Can be a URL or an HTML string. If a HTML DOM Object is provided, its innerHtml property value will be used. + * @param {options} The options to pass to the printer + */ + @Cordova() + static print(content: string | HTMLElement, options?: PrintOptions): Promise { return; } +}