# @ohos.print (Print) (System API)
The **print** module provides APIs for basic print operations.
> **NOTE**
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.print (Print)](./js-apis-print-sys.md).
## Modules to Import
```ts
import { print } from '@kit.BasicServicesKit';
```
## PrintMargin
Defines the page margins for printing.
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Attributes**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| top | number | No| Top margin of the page. The default value is **0**.|
| bottom | number | No| Bottom margin of the page. The default value is **0**.|
| left | number | No| Left margin of the page. The default value is **0**.|
| right | number | No| Right margin of the page. The default value is **0**.|
## PrinterRange
Defines the print range.
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Attributes**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| startPage | number | No| Start page. The default value is **1**.|
| endPage | number | No| End page. The default value is the maximum number of pages of the file to be printed.|
| pages | Array<number> | No| Page range set of the file to print. The default value is empty.|
## PreviewAttribute
Defines the print preview attributes.
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Attributes**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| previewRange | [PrinterRange](#printerrange) | Yes| Preview page range.|
| result | number | No| Print preview result. The default value is **-1**.|
## PrintResolution
Defines the resolution for printing.
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Attributes**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| id | string | Yes| Resolution ID.|
| horizontalDpi | number | Yes| Horizontal DPI.|
| verticalDpi | number | Yes| Vertical DPI.|
## PrinterCapability
Defines the printer capabilities.
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Attributes**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| colorMode | number | Yes| Color mode.|
| duplexMode | number | Yes| Single-sided or double-sided printing mode.|
| pageSize | Array<[PrintPageSize](./js-apis-print.md#printpagesize11)> | Yes| List of page sizes supported by the printer.|
| resolution | Array<[PrintResolution](#printresolution)> | No| List of resolutions supported by the printer.|
| minMargin | [PrintMargin](#printmargin) | No| Minimum margin of the printer.|
| options11+ | Object | No| Printer options. The value is a JSON object string.|
## PrinterInfo
Provides the printer information.
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Attributes**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerId | string | Yes| Printer ID.|
| printerName | string | Yes| Printer name.|
| printerState | [PrinterState](./js-apis-print.md#printerstate14) | Yes| Printer state.|
| printerIcon | number | No| Resource ID of the printer icon. The default value is **-1**.|
| description | string | No| Printer description.|
| capability | [PrinterCapability](#printercapability) | No| Printer capability.|
| options | Object | No| Printer options. The value is a JSON object string.|
## PrintJob
Defines a print job.
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Attributes**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| fdList | Array<number> | Yes| FD list of files to print.|
| jobId | string | Yes| ID of the print job.|
| printerId | string | Yes| ID of the printer used for printing.|
| jobState | [PrintJobState](./js-apis-print.md#printjobstate14) | Yes| State of the print job.|
| jobSubstate11+ | [PrintJobSubState](./js-apis-print.md#printjobsubstate14) | Yes| Substate of the print job.|
| copyNumber | number | Yes| Copy of the file list.|
| pageRange | [PrinterRange](#printerrange) | Yes| Print range.|
| isSequential | boolean | Yes| Whether the printing is sequential. The value **true** means that the printing is sequential; the value **false** means the opposite. The default value is **false**.|
| pageSize | [PrintPageSize](./js-apis-print.md#printpagesize11) | Yes| Selected page size.|
| isLandscape | boolean | Yes| Whether the printing is in landscape mode. The value **true** means that the printing is in landscape mode; the value **false** means the printing is in portrait mode The default value is **false**.|
| colorMode | number | Yes| Color mode.|
| duplexMode | number | Yes| Single-sided or double-sided printing mode.|
| margin | [PrintMargin](#printmargin) | No| Current page margin.|
| preview | [PreviewAttribute](#previewattribute) | No| Preview settings.|
| options | Object | No| Printer options. The value is a JSON object string.|
## PrinterExtensionInfo
Provides the printer extension information.
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Attributes**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| extensionId | string | Yes| ID of the printer extension.|
| vendorId | string | Yes| Vendor ID of the printer extension.|
| vendorName | string | Yes| Vendor name of the printer extension.|
| vendorIcon | number | Yes| Vendor icon of the printer extension.|
| version | string | Yes| Version of the printer extension.|
## print.queryAllPrinterExtensionInfos
queryAllPrinterExtensionInfos(callback: AsyncCallback<Array<PrinterExtensionInfo>>): void
Obtains the information of all installed printer extensions. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<Array<[PrinterExtensionInfo](#printerextensioninfo)>> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
print.queryAllPrinterExtensionInfos((err: BusinessError, extensionInfos: print.PrinterExtensionInfo[]) => {
if (err) {
console.error('queryAllPrinterExtensionInfos err ' + JSON.stringify(err));
} else {
console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos));
}
})
```
## print.queryAllPrinterExtensionInfos
queryAllPrinterExtensionInfos(): Promise<Array<PrinterExtensionInfo>>
Obtains the information of all installed printer extensions. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<Array<[PrinterExtensionInfo](#printerextensioninfo)>> | Promise used to return the result.used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
print.queryAllPrinterExtensionInfos().then((extensionInfos: print.PrinterExtensionInfo[]) => {
console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos));
// ...
}).catch((error: BusinessError) => {
console.error('failed to get AllPrinterExtension because ' + JSON.stringify(error));
})
```
## print.disconnectPrinter
disconnectPrinter(printerId: string, callback: AsyncCallback<void>): void
Disconnects from the specified printer. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerId | string | Yes| Printer ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId: string = 'printerId_32';
print.disconnectPrinter(printerId, (err: BusinessError) => {
if (err) {
console.error('failed to disconnect Printer because : ' + JSON.stringify(err));
} else {
console.log('start disconnect Printer success');
}
})
```
## print.disconnectPrinter
disconnectPrinter(printerId: string): Promise<void>
Disconnects from the specified printer. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerId | string | Yes| Printer ID.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId: string = 'printerId_32';
print.disconnectPrinter(printerId).then(() => {
console.log('start disconnect Printer success');
}).catch((error: BusinessError) => {
console.error('failed to disconnect Printer because : ' + JSON.stringify(error));
})
```
## print.queryPrinterCapability
queryPrinterCapability(printerId: string, callback: AsyncCallback<void>): void
Queries the printer capability. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerId | string | Yes| Printer ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId: string = 'printerId_32';
print.queryPrinterCapability(printerId, (err: BusinessError) => {
if (err) {
console.error('failed to query Printer Capability because : ' + JSON.stringify(err));
} else {
console.log('start query Printer Capability success');
}
})
```
## print.queryPrinterCapability
queryPrinterCapability(printerId: string): Promise<void>
Queries the printer capability. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerId | string | Yes| Printer ID.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId: string = 'printerId_32';
print.queryPrinterCapability(printerId).then(() => {
console.log('start query Printer success');
}).catch((error: BusinessError) => {
console.error('failed to query Printer Capability because : ' + JSON.stringify(error));
})
```
## print.startPrintJob
startPrintJob(jobInfo: PrintJob, callback: AsyncCallback<void>): void
Starts the specified print job. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobInfo | [PrintJob](#printjob) | Yes| Information about the print job.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobInfo : print.PrintJob = {
fdList : [44,45],
jobId : 'jobId_12',
printerId : 'printerId_32',
jobState : PRINT_JOB_COMPLETED,
jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS,
copyNumber : 1,
pageRange : {},
isSequential : false,
pageSize : {id : '', name : '', width : 10, height : 20},
isLandscape : false,
colorMode : COLOR_MODE_COLOR,
duplexMode : DUPLEX_MODE_NONE,
margin : undefined,
preview : undefined,
options : undefined
};
print.startPrintJob(jobInfo, (err: BusinessError) => {
if (err) {
console.error('failed to start Print Job because : ' + JSON.stringify(err));
} else {
console.log('start Print Job success');
}
})
```
## print.startPrintJob
startPrintJob(jobInfo: PrintJob): Promise<void>
Starts the specified print job. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobInfo | [PrintJob](#printjob) | Yes| Information about the print job.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobInfo : print.PrintJob = {
fdList : [44,45],
jobId : 'jobId_12',
printerId : 'printerId_32',
jobState : PRINT_JOB_COMPLETED,
jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS,
copyNumber : 1,
pageRange : {},
isSequential : false,
pageSize : {id : '', name : '', width : 10, height : 20},
isLandscape : false,
colorMode : COLOR_MODE_COLOR,
duplexMode : DUPLEX_MODE_NONE,
margin : undefined,
preview : undefined,
options : undefined
};
print.startPrintJob(jobInfo).then(() => {
console.log('start Print success');
}).catch((error: BusinessError) => {
console.error('failed to start Print because : ' + JSON.stringify(error));
})
```
## print.cancelPrintJob
cancelPrintJob(jobId: string, callback: AsyncCallback<void>): void
Cancels the specified print job, which is on the print queue of the printer. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobId | string | Yes| Print job ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobId : string = '121212';
print.cancelPrintJob(jobId, (err: BusinessError) => {
if (err) {
console.error('cancelPrintJob failed, because : ' + JSON.stringify(err));
} else {
console.log('cancelPrintJob success');
}
})
```
## print.cancelPrintJob
cancelPrintJob(jobId: string): Promise<void>
Cancels the specified print job, which is on the print queue of the printer. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobId | string | Yes| Print job ID.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobId : string = '121212';
print.cancelPrintJob(jobId).then(() => {
console.log('cancelPrintJob success');
}).catch((error: BusinessError) => {
console.error('cancelPrintJob failed, because : ' + JSON.stringify(error));
})
```
## print.restartPrintJob20+
restartPrintJob(jobId: string): Promise<void>
Restarts a print job that has been finished before. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobId | string | Yes| ID of a print job that has been finished before.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobId : string = '121212';
print.restartPrintJob(jobId).then(() => {
console.log('restartPrintJob success');
}).catch((error: BusinessError) => {
console.error('restartPrintJob failed, because : ' + JSON.stringify(error));
})
```
## print.requestPrintPreview
requestPrintPreview(jobInfo: PrintJob, callback: Callback<number>): void
Requests print preview data. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobInfo | [PrintJob](#printjob) | Yes| Information about the print job.|
| callback | Callback<number> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
let jobInfo : print.PrintJob = {
fdList : [44,45],
jobId : 'jobId_12',
printerId : 'printerId_32',
jobState : PRINT_JOB_COMPLETED,
jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS,
copyNumber : 1,
pageRange : {},
isSequential : false,
pageSize : {id : '', name : '', width : 10, height : 20},
isLandscape : false,
colorMode : COLOR_MODE_COLOR,
duplexMode : DUPLEX_MODE_NONE,
margin : undefined,
preview : undefined,
options : undefined
};
print.requestPrintPreview(jobInfo, (num : number) => {
console.log('requestPrintPreview success, num : ' + JSON.stringify(num));
})
```
## print.requestPrintPreview
requestPrintPreview(jobInfo: PrintJob): Promise<number>
Requests print preview data. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobInfo | [PrintJob](#printjob) | Yes| Information about the print job.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<number> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobInfo : print.PrintJob = {
fdList : [44,45],
jobId : 'jobId_12',
printerId : 'printerId_32',
jobState : PRINT_JOB_COMPLETED,
jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS,
copyNumber : 1,
pageRange : {},
isSequential : false,
pageSize : {id : '', name : '', width : 10, height : 20},
isLandscape : false,
colorMode : COLOR_MODE_COLOR,
duplexMode : DUPLEX_MODE_NONE,
margin : undefined,
preview : undefined,
options : undefined
};
print.requestPrintPreview(jobInfo).then((num: number) => {
console.log('requestPrintPreview success, num : ' + JSON.stringify(num));
}).catch((error: BusinessError) => {
console.error('requestPrintPreview failed, because : ' + JSON.stringify(error));
})
```
## print.on
on(type: 'printerStateChange', callback: (state: PrinterState, info: PrinterInfo) => void): void
Registers a listener for printer state change events. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | 'printerStateChange' | Yes| Listening type. The value is fixed at **'printerStateChange'**.|
| callback | (state: [PrinterState](./js-apis-print.md#printerstate14), info: [PrinterInfo](#printerinfo)) => void | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
print.on('printerStateChange', (state: print.PrinterState, info: print.PrinterInfo) => {
if (state === null || info === null) {
console.error('printer state changed state is null or info is null');
return;
} else {
console.log('on printer state changed, state : ' + JSON.stringify(state));
console.log('on printer state changed, info : ' + JSON.stringify(info));
}
})
```
## print.off
off(type: 'printerStateChange', callback?: Callback<boolean>): void
Unregisters the listener for printer state change events. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | 'printerStateChange' | Yes| Listening type. The value is fixed at **'printerStateChange'**.|
| callback | Callback<boolean> | No| Callback used to return the result. The value **true** means that the listener for printer state change events is successfully unregistered, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
print.off('printerStateChange', (data: boolean) => {
console.log('off printerStateChange data : ' + JSON.stringify(data));
})
```
## print.on
on(type: 'jobStateChange', callback: (state: PrintJobState, job: PrintJob) => void): void
Registers a listener for print job state change events. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | 'jobStateChange' | Yes| Listening type. The value is fixed at **'jobStateChange'**.|
| callback | (state: [PrintJobState](./js-apis-print.md#printjobstate14), job: [PrintJob](#printjob)) => void | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
print.on('jobStateChange', (state: print.PrintJobState, job: print.PrintJob) => {
console.log('onJobStateChange, state : ' + JSON.stringify(state) + ', job : ' + JSON.stringify(job));
})
```
## print.off
off(type: 'jobStateChange', callback?: Callback<boolean>): void
Unregisters the listener for print job state change events. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | 'jobStateChange' | Yes| Listening type. The value is fixed at **'jobStateChange'**.|
| callback | Callback<boolean> | No| Callback used to return the result. The value **true** means that the listener for print job state change events is successfully unregistered, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
print.off('jobStateChange', (data: boolean) => {
console.log('offJobStateChanged data : ' + JSON.stringify(data));
})
```
## print.on
on(type: 'extInfoChange', callback: (extensionId: string, info: string) => void): void
Registers a listener for printer extension information change events. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | 'extInfoChange' | Yes| Listening type. The value is fixed at **'extInfoChange'**.|
| callback | (extensionId: string, info: string) => void | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
print.on('extInfoChange', (extensionId: string, info: string) => {
console.log('onExtInfoChange, entensionId : ' + JSON.stringify(extensionId) + ', info : ' + JSON.stringify(info));
})
```
## print.off
off(type: 'extInfoChange', callback?: Callback<boolean>): void
Unregisters the listener for printer extension information change events. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | 'extInfoChange' | Yes| Listening type. The value is fixed at **'extInfoChange'**.|
| callback | Callback<boolean> | No| Callback used to return the result. The value **true** means that the listener for printer extension information change events is successfully unregistered, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
print.off('extInfoChange', (data: boolean) => {
console.log('offExtInfoChange data : ' + JSON.stringify(data));
})
```
## print.addPrinters
addPrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void
Adds printers. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printers | Array<[PrinterInfo](#printerinfo)> | Yes| List of printers to add.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerInfo : print.PrinterInfo = {
printerId : '3232',
printerName : 'hhhhh',
printerState : 0,
printerIcon : 12,
description : 'str',
capability : undefined,
options : 'opt'
};
print.addPrinters([printerInfo], (err: BusinessError) => {
if (err) {
console.error('addPrinters failed, because : ' + JSON.stringify(err));
} else {
console.log('addPrinters success');
}
})
```
## print.addPrinters
addPrinters(printers: Array<PrinterInfo>): Promise<void>
Adds printers. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printers | Array<[PrinterInfo](#printerinfo)> | Yes| List of printers to add.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerInfo : print.PrinterInfo = {
printerId : '3232',
printerName : 'hhhhh',
printerState : 0,
printerIcon : 12,
description : 'str',
capability : undefined,
options : 'opt'
};
print.addPrinters([printerInfo]).then(() => {
console.log('add printers success.');
}).catch((error: BusinessError) => {
console.error('add printers error : ' + JSON.stringify(error));
})
```
## print.removePrinters
removePrinters(printerIds: Array<string>, callback: AsyncCallback<void>): void
Removes printers. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerIds | Array<string> | Yes| List of printers to remove.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId : string = '1212';
print.removePrinters([printerId], (err: BusinessError) => {
if (err) {
console.error('removePrinters failed, because : ' + JSON.stringify(err));
} else {
console.log('removePrinters success');
}
})
```
## print.removePrinters
removePrinters(printerIds: Array<string>): Promise<void>
Removes printers. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerIds | Array<string> | Yes| List of printers to remove.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId : string = '1212';
print.removePrinters([printerId]).then(() => {
console.log('remove printers success');
}).catch((error: BusinessError) => {
console.error('remove printers error : ' + JSON.stringify(error));
})
```
## print.updatePrinters
updatePrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void
Updates information about the specified printers. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printers | Array<[PrinterInfo](#printerinfo)> | Yes| List of printers whose information is to be updated.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerInfo : print.PrinterInfo = {
printerId : '3232',
printerName : 'hhhhh',
printerState : 0,
printerIcon : 12,
description : 'str',
capability : undefined,
options : 'opt'
};
print.updatePrinters([printerInfo], (err: BusinessError) => {
if (err) {
console.error('updataPrinters failed, because : ' + JSON.stringify(err));
} else {
console.log('updataPrinters success');
}
})
```
## print.updatePrinters
updatePrinters(printers: Array<PrinterInfo>): Promise<void>
Updates information about the specified printers. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printers | Array<[PrinterInfo](#printerinfo)> | Yes| List of printers whose information is to be updated.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerInfo : print.PrinterInfo = {
printerId : '3232',
printerName : 'hhhhh',
printerState : 0,
printerIcon : 12,
description : 'str',
capability : undefined,
options : 'opt'
};
print.updatePrinters([printerInfo]).then(() => {
console.log('update printers success');
}).catch((error: BusinessError) => {
console.error('update printers error : ' + JSON.stringify(error));
})
```
## print.updatePrinterState
updatePrinterState(printerId: string, state: PrinterState, callback: AsyncCallback<void>): void
Updates the printer state. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerId | string | Yes| Printer ID.|
| state | [PrinterState](./js-apis-print.md#printerstate14) | Yes| Printer state.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId : string = '1212';
let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED;
print.updatePrinterState(printerId, state, (err: BusinessError) => {
if (err) {
console.error('updatePrinterState failed, because : ' + JSON.stringify(err));
} else {
console.log('updatePrinterState success');
}
})
```
## print.updatePrinterState
updatePrinterState(printerId: string, state: PrinterState): Promise<void>
Updates the printer state. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerId | string | Yes| Printer ID.|
| state | [PrinterState](./js-apis-print.md#printerstate14) | Yes| Printer state.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId : string = '1212';
let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED;
print.updatePrinterState(printerId, state).then(() => {
console.log('update printer state success');
}).catch((error: BusinessError) => {
console.error('update printer state error : ' + JSON.stringify(error));
})
```
## print.updatePrintJobState
updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState, callback: AsyncCallback<void>): void
Updates the print job state. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobId | string | Yes| ID of the print job.|
| state | [PrintJobState](./js-apis-print.md#printjobstate14) | Yes| State of the print job.|
| subState | [PrintJobSubState](./js-apis-print.md#printjobsubstate14) | Yes| Substate of the print job.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobId : string = '3434';
let state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE;
let subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS;
print.updatePrintJobState(jobId, state, subState, (err: BusinessError) => {
if (err) {
console.error('updataPrintJobState failed, because : ' + JSON.stringify(err));
} else {
console.log('updatePrintJobState success');
}
})
```
## print.updatePrintJobState
updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState): Promise<void>
Updates the print job state. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobId | string | Yes| ID of the print job.|
| state | [PrintJobState](./js-apis-print.md#printjobstate14) | Yes| State of the print job.|
| subState | [PrintJobSubState](./js-apis-print.md#printjobsubstate14) | Yes| Substate of the print job.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobId : string = '3434';
let state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE;
let subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS;
print.updatePrintJobState(jobId, state, subState).then(() => {
console.log('update print job state success');
}).catch((error: BusinessError) => {
console.error('update print job state error : ' + JSON.stringify(error));
})
```
## print.updateExtensionInfo
updateExtensionInfo(info: string, callback: AsyncCallback<void>): void
Updates the printer extension information. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| info | string | Yes| New printer extension information.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let info : string = 'WIFI_INACTIVE';
print.updateExtensionInfo(info, (err: BusinessError) => {
if (err) {
console.error('updateExtensionInfo failed, because : ' + JSON.stringify(err));
} else {
console.log('updateExtensionInfo success');
}
})
```
## print.updateExtensionInfo
updateExtensionInfo(info: string): Promise<void>
Updates the printer extension information. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| info | string | Yes| New printer extension information.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let info : string = 'WIFI_INACTIVE';
print.updateExtensionInfo(info).then(() => {
console.log('update print job state success');
}).catch((error: BusinessError) => {
console.error('update print job state error : ' + JSON.stringify(error));
})
```
## print.queryAllPrintJobs(deprecated)
> This API is supported since API version 10 and deprecated since API version 11.
> You are advised to use [queryPrintJobList](#printqueryprintjoblist11) instead.
queryAllPrintJobs(callback: AsyncCallback<void>): void
Queries all print jobs. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
print.queryAllPrintJobs((err: BusinessError) => {
if (err) {
console.error('queryAllPrintJobs failed, because : ' + JSON.stringify(err));
} else {
console.log('queryAllPrintJobs success');
}
})
```
## print.queryAllPrintJobs(deprecated)
> This API is supported since API version 10 and deprecated since API version 11.
> You are advised to use [queryPrintJobList](#printqueryprintjoblist11-1) instead.
queryAllPrintJobs(): Promise<void>
Queries all print jobs. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
print.queryAllPrintJobs().then(() => {
console.log('queryAllPrintJobs success');
}).catch((error: BusinessError) => {
console.error('queryAllPrintJobs failed, error : ' + JSON.stringify(error));
})
```
## print.queryAllActivePrintJobList20+
queryAllActivePrintJobList(): Promise<[PrintJob](#printjob)[]>
Queries all active print jobs. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<[PrintJob](#printjob)[]> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
print.queryAllActivePrintJobList().then((printJobs : print.PrintJob[]) => {
console.log('queryPrinqueryAllActivePrintJobListtJobList success, data : ' + JSON.stringify(printJobs));
}).catch((error: BusinessError) => {
console.error('queryAllActivePrintJobList failed, error : ' + JSON.stringify(error));
})
```
## print.queryPrintJobList11+
queryPrintJobList(callback: AsyncCallback<Array<PrintJob>>): void
Queries all print jobs. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<Array<[PrintJob](#printjob)>> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
print.queryPrintJobList((err: BusinessError, printJobs : print.PrintJob[]) => {
if (err) {
console.error('queryPrintJobList failed, because : ' + JSON.stringify(err));
} else {
console.log('queryPrintJobList success, data : ' + JSON.stringify(printJobs));
}
})
```
## print.queryPrintJobList11+
queryPrintJobList(): Promise<Array<PrintJob>>
Queries all print jobs. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<Array<[PrintJob](#printjob)>> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
print.queryPrintJobList().then((printJobs : print.PrintJob[]) => {
console.log('queryPrintJobList success, data : ' + JSON.stringify(printJobs));
}).catch((error: BusinessError) => {
console.error('queryPrintJobList failed, error : ' + JSON.stringify(error));
})
```
## print.queryPrintJobById11+
queryPrintJobById(jobId: string, callback: AsyncCallback<PrintJob>): void
Queries a print job by ID. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobId | string | Yes| ID of the print job.|
| callback | AsyncCallback<[PrintJob](#printjob)> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobId : string = '1';
print.queryPrintJobById(jobId, (err: BusinessError, printJob : print.PrintJob) => {
if (err) {
console.error('queryPrintJobById failed, because : ' + JSON.stringify(err));
} else {
console.log('queryPrintJobById success, data : ' + JSON.stringify(printJob));
}
})
```
## print.queryPrintJobById11+
queryPrintJobById(jobId: string): Promise<PrintJob>
Queries a print job by ID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobId | string | Yes| ID of the print job.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<[PrintJob](#printjob)> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobId : string = '1';
print.queryPrintJobById(jobId).then((printJob : print.PrintJob) => {
console.log('queryPrintJobById data : ' + JSON.stringify(printJob));
}).catch((error: BusinessError) => {
console.error('queryPrintJobById error : ' + JSON.stringify(error));
})
```
## print.startGettingPrintFile11+
startGettingPrintFile(jobId: string, printAttributes: PrintAttributes, fd: number, onFileStateChanged: Callback<PrintFileCreationState>): void
Starts to obtain the print file. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobId | string | Yes| ID of the print job.|
| printAttributes | [PrintAttributes](./js-apis-print.md#printattributes11) | Yes| Print attributes.|
| fd | number | Yes| File descriptor.|
| onFileStateChanged | Callback<[PrintFileCreationState](./js-apis-print.md#printfilecreationstate11)> | Yes| Callback for updating the file state.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobId : string= '1';
class MyPrintAttributes implements print.PrintAttributes {
copyNumber?: number;
pageRange?: print.PrintPageRange;
pageSize?: print.PrintPageSize | print.PrintPageType;
directionMode?: print.PrintDirectionMode;
colorMode?: print.PrintColorMode;
duplexMode?: print.PrintDuplexMode;
}
class MyPrintPageRange implements print.PrintPageRange {
startPage?: number;
endPage?: number;
pages?: Array;
}
class MyPrintPageSize implements print.PrintPageSize {
id: string = '0';
name: string = '0';
width: number = 210;
height: number = 297;
}
let printAttributes = new MyPrintAttributes();
printAttributes.copyNumber = 2;
printAttributes.pageRange = new MyPrintPageRange();
printAttributes.pageRange.pages = [1, 3];
printAttributes.pageSize = print.PrintPageType.PAGE_ISO_A3;
printAttributes.directionMode = print.PrintDirectionMode.DIRECTION_MODE_AUTO;
printAttributes.colorMode = print.PrintColorMode.COLOR_MODE_MONOCHROME;
printAttributes.duplexMode = print.PrintDuplexMode.DUPLEX_MODE_NONE;
let fd : number = 1;
print.startGettingPrintFile(jobId, printAttributes, fd, (state: print.PrintFileCreationState) => {
console.log('onFileStateChanged success, data : ' + JSON.stringify(state));
})
```
## print.notifyPrintService11+
notifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started', callback: AsyncCallback<void>): void
Notifies the print service of the spooler shutdown information. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobId | string | Yes| ID of the print job.|
| type | 'spooler_closed_for_cancelled' \| 'spooler_closed_for_started' | Yes| Spooler shutdown information.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobId : string = '1';
print.notifyPrintService(jobId, 'spooler_closed_for_started', (err: BusinessError) => {
if (err) {
console.error('notifyPrintService failed, because : ' + JSON.stringify(err));
} else {
console.log('notifyPrintService success');
}
})
```
## print.notifyPrintService11+
notifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started'): Promise<void>
Notifies the print service of the spooler shutdown information. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| jobId | string | Yes| ID of the print job.|
| type | 'spooler_closed_for_cancelled' \| 'spooler_closed_for_started' | Yes| Spooler shutdown information.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let jobId : string = '1';
print.notifyPrintService(jobId, 'spooler_closed_for_started').then(() => {
console.log('notifyPrintService success');
}).catch((error: BusinessError) => {
console.error('notifyPrintService error : ' + JSON.stringify(error));
})
```
## print.getPrinterInfoById12+
getPrinterInfoById(printerId: string): Promise<PrinterInfo>
Obtains printer information based on the printer ID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerId | string | Yes| Printer ID.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<[PrinterInfo](#printerinfo)> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId : string = '1';
print.getPrinterInfoById(printerId).then((printerInfo : print.PrinterInfo) => {
console.log('getPrinterInfoById data : ' + JSON.stringify(printerInfo));
}).catch((error: BusinessError) => {
console.error('getPrinterInfoById error : ' + JSON.stringify(error));
})
```
## print.notifyPrintServiceEvent12+
notifyPrintServiceEvent(event: ApplicationEvent): Promise<void>
Notifies the print service of the print application events. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| event | [ApplicationEvent](./js-apis-print.md#applicationevent14) | Yes| Print application events.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let event : print.ApplicationEvent = print.ApplicationEvent.APPLICATION_CREATED;
print.notifyPrintServiceEvent(event).then(() => {
console.log('notifyPrintServiceEvent success');
}).catch((error: BusinessError) => {
console.error('notifyPrintServiceEvent error : ' + JSON.stringify(error));
})
```
## print.updatePrinterInformation18+
updatePrinterInformation(printerInformation: PrinterInformation): Promise<void>
Updates the information of a printer in the system. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerInformation | [PrinterInformation](./js-apis-print.md#printerinformation14) | Yes| Printer whose information is to be updated.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result of updating the printer information to the printer discovery list.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let testPageSize : print.PrintPageSize = {
id : 'ISO_A4',
name : 'iso_a4_210x297mm',
width : 8268,
height : 11692
};
let testCapability : print.PrinterCapabilities = {
supportedPageSizes : [testPageSize],
supportedColorModes : [print.PrintColorMode.COLOR_MODE_MONOCHROME],
supportedDuplexModes : [print.PrintDuplexMode.DUPLEX_MODE_NONE],
supportedMediaTypes : ['stationery'],
supportedQualities : [print.PrintQuality.QUALITY_NORMAL],
supportedOrientations : [print.PrintOrientationMode.ORIENTATION_MODE_PORTRAIT],
options : 'testOptions'
};
let printerInformation : print.PrinterInformation = {
printerId : 'testPrinterId',
printerName : 'testPrinterName',
printerStatus : 0,
description : 'testDesc',
capability : testCapability,
uri : 'testUri',
printerMake : 'testPrinterMake',
options : 'testOptions'
};
print.updatePrinterInformation(printerInformation).then(() => {
console.log('updatePrinterInformation success');
}).catch((error: BusinessError) => {
console.error('updatePrinterInformation error : ' + JSON.stringify(error));
})
```
## print.setPrinterPreferences18+
setPrinterPreferences(printerId: string, printerPreferences: PrinterPreferences): Promise<void>
Sets the printer preferences. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerId | string | Yes| Printer ID.|
| printerPreferences | [PrinterPreferences](./js-apis-print.md#printerpreferences18) | Yes| Printer preferences.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result of setting printer preferences.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId : string = 'testPrinterId';
let preferences : print.PrinterPreferences = {
defaultDuplexMode: print.PrintDuplexMode.DUPLEX_MODE_NONE
};
print.setPrinterPreferences(printerId, preferences).then(() => {
console.log('setPrinterPreferences success');
}).catch((error: BusinessError) => {
console.error('setPrinterPreferences error : ' + JSON.stringify(error));
})
```
## print.discoverUsbPrinters18+
discoverUsbPrinters(): Promise<Array<PrinterInformation>>
Discovers USB printers. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<Array<[PrinterInformation](./js-apis-print.md#printerinformation14)>> | Promise used to return the discovered USB printer list.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
print.discoverUsbPrinters().then((printers : print.PrinterInformation[]) => {
console.log('discoverUsbPrinters data : ' + JSON.stringify(printers));
}).catch((error: BusinessError) => {
console.error('discoverUsbPrinters error : ' + JSON.stringify(error));
})
```
## print.setDefaultPrinter18+
setDefaultPrinter(printerId: string, type: DefaultPrinterType): Promise<void>
Sets the default printer. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| printerId | string | Yes| Printer ID.|
| type | [DefaultPrinterType](./js-apis-print.md#defaultprintertype18) | Yes| Default printer type.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result of setting the default printer.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let printerId : string = '1';
let type : print.DefaultPrinterType = print.DefaultPrinterType.DEFAULT_PRINTER_TYPE_SET_BY_USER;
print.setDefaultPrinter(printerId, type).then(() => {
console.log('setDefaultPrinter success');
}).catch((error: BusinessError) => {
console.error('setDefaultPrinter error : ' + JSON.stringify(error));
})
```
## print.notifyPrintServiceEvent18+
notifyPrintServiceEvent(event: ApplicationEvent, jobId: string): Promise<void>
Notifies the print service of the print application events. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
**System API**: This is a system API.
**System capability**: SystemCapability.Print.PrintFramework
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| event | [ApplicationEvent](./js-apis-print.md#applicationevent14) | Yes| Print application events.|
| jobId | string | Yes| ID of the print job.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
**Example**
```ts
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@ohos.base';
let event : print.ApplicationEvent = print.ApplicationEvent.APPLICATION_CREATED;
let jobId : string = '1';
print.notifyPrintServiceEvent(event, jobId).then(() => {
console.log('notifyPrintServiceEvent success');
}).catch((error: BusinessError) => {
console.error('notifyPrintServiceEvent error : ' + JSON.stringify(error));
})
```