Print

Introduction

The Trust1Connector print module provides the integrator the ability to communicate with local printers. It provides an interface to retrieve the available printers and then execute a specific print job on one of those printers.

Interface

Below you can find the interface of the Trust1Connector print module.
1
export interface AbstractRawPrint {
2
list( callback?: (error: T1CLibException, data: PrinterListResponse) => void): Promise<PrinterListResponse>;
3
print(name: string, job: string, data: string, callback?: (error: T1CLibException, data: PrintResponse) => void): Promise<PrintResponse>;
4
}
Copied!

Model Objects

Below you can find the available models for Trust1Connector print module which are used in the interface.
1
export class PrinterList {
2
constructor(public printers: Array<string>) {}
3
}
4
5
export class PrinterListResponse extends T1CResponse {
6
constructor(public data: PrinterList, public success: boolean) {
7
super(success, data);
8
}
9
}
10
11
export class Print {
12
constructor(public printed: boolean) {}
13
}
14
15
export class PrintResponse extends T1CResponse {
16
constructor(public data: Print, public success: boolean) {
17
super(success, data);
18
}
19
}
20
Copied!

Get Printer module object

Before we can use the print module we need to Initialise the Trust1Connector. The code sample below is a simplified version, for the complete initialise flow you can see Integration in Web Applications
1
T1CSdk.T1CClient.initialize(config).then(res => {
2
client = res;
3
}, err => {
4
console.error(error)
5
});
Copied!
After you've initialised the Trust1Connector you can use the client/response of the initialise function to instantiate the rawprint module. Later on we can keep using this module to execute various print functions provided by the Trust1Connector interface.
1
var print = client.rawprint();
Copied!
In the example below we execute the list function available in the rawprint module. Here we use the callback mechanism but a Promise is also available as defined in the interface
1
function callback(err,data) {
2
if(err){console.log("Error:",JSON.stringify(err, null, ' '));}
3
else {console.log(JSON.stringify(data, null, ' '));}
4
}
5
print.list(callback);
Copied!

List

The list function provides an iterator of all the available printers locally. These will return as identifiers that can be used when executing a print action as described in the Print function
1
client.rawprint().list(callback);
Copied!
An example callback:
1
function callback(err,data) {
2
if(err){
3
console.log("Error:",JSON.stringify(err, null, ' '));
4
}
5
else {
6
console.log(JSON.stringify(data, null, ' '));
7
}
8
}
Copied!
Response:
1
{
2
"printers": ["123"],
3
}
Copied!

Print

The Print function available on the interface provides print capabilities via the Trust1Connector. Here you need to specify the print job name, a name for the printer which can be fetched via the List function and the Data.
The data block needs to be base64 encoded.
1
const name = "test"
2
const job = "test-job-01"
3
const data = "SSdtIGRlZmluaXRseSBub3QgYSBNQUxBS0E="
4
client.rawprint().print(name, job, data, callback);
Copied!
An example callback:
1
function callback(err,data) {
2
if(err){
3
console.log("Error:",JSON.stringify(err, null, ' '));
4
}
5
else {
6
console.log(JSON.stringify(data, null, ' '));
7
}
8
}
Copied!
The print function will respond with a True or False depending on wether the command succeeded or failed.
1
{
2
"printed": true/false,
3
}
Copied!
Last modified 4mo ago