PrintService
Printing from mobile and backend apps

Overview

SERVICE This class is a "service" and it is automatically injected if declared as a member in the constructor of the consuming class. - See the constructor section below for details - See the Automatic Instance Injection page for details on the topic
The PrintService class provides methods to work with printers
Properties
Methods
Constructor
App Types
No properties
Don't instantiate directly instances of the PrintService.
PrintService instances are automatically injected by Dynamics Mobile framework.
1
import { View, PrintService} from '$dms';
2
import { Customer } from '$dms-bo';
3
4
@View()
5
export class MyView {
6
7
constructor(
8
//we need to only declare the member
9
private PrintService: PrintService
10
){
11
12
}
13
14
async load(){
15
//we can now use the injected instance
16
await this.PrintService.print('iMZ320', 'Hello World printed');
17
}
18
19
}
Copied!
📳
Mobile
🌐
Backend
There is a difference in the behaviour of the PrintService API in mobile and backend apps.

print(options): Promise<void>

Description
Parameters
Returns
Example
print method sends the supplied text to the printer to print it
options: { printerName: string - name of the printer obtain via getPrinters method textToPrint: string - text content to be printed pageWidth: number - width if the page in dots pageHeight: number - height of the page in dots encoding: 'utf-8'|'acii'|'8859-5'|'cp866'|'cp864'|'cp1256'|'cp863'|'cp858'|'apex'|'koi8-r'|any insecure: boolean - value of true will print to a bluetooth paired printer. }
void
1
import { PrintService } from '@dms';
2
3
...
4
await this.PrintService.print(printerName:"Apex3BT"
5
textToPrint: "Hello World",
6
textWidth: 297,
7
textHeight: 197,
8
encoding: 'utf-8'
9
insecure:true
10
}
Copied!

printImage(options): Promise<void>

Description
Parameters
Returns
Example
The printImage sends and prints an image to a connected printer
options: { printerName: string data: { command: string - printer specific command to print an image,depends on the printer type commandData: string - encoded image, format depends on the printer type printerModel?: "Apex3"|"Alpha-3R"|"MIP480"|any - printer type printOptions?: any - printer specific options }, secureConnection?: boolean - value of true will print to a bluetooth paired printer. }
void
1
import { PrintService } from '@dms';
2
3
...
4
await this.PrintService.printImage(printerName:"Apex3BT"
5
data: {
6
command: "27:23",
7
commandData: ".......",
8
printerModel: "Apex3",
9
printOptions:{}
10
},
11
secureConnection:true
12
}
Copied!

getPrinters(): Promise<string[]>

Description
Parameters
Returns
Example
getPrinters method returns list with the names of of bluetooth paired printers. It actually returns all bluetooth paired devices, so the developer needs to provide a mechanism for the user to point out the actual printer name and save it into a configuration.
string[]
1
import { PrintService} from '@dms';
2
3
...
4
const btDevices = await this.PrintService.getPrinters();
5
btDevices.forEach(device=>{
6
console.log(`Device: ${device}`)
7
})
Copied!
Last modified 1yr ago