printer
Extends NativeObject
Allows to print PDF documents from the device. A printer object is always available from tabris.printer.
Import this object with “const {printer} = require('tabris');
”
Methods
print(data, options)
iOSAndroid
Parameters:
- data: any
- the bytes of the document to print. The value can either be an ArrayBuffer or a typed array.
- options: {jobName?: string} [Optional]
- an optional set of configuration parameters. Setting the
jobName
allows to provide the document name shown the user.
- an optional set of configuration parameters. Setting the
Returns: *Promise
Prints a PDF document using the native printing capabilities of the device. The data has to be provided as an ArrayBuffer
or typed array. The method returns a promise which resolves to an event object with the property result
. The result
can either be completed
or canceled
. When printing fails the promise is rejected with an Error
parameter containing additional information about the error. Supported on iOS and Android 4.4+.
Example
const {Button, printer, ui, app} = require('tabris');
// Print a bundled PDF
new Button({
left: 16, right: 16, top: 16,
text: 'Print PDF'
}).on('select', () => {
fetch(app.getResourceLocation('resources/example.pdf'))
.then(res => res.arrayBuffer())
.then(data => printer.print(data, {jobName: 'tabris print example'}))
.then(event => console.log('Printing finished', event))
.catch(err => console.error(err));
}).appendTo(ui.contentView);