@ohos.print (打印)(系统接口)
该模块为基本打印的操作API,提供调用基础打印功能的接口。
说明:
本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 当前界面仅包含本模块的系统接口,其他公开接口参见@ohos.print (打印)。
导入模块
import { print } from '@kit.BasicServicesKit';
PrintMargin
定义打印页边距的接口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
属性:
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| top | number | 否 | 是 | 表示页面上边距。默认值为0。 |
| bottom | number | 否 | 是 | 表示页面下边距。默认值为0。 |
| left | number | 否 | 是 | 表示页面左边距。默认值为0。 |
| right | number | 否 | 是 | 表示页面右边距。默认值为0。 |
PrinterRange
定义打印范围的接口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
属性:
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| startPage | number | 否 | 是 | 表示起始页。默认值为1。 |
| endPage | number | 否 | 是 | 表示结束页。默认值为待打印文件的最大页数。 |
| pages | Array<number> | 否 | 是 | 表示待打印的页面范围的集合。默认值为空。 |
PreviewAttribute
定义打印预览属性的接口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
属性:
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| previewRange | PrinterRange | 否 | 否 | 表示预览页面范围。 |
| result | number | 否 | 是 | 表示预览文件结果。默认值为-1。 |
PrintResolution
定义打印分辨率的接口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
属性:
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| id | string | 否 | 否 | 表示分辨率ID。 |
| horizontalDpi | number | 否 | 否 | 表示水平DPI。 |
| verticalDpi | number | 否 | 否 | 表示垂直DPI。 |
PrinterCapability
定义打印能力的接口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
属性:
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| colorMode | number | 否 | 否 | 表示色彩模式。 |
| duplexMode | number | 否 | 否 | 表示单双面打印模式。 |
| pageSize | Array<PrintPageSize> | 否 | 否 | 表示打印机支持的页面尺寸列表。 |
| resolution | Array<PrintResolution> | 否 | 是 | 表示打印机支持的分辨率列表。 |
| minMargin | PrintMargin | 否 | 是 | 表示打印机最小边距。 |
| options11+ | Object | 否 | 是 | 表示JSON对象字符串。 |
PrinterInfo
定义打印信息的接口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
属性:
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| printerId | string | 否 | 否 | 表示打印机ID。 |
| printerName | string | 否 | 否 | 表示打印机名称。 |
| printerState | PrinterState | 否 | 否 | 表示当前打印机状态。 |
| printerIcon | number | 否 | 是 | 表示打印机图标的资源ID。默认值为-1。 |
| description | string | 否 | 是 | 表示打印机说明。 |
| capability | PrinterCapability | 否 | 是 | 表示打印机功能。 |
| options | Object | 否 | 是 | 表示JSON对象字符串。 |
PrintJob
定义打印任务的接口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
属性:
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| fdList | Array<number> | 否 | 否 | 表示待打印文件fd列表。 |
| jobId | string | 否 | 否 | 表示打印任务ID。 |
| printerId | string | 否 | 否 | 表示负责打印的打印机ID。 |
| jobState | PrintJobState | 否 | 否 | 表示当前打印任务状态。 |
| jobSubstate11+ | PrintJobSubState | 否 | 否 | 表示当前打印任务子状态。 |
| copyNumber | number | 否 | 否 | 表示文件列表副本。 |
| pageRange | PrinterRange | 否 | 否 | 表示打印范围大小。 |
| isSequential | boolean | 否 | 否 | 表示是否连续打印。true表示连续打印,false表示不连续打印。默认值为false。 |
| pageSize | PrintPageSize | 否 | 否 | 表示选定的页面尺寸。 |
| isLandscape | boolean | 否 | 否 | 表示是否横向打印。true表示横向打印,false表示纵向打印。默认值为false。 |
| colorMode | number | 否 | 否 | 表示色彩模式。 |
| duplexMode | number | 否 | 否 | 表示单双面打印模式。 |
| margin | PrintMargin | 否 | 是 | 表示当前页边距设置。 |
| preview | PreviewAttribute | 否 | 是 | 表示预览设置。 |
| options | Object | 否 | 是 | 表示JSON对象字符串。 |
PrinterExtensionInfo
定义打印扩展信息的接口。
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
属性:
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| extensionId | string | 否 | 否 | 表示打印机扩展的扩展ID。 |
| vendorId | string | 否 | 否 | 表示扩展的供应商ID。 |
| vendorName | string | 否 | 否 | 表示供应商名称。 |
| vendorIcon | number | 否 | 否 | 表示供应商图标。 |
| version | string | 否 | 否 | 表示当前打印机扩展的版本。 |
print.queryAllPrinterExtensionInfos
queryAllPrinterExtensionInfos(callback: AsyncCallback<Array<PrinterExtensionInfo>>): void
查询所有已安装的打印机扩展服务,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| callback | AsyncCallback<Array<PrinterExtensionInfo>> | 是 | 异步查询所有已安装的打印机扩展服务之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
print.queryAllPrinterExtensionInfos((err: BusinessError, extensionInfos: print.PrinterExtensionInfo[]) => {
if (err) {
console.error('queryAllPrinterExtensionInfos err ' + JSON.stringify(err));
} else {
console.info('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos));
}
})
print.queryAllPrinterExtensionInfos
queryAllPrinterExtensionInfos(): Promise<Array<PrinterExtensionInfo>>
查询所有已安装的打印机扩展服务,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
返回值:
| 类型 | 说明 |
|---|---|
| Promise<Array<PrinterExtensionInfo>> | 查询所有已安装的打印机扩展服务完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
print.queryAllPrinterExtensionInfos().then((extensionInfos: print.PrinterExtensionInfo[]) => {
console.info('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
断开特定打印机的连接,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerId | string | 是 | 打印机ID。 |
| callback | AsyncCallback<void> | 是 | 异步断开特定打印机的连接之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerId: string = 'printerId_32';
print.disconnectPrinter(printerId, (err: BusinessError) => {
if (err) {
console.error('failed to disconnect Printer because : ' + JSON.stringify(err));
} else {
console.info('start disconnect Printer success');
}
})
print.disconnectPrinter
disconnectPrinter(printerId: string): Promise<void>
断开特定打印机的连接,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerId | string | 是 | 打印机ID。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 断开特定打印机的连接完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerId: string = 'printerId_32';
print.disconnectPrinter(printerId).then(() => {
console.info('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
查询打印机能力,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerId | string | 是 | 打印机ID。 |
| callback | AsyncCallback<void> | 是 | 异步查询打印机能力之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
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.info('start query Printer Capability success');
}
})
print.queryPrinterCapability
queryPrinterCapability(printerId: string): Promise<void>
查询打印机能力,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerId | string | 是 | 打印机ID。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 查询打印机能力完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerId: string = 'printerId_32';
print.queryPrinterCapability(printerId).then(() => {
console.info('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
开始打印任务,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobInfo | PrintJob | 是 | 打印任务信息。 |
| callback | AsyncCallback<void> | 是 | 异步开始打印任务之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let jobInfo : print.PrintJob = {
fdList : [44,45],
jobId : 'jobId_12',
printerId : 'printerId_32',
jobState : print.PrintJobState.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 : print.PrintColorMode.COLOR_MODE_COLOR,
duplexMode : print.PrintDuplexMode.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.info('start Print Job success');
}
})
print.startPrintJob
startPrintJob(jobInfo: PrintJob): Promise<void>
开始打印任务,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobInfo | PrintJob | 是 | 打印任务信息。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 开始打印任务完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let jobInfo : print.PrintJob = {
fdList : [44,45],
jobId : 'jobId_12',
printerId : 'printerId_32',
jobState : print.PrintJobState.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 : print.PrintColorMode.COLOR_MODE_COLOR,
duplexMode : print.PrintDuplexMode.DUPLEX_MODE_NONE,
margin : undefined,
preview : undefined,
options : undefined
};
print.startPrintJob(jobInfo).then(() => {
console.info('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
取消已发送到打印机的打印任务,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobId | string | 是 | 打印任务ID。 |
| callback | AsyncCallback<void> | 是 | 异步取消已发送到打印机的打印任务之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let jobId : string = '121212';
print.cancelPrintJob(jobId, (err: BusinessError) => {
if (err) {
console.error('cancelPrintJob failed, because : ' + JSON.stringify(err));
} else {
console.info('cancelPrintJob success');
}
})
print.cancelPrintJob
cancelPrintJob(jobId: string): Promise<void>
取消已发送到打印机的打印任务,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobId | string | 是 | 打印任务ID。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 取消已发送到打印机的打印任务完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let jobId : string = '121212';
print.cancelPrintJob(jobId).then(() => {
console.info('cancelPrintJob success');
}).catch((error: BusinessError) => {
console.error('cancelPrintJob failed, because : ' + JSON.stringify(error));
})
print.restartPrintJob20+
restartPrintJob(jobId: string): Promise<void>
重新打印之前打印过的打印任务,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobId | string | 是 | 之前打印过的打印任务ID。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 重新开始打印任务的结果的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let jobId : string = '121212';
print.restartPrintJob(jobId).then(() => {
console.info('restartPrintJob success');
}).catch((error: BusinessError) => {
console.error('restartPrintJob failed, because : ' + JSON.stringify(error));
})
print.requestPrintPreview
requestPrintPreview(jobInfo: PrintJob, callback: Callback<number>): void
请求预览打印数据,使用callback回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobInfo | PrintJob | 是 | 打印任务信息。 |
| callback | Callback<number> | 是 | 请求预览打印数据之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
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.info('requestPrintPreview success, num : ' + JSON.stringify(num));
})
print.requestPrintPreview
requestPrintPreview(jobInfo: PrintJob): Promise<number>
请求预览打印数据,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobInfo | PrintJob | 是 | 打印任务信息。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<number> | 请求预览打印数据完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } 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).then((num: number) => {
console.info('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
注册打印机状态变化事件回调,使用callback回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'printerStateChange' | 是 | 表示打印机状态改变。 |
| callback | (state: PrinterState, info: PrinterInfo) => void | 是 | 打印机状态改变之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
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.info('on printer state changed, state : ' + JSON.stringify(state));
console.info('on printer state changed, info : ' + JSON.stringify(info));
}
})
print.off
off(type: 'printerStateChange', callback?: Callback<boolean>): void
取消注册打印机状态变化事件回调,使用callback回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'printerStateChange' | 是 | 表示打印机状态改变。 |
| callback | Callback<boolean> | 否 | 表示取消注册打印机状态变化事件是否成功。true表示成功,false表示失败。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
print.off('printerStateChange', (data: boolean) => {
console.info('off printerStateChange data : ' + JSON.stringify(data));
})
print.on
on(type: 'jobStateChange', callback: (state: PrintJobState, job: PrintJob) => void): void
注册打印任务状态变化事件回调,使用callback回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'jobStateChange' | 是 | 表示打印任务状态改变。 |
| callback | (state: PrintJobState, job: PrintJob) => void | 是 | 打印任务状态改变之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
print.on('jobStateChange', (state: print.PrintJobState, job: print.PrintJob) => {
console.info('onJobStateChange, state : ' + JSON.stringify(state) + ', job : ' + JSON.stringify(job));
})
print.off
off(type: 'jobStateChange', callback?: Callback<boolean>): void
取消注册打印任务状态变化事件回调,使用callback回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'jobStateChange' | 是 | 表示打印任务状态改变。 |
| callback | Callback<boolean> | 否 | 表示取消注册打印任务状态变化事件是否成功。true表示成功,false表示失败。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
print.off('jobStateChange', (data: boolean) => {
console.info('offJobStateChanged data : ' + JSON.stringify(data));
})
print.on
on(type: 'extInfoChange', callback: (extensionId: string, info: string) => void): void
注册打印扩展信息变化事件回调,使用callback回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'extInfoChange' | 是 | 表示打印扩展信息改变。 |
| callback | (extensionId: string, info: string) => void | 是 | 打印扩展信息改变之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
print.on('extInfoChange', (extensionId: string, info: string) => {
console.info('onExtInfoChange, extensionId : ' + JSON.stringify(extensionId) + ', info : ' + JSON.stringify(info));
})
print.off
off(type: 'extInfoChange', callback?: Callback<boolean>): void
取消注册打印扩展信息变化事件回调,使用callback回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| type | 'extInfoChange' | 是 | 表示打印扩展信息改变。 |
| callback | Callback<boolean> | 否 | 表示取消注册打印扩展信息变化事件是否成功。true表示成功,false表示失败。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
print.off('extInfoChange', (data: boolean) => {
console.info('offExtInfoChange data : ' + JSON.stringify(data));
})
print.addPrinters
addPrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void
添加打印机,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printers | Array<PrinterInfo> | 是 | 表示新到达的打印机列表。 |
| callback | AsyncCallback<void> | 是 | 异步添加打印机之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
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.info('addPrinters success');
}
})
print.addPrinters
addPrinters(printers: Array<PrinterInfo>): Promise<void>
添加打印机,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printers | Array<PrinterInfo> | 是 | 表示新到达的打印机列表。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 添加打印机完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerInfo : print.PrinterInfo = {
printerId : '3232',
printerName : 'hhhhh',
printerState : 0,
printerIcon : 12,
description : 'str',
capability : undefined,
options : 'opt'
};
print.addPrinters([printerInfo]).then(() => {
console.info('add printers success.');
}).catch((error: BusinessError) => {
console.error('add printers error : ' + JSON.stringify(error));
})
print.removePrinters
removePrinters(printerIds: Array<string>, callback: AsyncCallback<void>): void
移除打印机,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerIds | Array<string> | 是 | 表示需移除的打印机列表。 |
| callback | AsyncCallback<void> | 是 | 异步移除打印机之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerId : string = '1212';
print.removePrinters([printerId], (err: BusinessError) => {
if (err) {
console.error('removePrinters failed, because : ' + JSON.stringify(err));
} else {
console.info('removePrinters success');
}
})
print.removePrinters
removePrinters(printerIds: Array<string>): Promise<void>
移除打印机,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerIds | Array<string> | 是 | 表示需移除的打印机列表。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 移除打印机完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerId : string = '1212';
print.removePrinters([printerId]).then(() => {
console.info('remove printers success');
}).catch((error: BusinessError) => {
console.error('remove printers error : ' + JSON.stringify(error));
})
print.updatePrinters
updatePrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void
更新特定打印机的信息,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printers | Array<PrinterInfo> | 是 | 表示待更新的打印机列表。 |
| callback | AsyncCallback<void> | 是 | 异步更新打印机信息之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
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.info('updataPrinters success');
}
})
print.updatePrinters
updatePrinters(printers: Array<PrinterInfo>): Promise<void>
更新特定打印机的信息,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printers | Array<PrinterInfo> | 是 | 表示待更新的打印机列表。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 更新打印机完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerInfo : print.PrinterInfo = {
printerId : '3232',
printerName : 'hhhhh',
printerState : 0,
printerIcon : 12,
description : 'str',
capability : undefined,
options : 'opt'
};
print.updatePrinters([printerInfo]).then(() => {
console.info('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
更新打印机状态,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerId | string | 是 | 表示打印机ID。 |
| state | PrinterState | 是 | 表示打印机状态。 |
| callback | AsyncCallback<void> | 是 | 异步更新打印机状态之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
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.info('updatePrinterState success');
}
})
print.updatePrinterState
updatePrinterState(printerId: string, state: PrinterState): Promise<void>
更新打印机状态,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerId | string | 是 | 表示打印机ID。 |
| state | PrinterState | 是 | 表示打印机状态。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 更新打印机状态完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerId : string = '1212';
let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED;
print.updatePrinterState(printerId, state).then(() => {
console.info('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
更新打印任务状态,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobId | string | 是 | 表示打印任务ID。 |
| state | PrintJobState | 是 | 表示打印任务状态。 |
| subState | PrintJobSubState | 是 | 表示打印任务子状态。 |
| callback | AsyncCallback<void> | 是 | 异步更新打印任务状态之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
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.info('updatePrintJobState success');
}
})
print.updatePrintJobState
updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState): Promise<void>
更新打印任务状态,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobId | string | 是 | 表示打印任务ID。 |
| state | PrintJobState | 是 | 表示打印任务状态。 |
| subState | PrintJobSubState | 是 | 表示打印任务子状态。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 更新打印任务状态完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
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.info('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
更新打印扩展状态,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| info | string | 是 | 表示打印扩展变更信息。 |
| callback | AsyncCallback<void> | 是 | 异步更新打印扩展状态之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let info : string = 'WIFI_INACTIVE';
print.updateExtensionInfo(info, (err: BusinessError) => {
if (err) {
console.error('updateExtensionInfo failed, because : ' + JSON.stringify(err));
} else {
console.info('updateExtensionInfo success');
}
})
print.updateExtensionInfo
updateExtensionInfo(info: string): Promise<void>
更新打印扩展状态,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| info | string | 是 | 表示打印扩展变更信息。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 更新打印扩展状态完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let info : string = 'WIFI_INACTIVE';
print.updateExtensionInfo(info).then(() => {
console.info('update print job state success');
}).catch((error: BusinessError) => {
console.error('update print job state error : ' + JSON.stringify(error));
})
print.queryAllPrintJobs(deprecated)
从API version 10开始支持,从API version 11开始废弃。 建议使用queryPrintJobList替代。
queryAllPrintJobs(callback: AsyncCallback<void>): void
查询所有打印任务,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| callback | AsyncCallback<void> | 是 | 异步查询所有打印任务之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
print.queryAllPrintJobs((err: BusinessError) => {
if (err) {
console.error('queryAllPrintJobs failed, because : ' + JSON.stringify(err));
} else {
console.info('queryAllPrintJobs success');
}
})
print.queryAllPrintJobs(deprecated)
从API version 10开始支持,从API version 11开始废弃。 建议使用queryPrintJobList替代。
queryAllPrintJobs(): Promise<void>
查询所有打印任务,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 查询所有打印任务完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
print.queryAllPrintJobs().then(() => {
console.info('queryAllPrintJobs success');
}).catch((error: BusinessError) => {
console.error('queryAllPrintJobs failed, error : ' + JSON.stringify(error));
})
print.queryAllActivePrintJobs20+
queryAllActivePrintJobs(): Promise<PrintJob[]>
查询所有活跃中的打印任务,使用Promise进行异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
返回值:
| 类型 | 说明 |
|---|---|
| Promise<PrintJob[]> | 包含所有活跃打印任务的列表的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
print.queryAllActivePrintJobs().then((printJobs : print.PrintJob[]) => {
console.info('queryAllActivePrintJobs success, data : ' + JSON.stringify(printJobs));
}).catch((error: BusinessError) => {
console.error('queryAllActivePrintJobs failed, error : ' + JSON.stringify(error));
})
print.queryPrintJobList11+
queryPrintJobList(callback: AsyncCallback<Array<PrintJob>>): void
查询所有打印任务,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| callback | AsyncCallback<Array<PrintJob>> | 是 | 异步查询所有打印任务之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
print.queryPrintJobList((err: BusinessError, printJobs : print.PrintJob[]) => {
if (err) {
console.error('queryPrintJobList failed, because : ' + JSON.stringify(err));
} else {
console.info('queryPrintJobList success, data : ' + JSON.stringify(printJobs));
}
})
print.queryPrintJobList11+
queryPrintJobList(): Promise<Array<PrintJob>>
查询所有打印任务,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
返回值:
| 类型 | 说明 |
|---|---|
| Promise<Array<PrintJob>> | 查询所有打印任务完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
print.queryPrintJobList().then((printJobs : print.PrintJob[]) => {
console.info('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
按打印任务ID查询打印任务,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobId | string | 是 | 表示打印任务ID。 |
| callback | AsyncCallback<PrintJob> | 是 | 异步按打印任务ID查询打印任务之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let jobId : string = '1';
print.queryPrintJobById(jobId, (err: BusinessError, printJob : print.PrintJob) => {
if (err) {
console.error('queryPrintJobById failed, because : ' + JSON.stringify(err));
} else {
console.info('queryPrintJobById success, data : ' + JSON.stringify(printJob));
}
})
print.queryPrintJobById11+
queryPrintJobById(jobId: string): Promise<PrintJob>
按打印任务ID查询打印任务,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobId | string | 是 | 表示打印任务ID。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<PrintJob> | 按打印任务ID查询打印任务完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let jobId : string = '1';
print.queryPrintJobById(jobId).then((printJob : print.PrintJob) => {
console.info('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
开始获取打印文件,使用Callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobId | string | 是 | 表示打印任务ID。 |
| printAttributes | PrintAttributes | 是 | 表示打印参数。 |
| fd | number | 是 | 表示打印文件描述符。 |
| onFileStateChanged | Callback<PrintFileCreationState> | 是 | 表示更新文件状态的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
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<number>;
}
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.info('onFileStateChanged success, data : ' + JSON.stringify(state));
})
print.notifyPrintService11+
notifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started', callback: AsyncCallback<void>): void
将spooler关闭信息通知打印服务,使用callback异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobId | string | 是 | 表示打印任务ID。 |
| type | 'spooler_closed_for_cancelled' | 'spooler_closed_for_started' | 是 | 表示spooler关闭信息。 |
| callback | AsyncCallback<void> | 是 | 异步将spooler关闭信息通知打印服务之后的回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
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.info('notifyPrintService success');
}
})
print.notifyPrintService11+
notifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started'): Promise<void>
将spooler关闭信息通知打印服务,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| jobId | string | 是 | 表示打印任务ID。 |
| type | 'spooler_closed_for_cancelled' | 'spooler_closed_for_started' | 是 | 表示spooler关闭信息。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 将spooler关闭信息通知打印服务后的完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let jobId : string = '1';
print.notifyPrintService(jobId, 'spooler_closed_for_started').then(() => {
console.info('notifyPrintService success');
}).catch((error: BusinessError) => {
console.error('notifyPrintService error : ' + JSON.stringify(error));
})
print.getPrinterInfoById12+
getPrinterInfoById(printerId: string): Promise<PrinterInfo>
根据打印机id获取打印机信息,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerId | string | 是 | 表示打印机ID。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<PrinterInfo> | 根据打印机id获取打印机信息后的完成结果回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerId : string = '1';
print.getPrinterInfoById(printerId).then((printerInfo : print.PrinterInfo) => {
console.info('getPrinterInfoById data : ' + JSON.stringify(printerInfo));
}).catch((error: BusinessError) => {
console.error('getPrinterInfoById error : ' + JSON.stringify(error));
})
print.notifyPrintServiceEvent12+
notifyPrintServiceEvent(event: ApplicationEvent): Promise<void>
将打印应用相关事件通知打印服务,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event | ApplicationEvent | 是 | 表示打印应用事件。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 将打印应用相关事件通知打印服务后的完成结果回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let event : print.ApplicationEvent = print.ApplicationEvent.APPLICATION_CREATED;
print.notifyPrintServiceEvent(event).then(() => {
console.info('notifyPrintServiceEvent success');
}).catch((error: BusinessError) => {
console.error('notifyPrintServiceEvent error : ' + JSON.stringify(error));
})
print.updatePrinterInformation18+
updatePrinterInformation(printerInformation: PrinterInformation): Promise<void>
更新系统中打印机的部分信息,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerInformation | PrinterInformation | 是 | 表示待更新信息的打印机。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 更新打印机信息到系统打印机发现列表完成结果。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
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.info('updatePrinterInformation success');
}).catch((error: BusinessError) => {
console.error('updatePrinterInformation error : ' + JSON.stringify(error));
})
print.setPrinterPreferences18+
setPrinterPreferences(printerId: string, printerPreferences: PrinterPreferences): Promise<void>
设置打印机首选项,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerId | string | 是 | 表示打印机ID。 |
| printerPreferences | PrinterPreferences | 是 | 表示打印机首选项。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 设置打印机首选项后的完成结果回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerId : string = 'testPrinterId';
let preferences : print.PrinterPreferences = {
defaultDuplexMode: print.PrintDuplexMode.DUPLEX_MODE_NONE
};
print.setPrinterPreferences(printerId, preferences).then(() => {
console.info('setPrinterPreferences success');
}).catch((error: BusinessError) => {
console.error('setPrinterPreferences error : ' + JSON.stringify(error));
})
print.discoverUsbPrinters18+
discoverUsbPrinters(): Promise<Array<PrinterInformation>>
发现usb打印机,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
返回值:
| 类型 | 说明 |
|---|---|
| Promise<Array<PrinterInformation>> | 发现的usb打印机列表。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | the application does not have permission to call this function. |
| 202 | not system application |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
print.discoverUsbPrinters().then((printers : print.PrinterInformation[]) => {
console.info('discoverUsbPrinters data : ' + JSON.stringify(printers));
}).catch((error: BusinessError) => {
console.error('discoverUsbPrinters error : ' + JSON.stringify(error));
})
print.setDefaultPrinter18+
setDefaultPrinter(printerId: string, type: DefaultPrinterType): Promise<void>
设置默认打印机,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| printerId | string | 是 | 表示打印机ID。 |
| type | DefaultPrinterType | 是 | 表示默认打印机类型。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 设置默认打印机后的完成结果回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let printerId : string = '1';
let type : print.DefaultPrinterType = print.DefaultPrinterType.DEFAULT_PRINTER_TYPE_SET_BY_USER;
print.setDefaultPrinter(printerId, type).then(() => {
console.info('setDefaultPrinter success');
}).catch((error: BusinessError) => {
console.error('setDefaultPrinter error : ' + JSON.stringify(error));
})
print.notifyPrintServiceEvent18+
notifyPrintServiceEvent(event: ApplicationEvent, jobId: string): Promise<void>
将打印应用相关事件通知打印服务,使用Promise异步回调。
需要权限: ohos.permission.MANAGE_PRINT_JOB
系统接口: 此接口为系统接口。
系统能力: SystemCapability.Print.PrintFramework
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event | ApplicationEvent | 是 | 表示打印应用事件。 |
| jobId | string | 是 | 表示打印任务ID。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | 将打印应用相关事件通知打印服务后的完成结果回调。 |
错误码:
以下错误码的详细介绍请参见打印服务错误码。
| 错误码ID | 错误信息 |
|---|---|
| 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. |
示例:
import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';
let event : print.ApplicationEvent = print.ApplicationEvent.APPLICATION_CREATED;
let jobId : string = '1';
print.notifyPrintServiceEvent(event, jobId).then(() => {
console.info('notifyPrintServiceEvent success');
}).catch((error: BusinessError) => {
console.error('notifyPrintServiceEvent error : ' + JSON.stringify(error));
})