Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Printer

Improve this doc

Prints documents or HTML rendered content

Repo: https://github.com/katzer/cordova-plugin-printer

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-printer
    $ npm install --save @ionic-native/printer@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { Printer, PrintOptions } from '@ionic-native/printer';

constructor(private printer: Printer) { }

...

this.printer.isAvailable().then(onSuccess, onError);

let options: PrintOptions = {
     name: 'MyDocument',
     printerId: 'printer007',
     duplex: true,
     landscape: true,
     grayscale: true
   };

this.printer.print(content, options).then(onSuccess, onError);

Instance Members

isAvailable()

Checks whether the device is capable of printing (uses check() internally)

Returns: Promise<boolean>

check()

Checks if the printer service is available (iOS) or if printer services are installed and enabled (Android).

Returns: Promise<any> returns a promise that resolve with an object indicating whether printing is available, and providing the number of printers available

pick()

Displays a system interface allowing the user to select an available printer. To speak with a printer directly you need to know the network address by picking them before via printer.pick.

Returns: Promise<any>

print(content, options)

Sends content to the printer.

Param Type Details
content string|HTMLElement

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.

options PrintOptions

optional. The options to pass to the printer

Returns: Promise<any>

PrintOptions

Param Type Details
name string

The name of the print job and the document

(optional)
printerId string

The network URL of the printer. Only supported on iOS.

(optional)
duplex boolean

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

(optional)
landscape boolean

The orientation of the printed content, portrait or landscape Portrait by default.

(optional)
grayscale boolean

If your application only prints black text, setting this property to true can result in better performance in many cases. False by default.

(optional)
bounds number[] | any

The Size and position of the print view

(optional)

API

Native

General