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
Properties

No properties

Constructor

Don't instantiate directly instances of the PrintService.

PrintService instances are automatically injected by Dynamics Mobile framework.

import { View, PrintService} from '$dms';
import { Customer } from '$dms-bo';
@View()
export class MyView {
constructor(
//we need to only declare the member
private PrintService: PrintService
){
}
async load(){
//we can now use the injected instance
await this.PrintService.print('iMZ320', 'Hello World printed');
}
}
App Types

📳 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
Description

print method sends the supplied text to the printer to print it

Parameters

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. }

Returns

void

Example

import { PrintService } from '@dms';
...
await this.PrintService.print(printerName:"Apex3BT"
textToPrint: "Hello World",
textWidth: 297,
textHeight: 197,
encoding: 'utf-8'
insecure:true
}

printImage(options): Promise<void>

Description
Parameters
Returns
Example
Description

The printImage sends and prints an image to a connected printer

Parameters

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. }

Returns

void

Example
import { PrintService } from '@dms';
...
await this.PrintService.printImage(printerName:"Apex3BT"
data: {
command: "27:23",
commandData: ".......",
printerModel: "Apex3",
printOptions:{}
},
secureConnection:true
}

getPrinters(): Promise<string[]>

Description
Parameters
Returns
Example
Description

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.

Parameters

Returns

string[]

Example
import { PrintService} from '@dms';
...
const btDevices = await this.PrintService.getPrinters();
btDevices.forEach(device=>{
console.log(`Device: ${device}`)
})