1e41f4b71Sopenharmony_ci# @ohos.print (打印)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci该模块为基本打印的操作API,提供调用基础打印功能的接口。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 7e41f4b71Sopenharmony_ci> 当前界面仅包含本模块的系统接口,其他公开接口参见[@ohos.print (打印)](./js-apis-print-sys.md)。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## 导入模块 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## PrintMargin 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci定义打印页边距的接口。 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**属性:** 25e41f4b71Sopenharmony_ci| **名称** | **类型** | **必填** | **说明** | 26e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 27e41f4b71Sopenharmony_ci| top | number | 否 | 表示页面上边距 | 28e41f4b71Sopenharmony_ci| bottom | number | 否 | 表示页面下边距 | 29e41f4b71Sopenharmony_ci| left | number | 否 | 表示页面左边距 | 30e41f4b71Sopenharmony_ci| right | number | 否 | 表示页面右边距 | 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci## PrinterRange 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci定义打印范围的接口。 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**属性:** 41e41f4b71Sopenharmony_ci| **名称** | **类型** | **必填** | **说明** | 42e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 43e41f4b71Sopenharmony_ci| startPage | number | 否 | 表示起始页 | 44e41f4b71Sopenharmony_ci| endPage | number | 否 | 表示结束页 | 45e41f4b71Sopenharmony_ci| pages | Array<number> | 否 | 表示离散页面 | 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci## PreviewAttribute 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci定义打印预览属性的接口。 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci**属性:** 56e41f4b71Sopenharmony_ci| **名称** | **类型** | **必填** | **说明** | 57e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 58e41f4b71Sopenharmony_ci| previewRange | PrinterRange | 是 | 表示预览页面范围 | 59e41f4b71Sopenharmony_ci| result | number | 否 | 表示预览文件结果 | 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci## PrintResolution 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci定义打印分辨率的接口。 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci**属性:** 70e41f4b71Sopenharmony_ci| **名称** | **类型** | **必填** | **说明** | 71e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 72e41f4b71Sopenharmony_ci| id | string | 是 | 表示分辨率ID | 73e41f4b71Sopenharmony_ci| horizontalDpi | number | 是 | 表示水平DPI | 74e41f4b71Sopenharmony_ci| verticalDpi | number | 是 | 表示垂直DPI | 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci## PrinterCapability 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci定义打印能力的接口。 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**属性:** 87e41f4b71Sopenharmony_ci| **名称** | **类型** | **必填** | **说明** | 88e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 89e41f4b71Sopenharmony_ci| colorMode | number | 是 | 表示色彩模式 | 90e41f4b71Sopenharmony_ci| duplexMode | number | 是 | 表示单双面打印模式 | 91e41f4b71Sopenharmony_ci| pageSize | Array<PrintPageSize> | 是 | 表示打印机支持的页面尺寸列表 | 92e41f4b71Sopenharmony_ci| resolution | Array<PrintResolution> | 否 | 表示打印机支持的分辨率列表 | 93e41f4b71Sopenharmony_ci| minMargin | PrintMargin | 否 | 表示打印机最小边距 | 94e41f4b71Sopenharmony_ci| options<sup>11+</sup> | Object | 否 | 表示JSON对象字符串 | 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci## PrinterInfo 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci定义打印信息的接口。 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci**属性:** 105e41f4b71Sopenharmony_ci| **名称** | **类型** | **必填** | **说明** | 106e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 107e41f4b71Sopenharmony_ci| printerId | string | 是 | 表示打印机ID | 108e41f4b71Sopenharmony_ci| printerName | string | 是 | 表示打印机名称 | 109e41f4b71Sopenharmony_ci| printerState | PrinterState | 是 | 表示当前打印机状态 | 110e41f4b71Sopenharmony_ci| printerIcon | number | 否 | 表示打印机图标的资源ID | 111e41f4b71Sopenharmony_ci| description | string | 否 | 表示打印机说明 | 112e41f4b71Sopenharmony_ci| capability | PrinterCapability | 否 | 表示打印机功能 | 113e41f4b71Sopenharmony_ci| options | Object | 否 | 表示JSON对象字符串 | 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci## PrintJob 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci定义打印任务的接口。 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci**属性:** 124e41f4b71Sopenharmony_ci| **名称** | **类型** | **必填** | **说明** | 125e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 126e41f4b71Sopenharmony_ci| fdList | Array<number> | 是 | 表示待打印文件fd列表 | 127e41f4b71Sopenharmony_ci| jobId | string | 是 | 表示打印任务ID | 128e41f4b71Sopenharmony_ci| printerId | string | 是 | 表示负责打印的打印机ID | 129e41f4b71Sopenharmony_ci| jobState | PrintJobState | 是 | 表示当前打印任务状态 | 130e41f4b71Sopenharmony_ci| jobSubstate<sup>11+</sup> | PrintJobSubState | 是 | 表示当前打印任务子状态 | 131e41f4b71Sopenharmony_ci| copyNumber | number | 是 | 表示文件列表副本 | 132e41f4b71Sopenharmony_ci| pageRange | PrinterRange | 是 | 表示打印范围大小 | 133e41f4b71Sopenharmony_ci| isSequential | boolean | 是 | 表示连续打印 | 134e41f4b71Sopenharmony_ci| pageSize | PrintPageSize | 是 | 表示选定的页面尺寸 | 135e41f4b71Sopenharmony_ci| isLandscape | boolean | 是 | 表示垂直打印 | 136e41f4b71Sopenharmony_ci| colorMode | number | 是 | 表示色彩模式 | 137e41f4b71Sopenharmony_ci| duplexMode | number | 是 | 表示单双面打印模式 | 138e41f4b71Sopenharmony_ci| margin | PrintMargin | 否 | 表示当前页边距设置 | 139e41f4b71Sopenharmony_ci| preview | PreviewAttribute | 否 | 表示预览设置 | 140e41f4b71Sopenharmony_ci| options | Object | 否 | 表示JSON对象字符串 | 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci## PrinterState 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci打印机状态的枚举。 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci| **名称** | **值** | **说明** | 152e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 153e41f4b71Sopenharmony_ci| PRINTER_ADDED | 0 | 表示新打印机到达 | 154e41f4b71Sopenharmony_ci| PRINTER_REMOVED | 1 | 表示打印机丢失 | 155e41f4b71Sopenharmony_ci| PRINTER_CAPABILITY_UPDATED | 2 | 表示打印机更新 | 156e41f4b71Sopenharmony_ci| PRINTER_CONNECTED | 3 | 表示打印机已连接 | 157e41f4b71Sopenharmony_ci| PRINTER_DISCONNECTED | 4 | 表示打印机已断开连接 | 158e41f4b71Sopenharmony_ci| PRINTER_RUNNING | 5 | 表示打印机正在运行 | 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci## PrintJobState 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci打印任务状态的枚举。 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci| **名称** | **值** | **说明** | 169e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 170e41f4b71Sopenharmony_ci| PRINT_JOB_PREPARE | 0 | 表示打印任务的初始状态 | 171e41f4b71Sopenharmony_ci| PRINT_JOB_QUEUED | 1 | 表示打印任务传送到打印机 | 172e41f4b71Sopenharmony_ci| PRINT_JOB_RUNNING | 2 | 表示执行打印任务| 173e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCKED | 3 | 表示打印任务已被阻止 | 174e41f4b71Sopenharmony_ci| PRINT_JOB_COMPLETED | 4 | 表示打印任务完成 | 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci## PrintJobSubState 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci打印任务子状态的枚举。 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci| **名称** | **值** | **说明** | 185e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 186e41f4b71Sopenharmony_ci| PRINT_JOB_COMPLETED_SUCCESS | 0 | 表示打印任务成功 | 187e41f4b71Sopenharmony_ci| PRINT_JOB_COMPLETED_FAILED | 1 | 表示打印任务失败 | 188e41f4b71Sopenharmony_ci| PRINT_JOB_COMPLETED_CANCELLED | 2 | 表示打印任务已取消| 189e41f4b71Sopenharmony_ci| PRINT_JOB_COMPLETED_FILE_CORRUPTED | 3 | 表示打印任务已损坏 | 190e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_OFFLINE | 4 | 表示打印处于离线状态 | 191e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_BUSY | 5 | 表示打印被其他进程占用 | 192e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_CANCELLED | 6 | 表示打印任务已取消 | 193e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_OUT_OF_PAPER | 7 | 表示打印纸张用完 | 194e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_OUT_OF_INK | 8 | 表示打印墨水用完 | 195e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_OUT_OF_TONER | 9 | 表示打印墨粉用完 | 196e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_JAMMED | 10 | 表示打印卡纸 | 197e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_DOOR_OPEN | 11 | 表示打印盖开启 | 198e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_SERVICE_REQUEST | 12 | 表示打印服务请求 | 199e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_LOW_ON_INK | 13 | 表示打印墨水不足 | 200e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_LOW_ON_TONER | 14 | 表示打印墨粉不足 | 201e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_REALLY_LOW_ON_INK | 15 | 表示打印墨水量非常低 | 202e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_BAD_CERTIFICATE | 16 | 表示打印证书有误 | 203e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_ACCOUNT_ERROR<sup>11+</sup> | 18 | 表示打印账户时出错 | 204e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_PRINT_PERMISSION_ERROR<sup>11+</sup> | 19 | 表示打印许可异常 | 205e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_PRINT_COLOR_PERMISSION_ERROR<sup>11+</sup> | 20 | 表示彩色打印权限异常 | 206e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_NETWORK_ERROR<sup>11+</sup> | 21 | 表示设备未连接到网络 | 207e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_SERVER_CONNECTION_ERROR<sup>11+</sup> | 22 | 表示无法连接服务器 | 208e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_LARGE_FILE_ERROR<sup>11+</sup> | 23 | 表示打印大文件异常 | 209e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_FILE_PARSING_ERROR<sup>11+</sup> | 24 | 表示文件分析异常 | 210e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_SLOW_FILE_CONVERSION<sup>11+</sup> | 25 | 表示文件转换太慢 | 211e41f4b71Sopenharmony_ci| PRINT_JOB_RUNNING_UPLOADING_FILES<sup>11+</sup> | 26 | 表示正在上传文件 | 212e41f4b71Sopenharmony_ci| PRINT_JOB_RUNNING_CONVERTING_FILES<sup>11+</sup> | 27 | 表示正在转换文件 | 213e41f4b71Sopenharmony_ci| PRINT_JOB_BLOCK_UNKNOWN | 99 | 表示打印未知问题 | 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci## PrintErrorCode 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci打印错误代码的枚举。 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci| **名称** | **值** | **说明** | 224e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 225e41f4b71Sopenharmony_ci| E_PRINT_NONE | 0 | 表示没有错误 | 226e41f4b71Sopenharmony_ci| E_PRINT_NO_PERMISSION | 201 | 表示没有许可 | 227e41f4b71Sopenharmony_ci| E_PRINT_INVALID_PARAMETER | 401 | 表示无效的参数 | 228e41f4b71Sopenharmony_ci| E_PRINT_GENERIC_FAILURE | 13100001 | 表示一般打印失败 | 229e41f4b71Sopenharmony_ci| E_PRINT_RPC_FAILURE | 13100002 | 表示RPC失败 | 230e41f4b71Sopenharmony_ci| E_PRINT_SERVER_FAILURE | 13100003 | 表示打印服务失败 | 231e41f4b71Sopenharmony_ci| E_PRINT_INVALID_EXTENSION | 13100004 | 表示打印扩展无效 | 232e41f4b71Sopenharmony_ci| E_PRINT_INVALID_PRINTER | 13100005 | 表示打印机无效 | 233e41f4b71Sopenharmony_ci| E_PRINT_INVALID_PRINT_JOB | 13100006 | 表示打印任务无效 | 234e41f4b71Sopenharmony_ci| E_PRINT_FILE_IO | 13100007 | 表示文件输入/输出错误 | 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci## ApplicationEvent<sup>12+</sup> 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci打印应用事件的枚举。 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci| **名称** | **值** | **说明** | 245e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 246e41f4b71Sopenharmony_ci| APPLICATION_CREATED | 0 | 表示打印应用被拉起的事件 | 247e41f4b71Sopenharmony_ci| APPLICATION_CLOSED_FOR_STARTED | 1 | 表示由于点击打印而关于打印应用的事件 | 248e41f4b71Sopenharmony_ci| APPLICATION_CLOSED_FOR_CANCELED | 2 | 表示由于点击取消而关闭打印应用的事件 | 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci## PrinterExtensionInfo 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci定义打印扩展信息的接口。 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci**属性:** 259e41f4b71Sopenharmony_ci| **名称** | **类型** | **必填** | **说明** | 260e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 261e41f4b71Sopenharmony_ci| extensionId | string | 是 | 表示打印机扩展的扩展ID | 262e41f4b71Sopenharmony_ci| vendorId | string | 是 | 表示扩展的供应商ID | 263e41f4b71Sopenharmony_ci| vendorName | string | 是 | 表示供应商名称 | 264e41f4b71Sopenharmony_ci| vendorIcon | number | 是 | 表示供应商图标 | 265e41f4b71Sopenharmony_ci| version | string | 是 | 表示当前打印机扩展的版本 | 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci## queryAllPrinterExtensionInfos 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ciqueryAllPrinterExtensionInfos(callback: AsyncCallback<Array<PrinterExtensionInfo>>): void 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci查询所有已安装的打印机扩展服务,使用callback异步回调。 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci**参数:** 280e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 281e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 282e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<PrinterExtensionInfo>> | 是 | 异步查询所有已安装的打印机扩展服务之后的回调 | 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci**错误码:** 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 289e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 290e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 291e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci**示例:** 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci```ts 296e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 297e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ciprint.queryAllPrinterExtensionInfos((err: BusinessError, extensionInfos: print.PrinterExtensionInfo[]) => { 300e41f4b71Sopenharmony_ci if (err) { 301e41f4b71Sopenharmony_ci console.log('queryAllPrinterExtensionInfos err ' + JSON.stringify(err)); 302e41f4b71Sopenharmony_ci } else { 303e41f4b71Sopenharmony_ci console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos)); 304e41f4b71Sopenharmony_ci } 305e41f4b71Sopenharmony_ci}) 306e41f4b71Sopenharmony_ci``` 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci## queryAllPrinterExtensionInfos 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ciqueryAllPrinterExtensionInfos(): Promise<Array<PrinterExtensionInfo>> 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci查询所有已安装的打印机扩展服务,使用Promise异步回调。 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci**返回值:** 321e41f4b71Sopenharmony_ci| **类型** | **说明** | 322e41f4b71Sopenharmony_ci| -------- | -------- | 323e41f4b71Sopenharmony_ci| Promise<Array<PrinterExtensionInfo>> | 查询所有已安装的打印机扩展服务完成结果 | 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci**错误码:** 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 330e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 331e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 332e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci**示例:** 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci```ts 337e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 338e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ciprint.queryAllPrinterExtensionInfos().then((extensionInfos: print.PrinterExtensionInfo[]) => { 341e41f4b71Sopenharmony_ci console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos)); 342e41f4b71Sopenharmony_ci // ... 343e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 344e41f4b71Sopenharmony_ci console.log('failed to get AllPrinterExtension bacause ' + JSON.stringify(error)); 345e41f4b71Sopenharmony_ci}) 346e41f4b71Sopenharmony_ci``` 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci## startDiscoverPrinter 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_cistartDiscoverPrinter(extensionList: Array<string>, callback: AsyncCallback<void>): void 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ci加载特定的打印机扩展并开始发现打印机,使用callback异步回调。 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci**参数:** 361e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 362e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 363e41f4b71Sopenharmony_ci| extensionList | Array<string> | 是 | 要加载的打印机扩展列表 | 364e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步开始发现打印机之后的回调 | 365e41f4b71Sopenharmony_ci 366e41f4b71Sopenharmony_ci**错误码:** 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 371e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 372e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 373e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 374e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci**示例:** 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci```ts 379e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 380e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_cilet extensionList: string[] = []; 383e41f4b71Sopenharmony_ci//extensionList内无信息表示发现所有扩展 384e41f4b71Sopenharmony_ciprint.startDiscoverPrinter(extensionList, (err: BusinessError, data : void) => { 385e41f4b71Sopenharmony_ci if (err) { 386e41f4b71Sopenharmony_ci console.log('failed to start Discover Printer because : ' + JSON.stringify(err)); 387e41f4b71Sopenharmony_ci } else { 388e41f4b71Sopenharmony_ci console.log('start Discover Printer success data : ' + JSON.stringify(data)); 389e41f4b71Sopenharmony_ci } 390e41f4b71Sopenharmony_ci}) 391e41f4b71Sopenharmony_ci``` 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci## startDiscoverPrinter 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_cistartDiscoverPrinter(extensionList: Array<string>): Promise<void> 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci加载特定的打印机扩展并开始发现打印机,使用Promise异步回调。 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci**参数:** 406e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 407e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 408e41f4b71Sopenharmony_ci| extensionList | Array<string> | 是 | 要加载的打印机扩展列表 | 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci**返回值:** 411e41f4b71Sopenharmony_ci| **类型** | **说明** | 412e41f4b71Sopenharmony_ci| -------- | -------- | 413e41f4b71Sopenharmony_ci| Promise<void> | 加载特定的打印机扩展并开始发现打印机完成结果 | 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci**错误码:** 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 420e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 421e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 422e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 423e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ci**示例:** 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci```ts 428e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 429e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_cilet extensionList: string[] = []; 432e41f4b71Sopenharmony_ci//extensionList内无信息表示发现所有扩展 433e41f4b71Sopenharmony_ciprint.startDiscoverPrinter(extensionList).then((data : void) => { 434e41f4b71Sopenharmony_ci console.log('start Discovery success data : ' + JSON.stringify(data)); 435e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 436e41f4b71Sopenharmony_ci console.log('failed to start Discovery because : ' + JSON.stringify(error)); 437e41f4b71Sopenharmony_ci}) 438e41f4b71Sopenharmony_ci``` 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci## stopDiscoverPrinter 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_cistopDiscoverPrinter(callback: AsyncCallback<void>): void 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ci停止发现具有特定打印机扩展的打印机,使用callback异步回调。 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ci**参数:** 453e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 454e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 455e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步停止发现具有特定打印机扩展的打印机之后的回调 | 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci**错误码:** 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 462e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 463e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 464e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci**示例:** 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci```ts 469e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 470e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_ciprint.stopDiscoverPrinter((err: BusinessError, data : void) => { 473e41f4b71Sopenharmony_ci if (err) { 474e41f4b71Sopenharmony_ci console.log('failed to stop Discover Printer because : ' + JSON.stringify(err)); 475e41f4b71Sopenharmony_ci } else { 476e41f4b71Sopenharmony_ci console.log('stop Discover Printer success data : ' + JSON.stringify(data)); 477e41f4b71Sopenharmony_ci } 478e41f4b71Sopenharmony_ci}) 479e41f4b71Sopenharmony_ci``` 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci## stopDiscoverPrinter 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_cistopDiscoverPrinter(): Promise<void> 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci停止发现具有特定打印机扩展的打印机,使用Promise异步回调。 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci**返回值:** 494e41f4b71Sopenharmony_ci| **类型** | **说明** | 495e41f4b71Sopenharmony_ci| -------- | -------- | 496e41f4b71Sopenharmony_ci| Promise<void> | 停止发现具有特定打印机扩展的打印机完成结果 | 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ci**错误码:** 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 501e41f4b71Sopenharmony_ci 502e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 503e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 504e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 505e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci**示例:** 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci```ts 510e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 511e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ciprint.stopDiscoverPrinter().then((data : void) => { 514e41f4b71Sopenharmony_ci console.log('stop Discovery success data : ' + JSON.stringify(data)); 515e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 516e41f4b71Sopenharmony_ci console.log('failed to stop Discovery because : ' + JSON.stringify(error)); 517e41f4b71Sopenharmony_ci}) 518e41f4b71Sopenharmony_ci``` 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci## connectPrinter 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ciconnectPrinter(printerId: string, callback: AsyncCallback<void>): void 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci连接特定打印机,使用callback异步回调。 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 527e41f4b71Sopenharmony_ci 528e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 529e41f4b71Sopenharmony_ci 530e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci**参数:** 533e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 534e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 535e41f4b71Sopenharmony_ci| printerId | string | 是 | 打印机ID | 536e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步连接特定打印机之后的回调 | 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_ci**错误码:** 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 541e41f4b71Sopenharmony_ci 542e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 543e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 544e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 545e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 546e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ci**示例:** 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci```ts 551e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 552e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 553e41f4b71Sopenharmony_ci 554e41f4b71Sopenharmony_cilet printerId: string = 'printerId_32'; 555e41f4b71Sopenharmony_ciprint.connectPrinter(printerId, (err: BusinessError, data : void) => { 556e41f4b71Sopenharmony_ci if (err) { 557e41f4b71Sopenharmony_ci console.log('failed to connect Printer because : ' + JSON.stringify(err)); 558e41f4b71Sopenharmony_ci } else { 559e41f4b71Sopenharmony_ci console.log('start connect Printer success data : ' + JSON.stringify(data)); 560e41f4b71Sopenharmony_ci } 561e41f4b71Sopenharmony_ci}) 562e41f4b71Sopenharmony_ci``` 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci## connectPrinter 565e41f4b71Sopenharmony_ci 566e41f4b71Sopenharmony_ciconnectPrinter(printerId: string): Promise<void> 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ci连接特定打印机,使用Promise异步回调。 569e41f4b71Sopenharmony_ci 570e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 571e41f4b71Sopenharmony_ci 572e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci**参数:** 577e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 578e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 579e41f4b71Sopenharmony_ci| printerId | string | 是 | 打印机ID | 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_ci**返回值:** 582e41f4b71Sopenharmony_ci| **类型** | **说明** | 583e41f4b71Sopenharmony_ci| -------- | -------- | 584e41f4b71Sopenharmony_ci| Promise<void> | 连接特定打印机完成结果 | 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci**错误码:** 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 589e41f4b71Sopenharmony_ci 590e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 591e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 592e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 593e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 594e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 595e41f4b71Sopenharmony_ci 596e41f4b71Sopenharmony_ci**示例:** 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci```ts 599e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 600e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_cilet printerId: string = 'printerId_32'; 603e41f4b71Sopenharmony_ciprint.connectPrinter(printerId).then((data : void) => { 604e41f4b71Sopenharmony_ci console.log('start connect Printer success data : ' + JSON.stringify(data)); 605e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 606e41f4b71Sopenharmony_ci console.log('failed to connect Printer because : ' + JSON.stringify(error)); 607e41f4b71Sopenharmony_ci}) 608e41f4b71Sopenharmony_ci``` 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci## disconnectPrinter 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_cidisconnectPrinter(printerId: string, callback: AsyncCallback<void>): void 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ci断开特定打印机的连接,使用callback异步回调。 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 619e41f4b71Sopenharmony_ci 620e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ci**参数:** 623e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 624e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 625e41f4b71Sopenharmony_ci| printerId | string | 是 | 打印机ID | 626e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步断开特定打印机的连接之后的回调 | 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ci**错误码:** 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 631e41f4b71Sopenharmony_ci 632e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 633e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 634e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 635e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 636e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci**示例:** 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ci```ts 641e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 642e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_cilet printerId: string = 'printerId_32'; 645e41f4b71Sopenharmony_ciprint.disconnectPrinter(printerId, (err: BusinessError, data : void) => { 646e41f4b71Sopenharmony_ci if (err) { 647e41f4b71Sopenharmony_ci console.log('failed to disconnect Printer because : ' + JSON.stringify(err)); 648e41f4b71Sopenharmony_ci } else { 649e41f4b71Sopenharmony_ci console.log('start disconnect Printer success data : ' + JSON.stringify(data)); 650e41f4b71Sopenharmony_ci } 651e41f4b71Sopenharmony_ci}) 652e41f4b71Sopenharmony_ci``` 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci## disconnectPrinter 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_cidisconnectPrinter(printerId: string): Promise<void> 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ci断开特定打印机的连接,使用Promise异步回调。 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 663e41f4b71Sopenharmony_ci 664e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 665e41f4b71Sopenharmony_ci 666e41f4b71Sopenharmony_ci**参数:** 667e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 668e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 669e41f4b71Sopenharmony_ci| printerId | string | 是 | 打印机ID | 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci**返回值:** 672e41f4b71Sopenharmony_ci| **类型** | **说明** | 673e41f4b71Sopenharmony_ci| -------- | -------- | 674e41f4b71Sopenharmony_ci| Promise<void> | 断开特定打印机的连接完成结果 | 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ci**错误码:** 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 679e41f4b71Sopenharmony_ci 680e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 681e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 682e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 683e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 684e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci**示例:** 687e41f4b71Sopenharmony_ci 688e41f4b71Sopenharmony_ci```ts 689e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 690e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 691e41f4b71Sopenharmony_ci 692e41f4b71Sopenharmony_cilet printerId: string = 'printerId_32'; 693e41f4b71Sopenharmony_ciprint.disconnectPrinter(printerId).then((data : void) => { 694e41f4b71Sopenharmony_ci console.log('start disconnect Printer success data : ' + JSON.stringify(data)); 695e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 696e41f4b71Sopenharmony_ci console.log('failed to disconnect Printer because : ' + JSON.stringify(error)); 697e41f4b71Sopenharmony_ci}) 698e41f4b71Sopenharmony_ci``` 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_ci## queryPrinterCapability 701e41f4b71Sopenharmony_ci 702e41f4b71Sopenharmony_ciqueryPrinterCapability(printerId: string, callback: AsyncCallback<void>): void 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_ci查询打印机能力,使用callback异步回调。 705e41f4b71Sopenharmony_ci 706e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 709e41f4b71Sopenharmony_ci 710e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 711e41f4b71Sopenharmony_ci 712e41f4b71Sopenharmony_ci**参数:** 713e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 714e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 715e41f4b71Sopenharmony_ci| printerId | string | 是 | 打印机ID | 716e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步查询打印机能力之后的回调 | 717e41f4b71Sopenharmony_ci 718e41f4b71Sopenharmony_ci**错误码:** 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 721e41f4b71Sopenharmony_ci 722e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 723e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 724e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 725e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 726e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_ci**示例:** 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ci```ts 731e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 732e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 733e41f4b71Sopenharmony_ci 734e41f4b71Sopenharmony_cilet printerId: string = 'printerId_32'; 735e41f4b71Sopenharmony_ciprint.queryPrinterCapability(printerId, (err: BusinessError, data : void) => { 736e41f4b71Sopenharmony_ci if (err) { 737e41f4b71Sopenharmony_ci console.log('failed to query Printer Capability because : ' + JSON.stringify(err)); 738e41f4b71Sopenharmony_ci } else { 739e41f4b71Sopenharmony_ci console.log('start query Printer Capability success data : ' + JSON.stringify(data)); 740e41f4b71Sopenharmony_ci } 741e41f4b71Sopenharmony_ci}) 742e41f4b71Sopenharmony_ci``` 743e41f4b71Sopenharmony_ci 744e41f4b71Sopenharmony_ci## queryPrinterCapability 745e41f4b71Sopenharmony_ci 746e41f4b71Sopenharmony_ciqueryPrinterCapability(printerId: string): Promise<void> 747e41f4b71Sopenharmony_ci 748e41f4b71Sopenharmony_ci查询打印机能力,使用Promise异步回调。 749e41f4b71Sopenharmony_ci 750e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 751e41f4b71Sopenharmony_ci 752e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 753e41f4b71Sopenharmony_ci 754e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 755e41f4b71Sopenharmony_ci 756e41f4b71Sopenharmony_ci**参数:** 757e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 758e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 759e41f4b71Sopenharmony_ci| printerId | string | 是 | 打印机ID | 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci**返回值:** 762e41f4b71Sopenharmony_ci| **类型** | **说明** | 763e41f4b71Sopenharmony_ci| -------- | -------- | 764e41f4b71Sopenharmony_ci| Promise<void> | 查询打印机能力完成结果 | 765e41f4b71Sopenharmony_ci 766e41f4b71Sopenharmony_ci**错误码:** 767e41f4b71Sopenharmony_ci 768e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 771e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 772e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 773e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 774e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ci**示例:** 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ci```ts 779e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 780e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_cilet printerId: string = 'printerId_32'; 783e41f4b71Sopenharmony_ciprint.queryPrinterCapability(printerId).then((data : void) => { 784e41f4b71Sopenharmony_ci console.log('start query Printer success data : ' + JSON.stringify(data)); 785e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 786e41f4b71Sopenharmony_ci console.log('failed to query Printer Capability because : ' + JSON.stringify(error)); 787e41f4b71Sopenharmony_ci}) 788e41f4b71Sopenharmony_ci``` 789e41f4b71Sopenharmony_ci 790e41f4b71Sopenharmony_ci## startPrintJob 791e41f4b71Sopenharmony_ci 792e41f4b71Sopenharmony_cistartPrintJob(jobInfo: PrintJob, callback: AsyncCallback<void>): void 793e41f4b71Sopenharmony_ci 794e41f4b71Sopenharmony_ci开始打印任务,使用callback异步回调。 795e41f4b71Sopenharmony_ci 796e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 797e41f4b71Sopenharmony_ci 798e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 801e41f4b71Sopenharmony_ci 802e41f4b71Sopenharmony_ci**参数:** 803e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 804e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 805e41f4b71Sopenharmony_ci| jobInfo | PrintJob | 是 | 打印任务信息 | 806e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步开始打印任务之后的回调 | 807e41f4b71Sopenharmony_ci 808e41f4b71Sopenharmony_ci**错误码:** 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 811e41f4b71Sopenharmony_ci 812e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 813e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 814e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 815e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 816e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ci**示例:** 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ci```ts 821e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 822e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 823e41f4b71Sopenharmony_ci 824e41f4b71Sopenharmony_cilet jobInfo : print.PrintJob = { 825e41f4b71Sopenharmony_ci fdList : [0,1], 826e41f4b71Sopenharmony_ci jobId : 'jobId_12', 827e41f4b71Sopenharmony_ci printerId : 'printerId_32', 828e41f4b71Sopenharmony_ci jobState : 3, 829e41f4b71Sopenharmony_ci jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, 830e41f4b71Sopenharmony_ci copyNumber : 1, 831e41f4b71Sopenharmony_ci pageRange : {}, 832e41f4b71Sopenharmony_ci isSequential : false, 833e41f4b71Sopenharmony_ci pageSize : {id : '', name : '', width : 10, height : 20}, 834e41f4b71Sopenharmony_ci isLandscape : false, 835e41f4b71Sopenharmony_ci colorMode : 6, 836e41f4b71Sopenharmony_ci duplexMode : 6, 837e41f4b71Sopenharmony_ci margin : undefined, 838e41f4b71Sopenharmony_ci preview : undefined, 839e41f4b71Sopenharmony_ci options : undefined 840e41f4b71Sopenharmony_ci}; 841e41f4b71Sopenharmony_ciprint.startPrintJob(jobInfo, (err: BusinessError, data : void) => { 842e41f4b71Sopenharmony_ci if (err) { 843e41f4b71Sopenharmony_ci console.log('failed to start Print Job because : ' + JSON.stringify(err)); 844e41f4b71Sopenharmony_ci } else { 845e41f4b71Sopenharmony_ci console.log('start Print Job success data : ' + JSON.stringify(data)); 846e41f4b71Sopenharmony_ci } 847e41f4b71Sopenharmony_ci}) 848e41f4b71Sopenharmony_ci``` 849e41f4b71Sopenharmony_ci 850e41f4b71Sopenharmony_ci## startPrintJob 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_cistartPrintJob(jobInfo: PrintJob): Promise<void> 853e41f4b71Sopenharmony_ci 854e41f4b71Sopenharmony_ci开始打印任务,使用Promise异步回调。 855e41f4b71Sopenharmony_ci 856e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 857e41f4b71Sopenharmony_ci 858e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 859e41f4b71Sopenharmony_ci 860e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 861e41f4b71Sopenharmony_ci 862e41f4b71Sopenharmony_ci**参数:** 863e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 864e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 865e41f4b71Sopenharmony_ci| jobInfo | PrintJob | 是 | 打印任务信息 | 866e41f4b71Sopenharmony_ci 867e41f4b71Sopenharmony_ci**返回值:** 868e41f4b71Sopenharmony_ci| **类型** | **说明** | 869e41f4b71Sopenharmony_ci| -------- | -------- | 870e41f4b71Sopenharmony_ci| Promise<void> | 开始打印任务完成结果 | 871e41f4b71Sopenharmony_ci 872e41f4b71Sopenharmony_ci**错误码:** 873e41f4b71Sopenharmony_ci 874e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 875e41f4b71Sopenharmony_ci 876e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 877e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 878e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 879e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 880e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 881e41f4b71Sopenharmony_ci 882e41f4b71Sopenharmony_ci**示例:** 883e41f4b71Sopenharmony_ci 884e41f4b71Sopenharmony_ci```ts 885e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 886e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 887e41f4b71Sopenharmony_ci 888e41f4b71Sopenharmony_cilet jobInfo : print.PrintJob = { 889e41f4b71Sopenharmony_ci fdList : [0,1], 890e41f4b71Sopenharmony_ci jobId : 'jobId_12', 891e41f4b71Sopenharmony_ci printerId : 'printerId_32', 892e41f4b71Sopenharmony_ci jobState : 3, 893e41f4b71Sopenharmony_ci jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, 894e41f4b71Sopenharmony_ci copyNumber : 1, 895e41f4b71Sopenharmony_ci pageRange : {}, 896e41f4b71Sopenharmony_ci isSequential : false, 897e41f4b71Sopenharmony_ci pageSize : {id : '', name : '', width : 10, height : 20}, 898e41f4b71Sopenharmony_ci isLandscape : false, 899e41f4b71Sopenharmony_ci colorMode : 6, 900e41f4b71Sopenharmony_ci duplexMode : 6, 901e41f4b71Sopenharmony_ci margin : undefined, 902e41f4b71Sopenharmony_ci preview : undefined, 903e41f4b71Sopenharmony_ci options : undefined 904e41f4b71Sopenharmony_ci}; 905e41f4b71Sopenharmony_ciprint.startPrintJob(jobInfo).then((data : void) => { 906e41f4b71Sopenharmony_ci console.log('start Print success data : ' + JSON.stringify(data)); 907e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 908e41f4b71Sopenharmony_ci console.log('failed to start Print because : ' + JSON.stringify(error)); 909e41f4b71Sopenharmony_ci}) 910e41f4b71Sopenharmony_ci``` 911e41f4b71Sopenharmony_ci 912e41f4b71Sopenharmony_ci## cancelPrintJob 913e41f4b71Sopenharmony_ci 914e41f4b71Sopenharmony_cicancelPrintJob(jobId: string, callback: AsyncCallback<void>): void 915e41f4b71Sopenharmony_ci 916e41f4b71Sopenharmony_ci取消已发送到打印机的打印任务,使用callback异步回调。 917e41f4b71Sopenharmony_ci 918e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 919e41f4b71Sopenharmony_ci 920e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 921e41f4b71Sopenharmony_ci 922e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 923e41f4b71Sopenharmony_ci 924e41f4b71Sopenharmony_ci**参数:** 925e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 926e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 927e41f4b71Sopenharmony_ci| jobId | string | 是 | 打印任务ID | 928e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步取消已发送到打印机的打印任务之后的回调 | 929e41f4b71Sopenharmony_ci 930e41f4b71Sopenharmony_ci**错误码:** 931e41f4b71Sopenharmony_ci 932e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 935e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 936e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 937e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 938e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci**示例:** 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci```ts 943e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 944e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 945e41f4b71Sopenharmony_ci 946e41f4b71Sopenharmony_cilet jobId : string = '121212'; 947e41f4b71Sopenharmony_ciprint.cancelPrintJob(jobId, (err: BusinessError, data : void) => { 948e41f4b71Sopenharmony_ci if (err) { 949e41f4b71Sopenharmony_ci console.log('cancelPrintJob failed, because : ' + JSON.stringify(err)); 950e41f4b71Sopenharmony_ci } else { 951e41f4b71Sopenharmony_ci console.log('cancelPrintJob success, data: ' + JSON.stringify(data)); 952e41f4b71Sopenharmony_ci } 953e41f4b71Sopenharmony_ci}) 954e41f4b71Sopenharmony_ci``` 955e41f4b71Sopenharmony_ci 956e41f4b71Sopenharmony_ci## cancelPrintJob 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_cicancelPrintJob(jobId: string): Promise<void> 959e41f4b71Sopenharmony_ci 960e41f4b71Sopenharmony_ci取消已发送到打印机的打印任务,使用Promise异步回调。 961e41f4b71Sopenharmony_ci 962e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 963e41f4b71Sopenharmony_ci 964e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 965e41f4b71Sopenharmony_ci 966e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 967e41f4b71Sopenharmony_ci 968e41f4b71Sopenharmony_ci**参数:** 969e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 970e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 971e41f4b71Sopenharmony_ci| jobId | string | 是 | 打印任务ID | 972e41f4b71Sopenharmony_ci 973e41f4b71Sopenharmony_ci**返回值:** 974e41f4b71Sopenharmony_ci| **类型** | **说明** | 975e41f4b71Sopenharmony_ci| -------- | -------- | 976e41f4b71Sopenharmony_ci| Promise<void> | 取消已发送到打印机的打印任务完成结果 | 977e41f4b71Sopenharmony_ci 978e41f4b71Sopenharmony_ci**错误码:** 979e41f4b71Sopenharmony_ci 980e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 981e41f4b71Sopenharmony_ci 982e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 983e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 984e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 985e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 986e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 987e41f4b71Sopenharmony_ci 988e41f4b71Sopenharmony_ci**示例:** 989e41f4b71Sopenharmony_ci 990e41f4b71Sopenharmony_ci```ts 991e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 992e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 993e41f4b71Sopenharmony_ci 994e41f4b71Sopenharmony_cilet jobId : string = '121212'; 995e41f4b71Sopenharmony_ciprint.cancelPrintJob(jobId).then((data : void) => { 996e41f4b71Sopenharmony_ci console.log('cancelPrintJob success, data : ' + JSON.stringify(data)); 997e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 998e41f4b71Sopenharmony_ci console.log('cancelPrintJob failed, because : ' + JSON.stringify(error)); 999e41f4b71Sopenharmony_ci}) 1000e41f4b71Sopenharmony_ci``` 1001e41f4b71Sopenharmony_ci 1002e41f4b71Sopenharmony_ci## requestPrintPreview 1003e41f4b71Sopenharmony_ci 1004e41f4b71Sopenharmony_cirequestPrintPreview(jobInfo: PrintJob, callback: Callback<number>): void 1005e41f4b71Sopenharmony_ci 1006e41f4b71Sopenharmony_ci请求预览打印数据,使用callback回调。 1007e41f4b71Sopenharmony_ci 1008e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1009e41f4b71Sopenharmony_ci 1010e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1011e41f4b71Sopenharmony_ci 1012e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1013e41f4b71Sopenharmony_ci 1014e41f4b71Sopenharmony_ci**参数:** 1015e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1016e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1017e41f4b71Sopenharmony_ci| jobInfo | PrintJob | 是 | 打印任务信息 | 1018e41f4b71Sopenharmony_ci| callback | Callback<number> | 是 | 请求预览打印数据之后的回调 | 1019e41f4b71Sopenharmony_ci 1020e41f4b71Sopenharmony_ci**错误码:** 1021e41f4b71Sopenharmony_ci 1022e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1023e41f4b71Sopenharmony_ci 1024e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1025e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1026e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1027e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1028e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1029e41f4b71Sopenharmony_ci 1030e41f4b71Sopenharmony_ci**示例:** 1031e41f4b71Sopenharmony_ci 1032e41f4b71Sopenharmony_ci```ts 1033e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1034e41f4b71Sopenharmony_ci 1035e41f4b71Sopenharmony_cilet jobInfo : print.PrintJob = { 1036e41f4b71Sopenharmony_ci fdList : [0,1], 1037e41f4b71Sopenharmony_ci jobId : 'jobId_12', 1038e41f4b71Sopenharmony_ci printerId : 'printerId_32', 1039e41f4b71Sopenharmony_ci jobState : 3, 1040e41f4b71Sopenharmony_ci jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, 1041e41f4b71Sopenharmony_ci copyNumber : 1, 1042e41f4b71Sopenharmony_ci pageRange : {}, 1043e41f4b71Sopenharmony_ci isSequential : false, 1044e41f4b71Sopenharmony_ci pageSize : {id : '', name : '', width : 10, height : 20}, 1045e41f4b71Sopenharmony_ci isLandscape : false, 1046e41f4b71Sopenharmony_ci colorMode : 6, 1047e41f4b71Sopenharmony_ci duplexMode : 6, 1048e41f4b71Sopenharmony_ci margin : undefined, 1049e41f4b71Sopenharmony_ci preview : undefined, 1050e41f4b71Sopenharmony_ci options : undefined 1051e41f4b71Sopenharmony_ci}; 1052e41f4b71Sopenharmony_ciprint.requestPrintPreview(jobInfo, (num : number) => { 1053e41f4b71Sopenharmony_ci console.log('requestPrintPreview success, num : ' + JSON.stringify(num)); 1054e41f4b71Sopenharmony_ci 1055e41f4b71Sopenharmony_ci}) 1056e41f4b71Sopenharmony_ci``` 1057e41f4b71Sopenharmony_ci 1058e41f4b71Sopenharmony_ci## requestPrintPreview 1059e41f4b71Sopenharmony_ci 1060e41f4b71Sopenharmony_cirequestPrintPreview(jobInfo: PrintJob): Promise<number> 1061e41f4b71Sopenharmony_ci 1062e41f4b71Sopenharmony_ci请求预览打印数据,使用Promise异步回调。 1063e41f4b71Sopenharmony_ci 1064e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1065e41f4b71Sopenharmony_ci 1066e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1067e41f4b71Sopenharmony_ci 1068e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1069e41f4b71Sopenharmony_ci 1070e41f4b71Sopenharmony_ci**参数:** 1071e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1072e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1073e41f4b71Sopenharmony_ci| jobInfo | PrintJob | 是 | 打印任务信息 | 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci**返回值:** 1076e41f4b71Sopenharmony_ci| **类型** | **说明** | 1077e41f4b71Sopenharmony_ci| -------- | -------- | 1078e41f4b71Sopenharmony_ci| Promise<number> | 请求预览打印数据完成结果 | 1079e41f4b71Sopenharmony_ci 1080e41f4b71Sopenharmony_ci**错误码:** 1081e41f4b71Sopenharmony_ci 1082e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1083e41f4b71Sopenharmony_ci 1084e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1085e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1086e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1087e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1088e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1089e41f4b71Sopenharmony_ci 1090e41f4b71Sopenharmony_ci**示例:** 1091e41f4b71Sopenharmony_ci 1092e41f4b71Sopenharmony_ci```ts 1093e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1094e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1095e41f4b71Sopenharmony_ci 1096e41f4b71Sopenharmony_cilet jobInfo : print.PrintJob = { 1097e41f4b71Sopenharmony_ci fdList : [0,1], 1098e41f4b71Sopenharmony_ci jobId : 'jobId_12', 1099e41f4b71Sopenharmony_ci printerId : 'printerId_32', 1100e41f4b71Sopenharmony_ci jobState : 3, 1101e41f4b71Sopenharmony_ci jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, 1102e41f4b71Sopenharmony_ci copyNumber : 1, 1103e41f4b71Sopenharmony_ci pageRange : {}, 1104e41f4b71Sopenharmony_ci isSequential : false, 1105e41f4b71Sopenharmony_ci pageSize : {id : '', name : '', width : 10, height : 20}, 1106e41f4b71Sopenharmony_ci isLandscape : false, 1107e41f4b71Sopenharmony_ci colorMode : 6, 1108e41f4b71Sopenharmony_ci duplexMode : 6, 1109e41f4b71Sopenharmony_ci margin : undefined, 1110e41f4b71Sopenharmony_ci preview : undefined, 1111e41f4b71Sopenharmony_ci options : undefined 1112e41f4b71Sopenharmony_ci}; 1113e41f4b71Sopenharmony_ciprint.requestPrintPreview(jobInfo).then((num: number) => { 1114e41f4b71Sopenharmony_ci console.log('requestPrintPreview success, num : ' + JSON.stringify(num)); 1115e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 1116e41f4b71Sopenharmony_ci console.log('requestPrintPreview failed, because : ' + JSON.stringify(error)); 1117e41f4b71Sopenharmony_ci}) 1118e41f4b71Sopenharmony_ci``` 1119e41f4b71Sopenharmony_ci 1120e41f4b71Sopenharmony_ci## on 1121e41f4b71Sopenharmony_ci 1122e41f4b71Sopenharmony_cion(type: 'printerStateChange', callback: (state: PrinterState, info: PrinterInfo) => void): void 1123e41f4b71Sopenharmony_ci 1124e41f4b71Sopenharmony_ci注册打印机状态变化事件回调,使用callback回调。 1125e41f4b71Sopenharmony_ci 1126e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1127e41f4b71Sopenharmony_ci 1128e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1129e41f4b71Sopenharmony_ci 1130e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1131e41f4b71Sopenharmony_ci 1132e41f4b71Sopenharmony_ci**参数:** 1133e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1134e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1135e41f4b71Sopenharmony_ci| type | 'printerStateChange' | 是 | 表示打印机状态改变 | 1136e41f4b71Sopenharmony_ci| callback | (state: PrinterState, info: PrinterInfo) => void | 是 | 打印机状态改变之后的回调 | 1137e41f4b71Sopenharmony_ci 1138e41f4b71Sopenharmony_ci**错误码:** 1139e41f4b71Sopenharmony_ci 1140e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1141e41f4b71Sopenharmony_ci 1142e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1143e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1144e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1145e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1146e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1147e41f4b71Sopenharmony_ci 1148e41f4b71Sopenharmony_ci**示例:** 1149e41f4b71Sopenharmony_ci 1150e41f4b71Sopenharmony_ci```ts 1151e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ciprint.on('printerStateChange', (state: print.PrinterState, info: print.PrinterInfo) => { 1154e41f4b71Sopenharmony_ci if (state === null || info === null) { 1155e41f4b71Sopenharmony_ci console.log('printer state changed state is null or info is null'); 1156e41f4b71Sopenharmony_ci return; 1157e41f4b71Sopenharmony_ci } else { 1158e41f4b71Sopenharmony_ci console.log('on printer state changed, state : ' + JSON.stringify(state)); 1159e41f4b71Sopenharmony_ci console.log('on printer state changed, info : ' + JSON.stringify(info)); 1160e41f4b71Sopenharmony_ci } 1161e41f4b71Sopenharmony_ci}) 1162e41f4b71Sopenharmony_ci``` 1163e41f4b71Sopenharmony_ci 1164e41f4b71Sopenharmony_ci## off 1165e41f4b71Sopenharmony_ci 1166e41f4b71Sopenharmony_cioff(type: 'printerStateChange', callback?: Callback<boolean>): void 1167e41f4b71Sopenharmony_ci 1168e41f4b71Sopenharmony_ci取消注册打印机状态变化事件回调,使用callback回调。 1169e41f4b71Sopenharmony_ci 1170e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1171e41f4b71Sopenharmony_ci 1172e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1173e41f4b71Sopenharmony_ci 1174e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_ci**参数:** 1177e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1178e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1179e41f4b71Sopenharmony_ci| type | 'printerStateChange' | 是 | 表示打印机状态改变 | 1180e41f4b71Sopenharmony_ci| callback | Callback<boolean> | 否 | 打印机状态改变之后的回调 | 1181e41f4b71Sopenharmony_ci 1182e41f4b71Sopenharmony_ci**错误码:** 1183e41f4b71Sopenharmony_ci 1184e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1185e41f4b71Sopenharmony_ci 1186e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1187e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1188e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1189e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1190e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1191e41f4b71Sopenharmony_ci 1192e41f4b71Sopenharmony_ci**示例:** 1193e41f4b71Sopenharmony_ci 1194e41f4b71Sopenharmony_ci```ts 1195e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ciprint.off('printerStateChange', (data: boolean) => { 1198e41f4b71Sopenharmony_ci console.log('off printerStateChange data : ' + JSON.stringify(data)); 1199e41f4b71Sopenharmony_ci}) 1200e41f4b71Sopenharmony_ci``` 1201e41f4b71Sopenharmony_ci 1202e41f4b71Sopenharmony_ci## on 1203e41f4b71Sopenharmony_ci 1204e41f4b71Sopenharmony_cion(type: 'jobStateChange', callback: (state: PrintJobState, job: PrintJob) => void): void 1205e41f4b71Sopenharmony_ci 1206e41f4b71Sopenharmony_ci注册打印任务状态变化事件回调,使用callback回调。 1207e41f4b71Sopenharmony_ci 1208e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1209e41f4b71Sopenharmony_ci 1210e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1211e41f4b71Sopenharmony_ci 1212e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1213e41f4b71Sopenharmony_ci 1214e41f4b71Sopenharmony_ci**参数:** 1215e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1216e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1217e41f4b71Sopenharmony_ci| type | 'jobStateChange' | 是 | 表示打印任务状态改变 | 1218e41f4b71Sopenharmony_ci| callback | (state: PrintJobState, job: PrintJob) => void | 是 | 打印任务状态改变之后的回调 | 1219e41f4b71Sopenharmony_ci 1220e41f4b71Sopenharmony_ci**错误码:** 1221e41f4b71Sopenharmony_ci 1222e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1223e41f4b71Sopenharmony_ci 1224e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1225e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1226e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1227e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1228e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1229e41f4b71Sopenharmony_ci 1230e41f4b71Sopenharmony_ci**示例:** 1231e41f4b71Sopenharmony_ci 1232e41f4b71Sopenharmony_ci```ts 1233e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ciprint.on('jobStateChange', (state: print.PrintJobState, job: print.PrintJob) => { 1236e41f4b71Sopenharmony_ci console.log('onJobStateChange, state : ' + JSON.stringify(state) + ', job : ' + JSON.stringify(job)); 1237e41f4b71Sopenharmony_ci}) 1238e41f4b71Sopenharmony_ci``` 1239e41f4b71Sopenharmony_ci 1240e41f4b71Sopenharmony_ci## off 1241e41f4b71Sopenharmony_ci 1242e41f4b71Sopenharmony_cioff(type: 'jobStateChange', callback?: Callback<boolean>): void 1243e41f4b71Sopenharmony_ci 1244e41f4b71Sopenharmony_ci取消注册打印任务状态变化事件回调,使用callback回调。 1245e41f4b71Sopenharmony_ci 1246e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1247e41f4b71Sopenharmony_ci 1248e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1249e41f4b71Sopenharmony_ci 1250e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1251e41f4b71Sopenharmony_ci 1252e41f4b71Sopenharmony_ci**参数:** 1253e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1254e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1255e41f4b71Sopenharmony_ci| type | 'jobStateChange' | 是 | 表示打印任务状态改变 | 1256e41f4b71Sopenharmony_ci| callback | Callback<boolean> | 否 | 打印任务状态改变之后的回调 | 1257e41f4b71Sopenharmony_ci 1258e41f4b71Sopenharmony_ci**错误码:** 1259e41f4b71Sopenharmony_ci 1260e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1261e41f4b71Sopenharmony_ci 1262e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1263e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1264e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1265e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1266e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1267e41f4b71Sopenharmony_ci 1268e41f4b71Sopenharmony_ci**示例:** 1269e41f4b71Sopenharmony_ci 1270e41f4b71Sopenharmony_ci```ts 1271e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1272e41f4b71Sopenharmony_ci 1273e41f4b71Sopenharmony_ciprint.off('jobStateChange', (data: boolean) => { 1274e41f4b71Sopenharmony_ci console.log('offJobStateChanged data : ' + JSON.stringify(data)); 1275e41f4b71Sopenharmony_ci}) 1276e41f4b71Sopenharmony_ci``` 1277e41f4b71Sopenharmony_ci 1278e41f4b71Sopenharmony_ci## on 1279e41f4b71Sopenharmony_ci 1280e41f4b71Sopenharmony_cion(type: 'extInfoChange', callback: (extensionId: string, info: string) => void): void 1281e41f4b71Sopenharmony_ci 1282e41f4b71Sopenharmony_ci注册打印扩展信息变化事件回调,使用callback回调。 1283e41f4b71Sopenharmony_ci 1284e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1285e41f4b71Sopenharmony_ci 1286e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1287e41f4b71Sopenharmony_ci 1288e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1289e41f4b71Sopenharmony_ci 1290e41f4b71Sopenharmony_ci**参数:** 1291e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1292e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1293e41f4b71Sopenharmony_ci| type | 'extInfoChange' | 是 | 表示打印扩展信息改变 | 1294e41f4b71Sopenharmony_ci| callback | (extensionId: string, info: string) => void | 是 | 打印扩展信息改变之后的回调 | 1295e41f4b71Sopenharmony_ci 1296e41f4b71Sopenharmony_ci**错误码:** 1297e41f4b71Sopenharmony_ci 1298e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1299e41f4b71Sopenharmony_ci 1300e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1301e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1302e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1303e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1304e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1305e41f4b71Sopenharmony_ci 1306e41f4b71Sopenharmony_ci**示例:** 1307e41f4b71Sopenharmony_ci 1308e41f4b71Sopenharmony_ci```ts 1309e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1310e41f4b71Sopenharmony_ci 1311e41f4b71Sopenharmony_ciprint.on('extInfoChange', (extensionId: string, info: string) => { 1312e41f4b71Sopenharmony_ci console.log('onExtInfoChange, entensionId : ' + JSON.stringify(extensionId) + ', info : ' + JSON.stringify(info)); 1313e41f4b71Sopenharmony_ci}) 1314e41f4b71Sopenharmony_ci``` 1315e41f4b71Sopenharmony_ci 1316e41f4b71Sopenharmony_ci## off 1317e41f4b71Sopenharmony_ci 1318e41f4b71Sopenharmony_cioff(type: 'extInfoChange', callback?: Callback<boolean>): void 1319e41f4b71Sopenharmony_ci 1320e41f4b71Sopenharmony_ci取消注册打印扩展信息变化事件回调,使用callback回调。 1321e41f4b71Sopenharmony_ci 1322e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1323e41f4b71Sopenharmony_ci 1324e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1325e41f4b71Sopenharmony_ci 1326e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1327e41f4b71Sopenharmony_ci 1328e41f4b71Sopenharmony_ci**参数:** 1329e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1330e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1331e41f4b71Sopenharmony_ci| type | 'extInfoChange' | 是 | 表示打印扩展信息改变 | 1332e41f4b71Sopenharmony_ci| callback | Callback<boolean> | 否 | 打印任务扩展信息改变之后的回调 | 1333e41f4b71Sopenharmony_ci 1334e41f4b71Sopenharmony_ci**错误码:** 1335e41f4b71Sopenharmony_ci 1336e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1337e41f4b71Sopenharmony_ci 1338e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1339e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1340e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1341e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1342e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1343e41f4b71Sopenharmony_ci 1344e41f4b71Sopenharmony_ci**示例:** 1345e41f4b71Sopenharmony_ci 1346e41f4b71Sopenharmony_ci```ts 1347e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1348e41f4b71Sopenharmony_ci 1349e41f4b71Sopenharmony_ciprint.off('extInfoChange', (data: boolean) => { 1350e41f4b71Sopenharmony_ci console.log('offExtInfoChange data : ' + JSON.stringify(data)); 1351e41f4b71Sopenharmony_ci}) 1352e41f4b71Sopenharmony_ci``` 1353e41f4b71Sopenharmony_ci 1354e41f4b71Sopenharmony_ci## addPrinters 1355e41f4b71Sopenharmony_ci 1356e41f4b71Sopenharmony_ciaddPrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void 1357e41f4b71Sopenharmony_ci 1358e41f4b71Sopenharmony_ci添加打印机,使用callback异步回调。 1359e41f4b71Sopenharmony_ci 1360e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1361e41f4b71Sopenharmony_ci 1362e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1363e41f4b71Sopenharmony_ci 1364e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1365e41f4b71Sopenharmony_ci 1366e41f4b71Sopenharmony_ci**参数:** 1367e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1368e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1369e41f4b71Sopenharmony_ci| printers | Array<PrinterInfo> | 是 | 表示新到达的打印机列表 | 1370e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步添加打印机之后的回调 | 1371e41f4b71Sopenharmony_ci 1372e41f4b71Sopenharmony_ci**错误码:** 1373e41f4b71Sopenharmony_ci 1374e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1375e41f4b71Sopenharmony_ci 1376e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1377e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1378e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1379e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1380e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1381e41f4b71Sopenharmony_ci 1382e41f4b71Sopenharmony_ci**示例:** 1383e41f4b71Sopenharmony_ci 1384e41f4b71Sopenharmony_ci```ts 1385e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1386e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1387e41f4b71Sopenharmony_ci 1388e41f4b71Sopenharmony_cilet printerInfo : print.PrinterInfo = { 1389e41f4b71Sopenharmony_ci printerId : '3232', 1390e41f4b71Sopenharmony_ci printerName : 'hhhhh', 1391e41f4b71Sopenharmony_ci printerState : 0, 1392e41f4b71Sopenharmony_ci printerIcon : 12, 1393e41f4b71Sopenharmony_ci description : 'str', 1394e41f4b71Sopenharmony_ci capability : undefined, 1395e41f4b71Sopenharmony_ci options : 'opt' 1396e41f4b71Sopenharmony_ci}; 1397e41f4b71Sopenharmony_ciprint.addPrinters([printerInfo], (err: BusinessError, data : void) => { 1398e41f4b71Sopenharmony_ci if (err) { 1399e41f4b71Sopenharmony_ci console.log('addPrinters failed, because : ' + JSON.stringify(err)); 1400e41f4b71Sopenharmony_ci } else { 1401e41f4b71Sopenharmony_ci console.log('addPrinters success, data : ' + JSON.stringify(data)); 1402e41f4b71Sopenharmony_ci } 1403e41f4b71Sopenharmony_ci}) 1404e41f4b71Sopenharmony_ci``` 1405e41f4b71Sopenharmony_ci 1406e41f4b71Sopenharmony_ci## addPrinters 1407e41f4b71Sopenharmony_ci 1408e41f4b71Sopenharmony_ciaddPrinters(printers: Array<PrinterInfo>): Promise<void> 1409e41f4b71Sopenharmony_ci 1410e41f4b71Sopenharmony_ci添加打印机,使用Promise异步回调。 1411e41f4b71Sopenharmony_ci 1412e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1413e41f4b71Sopenharmony_ci 1414e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1415e41f4b71Sopenharmony_ci 1416e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1417e41f4b71Sopenharmony_ci 1418e41f4b71Sopenharmony_ci**参数:** 1419e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1420e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1421e41f4b71Sopenharmony_ci| printers | Array<PrinterInfo> | 是 | 表示新到达的打印机列表 | 1422e41f4b71Sopenharmony_ci 1423e41f4b71Sopenharmony_ci**返回值:** 1424e41f4b71Sopenharmony_ci| **类型** | **说明** | 1425e41f4b71Sopenharmony_ci| -------- | -------- | 1426e41f4b71Sopenharmony_ci| Promise<void> | 添加打印机完成结果 | 1427e41f4b71Sopenharmony_ci 1428e41f4b71Sopenharmony_ci**错误码:** 1429e41f4b71Sopenharmony_ci 1430e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1431e41f4b71Sopenharmony_ci 1432e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1433e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1434e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1435e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1436e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1437e41f4b71Sopenharmony_ci 1438e41f4b71Sopenharmony_ci**示例:** 1439e41f4b71Sopenharmony_ci 1440e41f4b71Sopenharmony_ci```ts 1441e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1442e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1443e41f4b71Sopenharmony_ci 1444e41f4b71Sopenharmony_cilet printerInfo : print.PrinterInfo = { 1445e41f4b71Sopenharmony_ci printerId : '3232', 1446e41f4b71Sopenharmony_ci printerName : 'hhhhh', 1447e41f4b71Sopenharmony_ci printerState : 0, 1448e41f4b71Sopenharmony_ci printerIcon : 12, 1449e41f4b71Sopenharmony_ci description : 'str', 1450e41f4b71Sopenharmony_ci capability : undefined, 1451e41f4b71Sopenharmony_ci options : 'opt' 1452e41f4b71Sopenharmony_ci}; 1453e41f4b71Sopenharmony_ciprint.addPrinters([printerInfo]).then((data : void) => { 1454e41f4b71Sopenharmony_ci console.log('add printers data : ' + JSON.stringify(data)); 1455e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 1456e41f4b71Sopenharmony_ci console.log('add printers error : ' + JSON.stringify(error)); 1457e41f4b71Sopenharmony_ci}) 1458e41f4b71Sopenharmony_ci``` 1459e41f4b71Sopenharmony_ci 1460e41f4b71Sopenharmony_ci## removePrinters 1461e41f4b71Sopenharmony_ci 1462e41f4b71Sopenharmony_ciremovePrinters(printerIds: Array<string>, callback: AsyncCallback<void>): void 1463e41f4b71Sopenharmony_ci 1464e41f4b71Sopenharmony_ci移除打印机,使用callback异步回调。 1465e41f4b71Sopenharmony_ci 1466e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1467e41f4b71Sopenharmony_ci 1468e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1469e41f4b71Sopenharmony_ci 1470e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1471e41f4b71Sopenharmony_ci 1472e41f4b71Sopenharmony_ci**参数:** 1473e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1474e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1475e41f4b71Sopenharmony_ci| printerIds | Array<string> | 是 | 表示需移除的打印机列表 | 1476e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步移除打印机之后的回调 | 1477e41f4b71Sopenharmony_ci 1478e41f4b71Sopenharmony_ci**错误码:** 1479e41f4b71Sopenharmony_ci 1480e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1481e41f4b71Sopenharmony_ci 1482e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1483e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1484e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1485e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1486e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1487e41f4b71Sopenharmony_ci 1488e41f4b71Sopenharmony_ci**示例:** 1489e41f4b71Sopenharmony_ci 1490e41f4b71Sopenharmony_ci```ts 1491e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1492e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1493e41f4b71Sopenharmony_ci 1494e41f4b71Sopenharmony_cilet printerId : string = '1212'; 1495e41f4b71Sopenharmony_ciprint.removePrinters([printerId], (err: BusinessError, data : void) => { 1496e41f4b71Sopenharmony_ci if (err) { 1497e41f4b71Sopenharmony_ci console.log('removePrinters failed, because : ' + JSON.stringify(err)); 1498e41f4b71Sopenharmony_ci } else { 1499e41f4b71Sopenharmony_ci console.log('removePrinters success, data : ' + JSON.stringify(data)); 1500e41f4b71Sopenharmony_ci } 1501e41f4b71Sopenharmony_ci}) 1502e41f4b71Sopenharmony_ci``` 1503e41f4b71Sopenharmony_ci 1504e41f4b71Sopenharmony_ci## removePrinters 1505e41f4b71Sopenharmony_ci 1506e41f4b71Sopenharmony_ciremovePrinters(printerIds: Array<string>): Promise<void> 1507e41f4b71Sopenharmony_ci 1508e41f4b71Sopenharmony_ci移除打印机,使用Promise异步回调。 1509e41f4b71Sopenharmony_ci 1510e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1511e41f4b71Sopenharmony_ci 1512e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1513e41f4b71Sopenharmony_ci 1514e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1515e41f4b71Sopenharmony_ci 1516e41f4b71Sopenharmony_ci**参数:** 1517e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1518e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1519e41f4b71Sopenharmony_ci| printerIds | Array<string> | 是 | 表示需移除的打印机列表 | 1520e41f4b71Sopenharmony_ci 1521e41f4b71Sopenharmony_ci**返回值:** 1522e41f4b71Sopenharmony_ci| **类型** | **说明** | 1523e41f4b71Sopenharmony_ci| -------- | -------- | 1524e41f4b71Sopenharmony_ci| Promise<void> | 移除打印机完成结果 | 1525e41f4b71Sopenharmony_ci 1526e41f4b71Sopenharmony_ci**错误码:** 1527e41f4b71Sopenharmony_ci 1528e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1529e41f4b71Sopenharmony_ci 1530e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1531e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1532e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1533e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1534e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1535e41f4b71Sopenharmony_ci 1536e41f4b71Sopenharmony_ci**示例:** 1537e41f4b71Sopenharmony_ci 1538e41f4b71Sopenharmony_ci```ts 1539e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1540e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1541e41f4b71Sopenharmony_ci 1542e41f4b71Sopenharmony_cilet printerId : string = '1212'; 1543e41f4b71Sopenharmony_ciprint.removePrinters([printerId]).then((data : void) => { 1544e41f4b71Sopenharmony_ci console.log('remove printers data : ' + JSON.stringify(data)); 1545e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 1546e41f4b71Sopenharmony_ci console.log('remove printers error : ' + JSON.stringify(error)); 1547e41f4b71Sopenharmony_ci}) 1548e41f4b71Sopenharmony_ci``` 1549e41f4b71Sopenharmony_ci 1550e41f4b71Sopenharmony_ci## updatePrinters 1551e41f4b71Sopenharmony_ci 1552e41f4b71Sopenharmony_ciupdatePrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void 1553e41f4b71Sopenharmony_ci 1554e41f4b71Sopenharmony_ci更新特定打印机的信息,使用callback异步回调。 1555e41f4b71Sopenharmony_ci 1556e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1557e41f4b71Sopenharmony_ci 1558e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1559e41f4b71Sopenharmony_ci 1560e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1561e41f4b71Sopenharmony_ci 1562e41f4b71Sopenharmony_ci**参数:** 1563e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1564e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1565e41f4b71Sopenharmony_ci| printers | Array<PrinterInfo> | 是 | 表示待更新的打印机列表 | 1566e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步更新打印机信息之后的回调 | 1567e41f4b71Sopenharmony_ci 1568e41f4b71Sopenharmony_ci**错误码:** 1569e41f4b71Sopenharmony_ci 1570e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1571e41f4b71Sopenharmony_ci 1572e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1573e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1574e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1575e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1576e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1577e41f4b71Sopenharmony_ci 1578e41f4b71Sopenharmony_ci**示例:** 1579e41f4b71Sopenharmony_ci 1580e41f4b71Sopenharmony_ci```ts 1581e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1582e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1583e41f4b71Sopenharmony_ci 1584e41f4b71Sopenharmony_cilet printerInfo : print.PrinterInfo = { 1585e41f4b71Sopenharmony_ci printerId : '3232', 1586e41f4b71Sopenharmony_ci printerName : 'hhhhh', 1587e41f4b71Sopenharmony_ci printerState : 0, 1588e41f4b71Sopenharmony_ci printerIcon : 12, 1589e41f4b71Sopenharmony_ci description : 'str', 1590e41f4b71Sopenharmony_ci capability : undefined, 1591e41f4b71Sopenharmony_ci options : 'opt' 1592e41f4b71Sopenharmony_ci}; 1593e41f4b71Sopenharmony_ciprint.updatePrinters([printerInfo], (err: BusinessError, data : void) => { 1594e41f4b71Sopenharmony_ci if (err) { 1595e41f4b71Sopenharmony_ci console.log('updataPrinters failed, because : ' + JSON.stringify(err)); 1596e41f4b71Sopenharmony_ci } else { 1597e41f4b71Sopenharmony_ci console.log('updataPrinters success, data : ' + JSON.stringify(data)); 1598e41f4b71Sopenharmony_ci } 1599e41f4b71Sopenharmony_ci}) 1600e41f4b71Sopenharmony_ci``` 1601e41f4b71Sopenharmony_ci 1602e41f4b71Sopenharmony_ci## updatePrinters 1603e41f4b71Sopenharmony_ci 1604e41f4b71Sopenharmony_ciupdatePrinters(printers: Array<PrinterInfo>): Promise<void> 1605e41f4b71Sopenharmony_ci 1606e41f4b71Sopenharmony_ci更新特定打印机的信息,使用Promise异步回调。 1607e41f4b71Sopenharmony_ci 1608e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1609e41f4b71Sopenharmony_ci 1610e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1611e41f4b71Sopenharmony_ci 1612e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1613e41f4b71Sopenharmony_ci 1614e41f4b71Sopenharmony_ci**参数:** 1615e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1616e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1617e41f4b71Sopenharmony_ci| printers | Array<PrinterInfo> | 是 | 表示待更新的打印机列表 | 1618e41f4b71Sopenharmony_ci 1619e41f4b71Sopenharmony_ci**返回值:** 1620e41f4b71Sopenharmony_ci| **类型** | **说明** | 1621e41f4b71Sopenharmony_ci| -------- | -------- | 1622e41f4b71Sopenharmony_ci| Promise<void> | 更新打印机完成结果 | 1623e41f4b71Sopenharmony_ci 1624e41f4b71Sopenharmony_ci**错误码:** 1625e41f4b71Sopenharmony_ci 1626e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1627e41f4b71Sopenharmony_ci 1628e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1629e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1630e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1631e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1632e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1633e41f4b71Sopenharmony_ci 1634e41f4b71Sopenharmony_ci**示例:** 1635e41f4b71Sopenharmony_ci 1636e41f4b71Sopenharmony_ci```ts 1637e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1638e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1639e41f4b71Sopenharmony_ci 1640e41f4b71Sopenharmony_cilet printerInfo : print.PrinterInfo = { 1641e41f4b71Sopenharmony_ci printerId : '3232', 1642e41f4b71Sopenharmony_ci printerName : 'hhhhh', 1643e41f4b71Sopenharmony_ci printerState : 0, 1644e41f4b71Sopenharmony_ci printerIcon : 12, 1645e41f4b71Sopenharmony_ci description : 'str', 1646e41f4b71Sopenharmony_ci capability : undefined, 1647e41f4b71Sopenharmony_ci options : 'opt' 1648e41f4b71Sopenharmony_ci}; 1649e41f4b71Sopenharmony_ciprint.updatePrinters([printerInfo]).then((data : void) => { 1650e41f4b71Sopenharmony_ci console.log('update printers data : ' + JSON.stringify(data)); 1651e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 1652e41f4b71Sopenharmony_ci console.log('update printers error : ' + JSON.stringify(error)); 1653e41f4b71Sopenharmony_ci}) 1654e41f4b71Sopenharmony_ci``` 1655e41f4b71Sopenharmony_ci 1656e41f4b71Sopenharmony_ci## updatePrinterState 1657e41f4b71Sopenharmony_ci 1658e41f4b71Sopenharmony_ciupdatePrinterState(printerId: string, state: PrinterState, callback: AsyncCallback<void>): void 1659e41f4b71Sopenharmony_ci 1660e41f4b71Sopenharmony_ci更新打印机状态,使用callback异步回调。 1661e41f4b71Sopenharmony_ci 1662e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1663e41f4b71Sopenharmony_ci 1664e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1665e41f4b71Sopenharmony_ci 1666e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1667e41f4b71Sopenharmony_ci 1668e41f4b71Sopenharmony_ci**参数:** 1669e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1670e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1671e41f4b71Sopenharmony_ci| printerId | string | 是 | 表示打印机ID | 1672e41f4b71Sopenharmony_ci| state | PrinterState | 是 | 表示打印机状态 | 1673e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步更新打印机状态之后的回调 | 1674e41f4b71Sopenharmony_ci 1675e41f4b71Sopenharmony_ci**错误码:** 1676e41f4b71Sopenharmony_ci 1677e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1678e41f4b71Sopenharmony_ci 1679e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1680e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1681e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1682e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1683e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1684e41f4b71Sopenharmony_ci 1685e41f4b71Sopenharmony_ci**示例:** 1686e41f4b71Sopenharmony_ci 1687e41f4b71Sopenharmony_ci```ts 1688e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1689e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1690e41f4b71Sopenharmony_ci 1691e41f4b71Sopenharmony_cilet printerId : string = '1212'; 1692e41f4b71Sopenharmony_cilet state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED; 1693e41f4b71Sopenharmony_ciprint.updatePrinterState(printerId, state, (err: BusinessError, data : void) => { 1694e41f4b71Sopenharmony_ci if (err) { 1695e41f4b71Sopenharmony_ci console.log('updataPrinterState failed, because : ' + JSON.stringify(err)); 1696e41f4b71Sopenharmony_ci } else { 1697e41f4b71Sopenharmony_ci console.log('updataPrinterState success, data : ' + JSON.stringify(data)); 1698e41f4b71Sopenharmony_ci } 1699e41f4b71Sopenharmony_ci}) 1700e41f4b71Sopenharmony_ci``` 1701e41f4b71Sopenharmony_ci 1702e41f4b71Sopenharmony_ci## updatePrinterState 1703e41f4b71Sopenharmony_ci 1704e41f4b71Sopenharmony_ciupdatePrinterState(printerId: string, state: PrinterState): Promise<void> 1705e41f4b71Sopenharmony_ci 1706e41f4b71Sopenharmony_ci更新打印机状态,使用Promise异步回调。 1707e41f4b71Sopenharmony_ci 1708e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1709e41f4b71Sopenharmony_ci 1710e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1711e41f4b71Sopenharmony_ci 1712e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1713e41f4b71Sopenharmony_ci 1714e41f4b71Sopenharmony_ci**参数:** 1715e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1716e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1717e41f4b71Sopenharmony_ci| printerId | string | 是 | 表示打印机ID | 1718e41f4b71Sopenharmony_ci| state | PrinterState | 是 | 表示打印机状态 | 1719e41f4b71Sopenharmony_ci 1720e41f4b71Sopenharmony_ci**返回值:** 1721e41f4b71Sopenharmony_ci| **类型** | **说明** | 1722e41f4b71Sopenharmony_ci| -------- | -------- | 1723e41f4b71Sopenharmony_ci| Promise<void> | 更新打印机状态完成结果 | 1724e41f4b71Sopenharmony_ci 1725e41f4b71Sopenharmony_ci**错误码:** 1726e41f4b71Sopenharmony_ci 1727e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1728e41f4b71Sopenharmony_ci 1729e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1730e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1731e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1732e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1733e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1734e41f4b71Sopenharmony_ci 1735e41f4b71Sopenharmony_ci**示例:** 1736e41f4b71Sopenharmony_ci 1737e41f4b71Sopenharmony_ci```ts 1738e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1739e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1740e41f4b71Sopenharmony_ci 1741e41f4b71Sopenharmony_cilet printerId : string = '1212'; 1742e41f4b71Sopenharmony_cilet state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED; 1743e41f4b71Sopenharmony_ciprint.updatePrinterState(printerId, state).then((data : void) => { 1744e41f4b71Sopenharmony_ci console.log('update printer state data : ' + JSON.stringify(data)); 1745e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 1746e41f4b71Sopenharmony_ci console.log('update printer state error : ' + JSON.stringify(error)); 1747e41f4b71Sopenharmony_ci}) 1748e41f4b71Sopenharmony_ci``` 1749e41f4b71Sopenharmony_ci 1750e41f4b71Sopenharmony_ci## updatePrintJobState 1751e41f4b71Sopenharmony_ci 1752e41f4b71Sopenharmony_ciupdatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState, callback: AsyncCallback<void>): void 1753e41f4b71Sopenharmony_ci 1754e41f4b71Sopenharmony_ci更新打印任务状态,使用callback异步回调。 1755e41f4b71Sopenharmony_ci 1756e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1757e41f4b71Sopenharmony_ci 1758e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1759e41f4b71Sopenharmony_ci 1760e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1761e41f4b71Sopenharmony_ci 1762e41f4b71Sopenharmony_ci**参数:** 1763e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1764e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1765e41f4b71Sopenharmony_ci| jobId | string | 是 | 表示打印任务ID | 1766e41f4b71Sopenharmony_ci| state | PrintJobState | 是 | 表示打印任务状态 | 1767e41f4b71Sopenharmony_ci| subState | PrintJobSubState | 是 | 表示打印任务子状态 | 1768e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步更新打印任务状态之后的回调 | 1769e41f4b71Sopenharmony_ci 1770e41f4b71Sopenharmony_ci**错误码:** 1771e41f4b71Sopenharmony_ci 1772e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1773e41f4b71Sopenharmony_ci 1774e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1775e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1776e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1777e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1778e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1779e41f4b71Sopenharmony_ci 1780e41f4b71Sopenharmony_ci**示例:** 1781e41f4b71Sopenharmony_ci 1782e41f4b71Sopenharmony_ci```ts 1783e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1784e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1785e41f4b71Sopenharmony_ci 1786e41f4b71Sopenharmony_cilet jobId : string = '3434'; 1787e41f4b71Sopenharmony_cilet state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE; 1788e41f4b71Sopenharmony_cilet subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS; 1789e41f4b71Sopenharmony_ciprint.updatePrintJobState(jobId, state, subState, (err: BusinessError, data : void) => { 1790e41f4b71Sopenharmony_ci if (err) { 1791e41f4b71Sopenharmony_ci console.log('updataPrintJobState failed, because : ' + JSON.stringify(err)); 1792e41f4b71Sopenharmony_ci } else { 1793e41f4b71Sopenharmony_ci console.log('updatePrintJobState success, data : ' + JSON.stringify(data)); 1794e41f4b71Sopenharmony_ci } 1795e41f4b71Sopenharmony_ci}) 1796e41f4b71Sopenharmony_ci``` 1797e41f4b71Sopenharmony_ci 1798e41f4b71Sopenharmony_ci## updatePrintJobState 1799e41f4b71Sopenharmony_ci 1800e41f4b71Sopenharmony_ciupdatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState): Promise<void> 1801e41f4b71Sopenharmony_ci 1802e41f4b71Sopenharmony_ci更新打印任务状态,使用Promise异步回调。 1803e41f4b71Sopenharmony_ci 1804e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1805e41f4b71Sopenharmony_ci 1806e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1807e41f4b71Sopenharmony_ci 1808e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1809e41f4b71Sopenharmony_ci 1810e41f4b71Sopenharmony_ci**参数:** 1811e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1812e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1813e41f4b71Sopenharmony_ci| jobId | string | 是 | 表示打印任务ID | 1814e41f4b71Sopenharmony_ci| state | PrintJobState | 是 | 表示打印任务状态 | 1815e41f4b71Sopenharmony_ci| subState | PrintJobSubState | 是 | 表示打印任务子状态 | 1816e41f4b71Sopenharmony_ci 1817e41f4b71Sopenharmony_ci**返回值:** 1818e41f4b71Sopenharmony_ci| **类型** | **说明** | 1819e41f4b71Sopenharmony_ci| -------- | -------- | 1820e41f4b71Sopenharmony_ci| Promise<void> | 更新打印任务状态完成结果 | 1821e41f4b71Sopenharmony_ci 1822e41f4b71Sopenharmony_ci**错误码:** 1823e41f4b71Sopenharmony_ci 1824e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1825e41f4b71Sopenharmony_ci 1826e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1827e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1828e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1829e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1830e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1831e41f4b71Sopenharmony_ci 1832e41f4b71Sopenharmony_ci**示例:** 1833e41f4b71Sopenharmony_ci 1834e41f4b71Sopenharmony_ci```ts 1835e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1836e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1837e41f4b71Sopenharmony_ci 1838e41f4b71Sopenharmony_cilet jobId : string = '3434'; 1839e41f4b71Sopenharmony_cilet state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE; 1840e41f4b71Sopenharmony_cilet subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS; 1841e41f4b71Sopenharmony_ciprint.updatePrintJobState(jobId, state, subState).then((data : void) => { 1842e41f4b71Sopenharmony_ci console.log('update print job state data : ' + JSON.stringify(data)); 1843e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 1844e41f4b71Sopenharmony_ci console.log('update print job state error : ' + JSON.stringify(error)); 1845e41f4b71Sopenharmony_ci}) 1846e41f4b71Sopenharmony_ci``` 1847e41f4b71Sopenharmony_ci 1848e41f4b71Sopenharmony_ci## updateExtensionInfo 1849e41f4b71Sopenharmony_ci 1850e41f4b71Sopenharmony_ciupdateExtensionInfo(info: string, callback: AsyncCallback<void>): void 1851e41f4b71Sopenharmony_ci 1852e41f4b71Sopenharmony_ci更新打印扩展状态,使用callback异步回调。 1853e41f4b71Sopenharmony_ci 1854e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1855e41f4b71Sopenharmony_ci 1856e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1857e41f4b71Sopenharmony_ci 1858e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1859e41f4b71Sopenharmony_ci 1860e41f4b71Sopenharmony_ci**参数:** 1861e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1862e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1863e41f4b71Sopenharmony_ci| info | string | 是 | 表示打印扩展变更信息 | 1864e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步更新打印扩展状态之后的回调 | 1865e41f4b71Sopenharmony_ci 1866e41f4b71Sopenharmony_ci**错误码:** 1867e41f4b71Sopenharmony_ci 1868e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1869e41f4b71Sopenharmony_ci 1870e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1871e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1872e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1873e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1874e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1875e41f4b71Sopenharmony_ci 1876e41f4b71Sopenharmony_ci**示例:** 1877e41f4b71Sopenharmony_ci 1878e41f4b71Sopenharmony_ci```ts 1879e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1880e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1881e41f4b71Sopenharmony_ci 1882e41f4b71Sopenharmony_cilet info : string = 'WIFI_INACTIVE'; 1883e41f4b71Sopenharmony_ciprint.updateExtensionInfo(info, (err: BusinessError, data : void) => { 1884e41f4b71Sopenharmony_ci if (err) { 1885e41f4b71Sopenharmony_ci console.log('updateExtensionInfo failed, because : ' + JSON.stringify(err)); 1886e41f4b71Sopenharmony_ci } else { 1887e41f4b71Sopenharmony_ci console.log('updateExtensionInfo success, data : ' + JSON.stringify(data)); 1888e41f4b71Sopenharmony_ci } 1889e41f4b71Sopenharmony_ci}) 1890e41f4b71Sopenharmony_ci``` 1891e41f4b71Sopenharmony_ci 1892e41f4b71Sopenharmony_ci## updateExtensionInfo 1893e41f4b71Sopenharmony_ci 1894e41f4b71Sopenharmony_ciupdateExtensionInfo(info: string): Promise<void> 1895e41f4b71Sopenharmony_ci 1896e41f4b71Sopenharmony_ci更新打印扩展状态,使用Promise异步回调。 1897e41f4b71Sopenharmony_ci 1898e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1899e41f4b71Sopenharmony_ci 1900e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1901e41f4b71Sopenharmony_ci 1902e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1903e41f4b71Sopenharmony_ci 1904e41f4b71Sopenharmony_ci**参数:** 1905e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1906e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1907e41f4b71Sopenharmony_ci| info | string | 是 | 表示打印扩展变更信息 | 1908e41f4b71Sopenharmony_ci 1909e41f4b71Sopenharmony_ci**返回值:** 1910e41f4b71Sopenharmony_ci| **类型** | **说明** | 1911e41f4b71Sopenharmony_ci| -------- | -------- | 1912e41f4b71Sopenharmony_ci| Promise<void> | 更新打印扩展状态完成结果 | 1913e41f4b71Sopenharmony_ci 1914e41f4b71Sopenharmony_ci**错误码:** 1915e41f4b71Sopenharmony_ci 1916e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1917e41f4b71Sopenharmony_ci 1918e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1919e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1920e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1921e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1922e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1923e41f4b71Sopenharmony_ci 1924e41f4b71Sopenharmony_ci**示例:** 1925e41f4b71Sopenharmony_ci 1926e41f4b71Sopenharmony_ci```ts 1927e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1928e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1929e41f4b71Sopenharmony_ci 1930e41f4b71Sopenharmony_cilet info : string = 'WIFI_INACTIVE'; 1931e41f4b71Sopenharmony_ciprint.updateExtensionInfo(info).then((data : void) => { 1932e41f4b71Sopenharmony_ci console.log('update print job state data : ' + JSON.stringify(data)); 1933e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 1934e41f4b71Sopenharmony_ci console.log('update print job state error : ' + JSON.stringify(error)); 1935e41f4b71Sopenharmony_ci}) 1936e41f4b71Sopenharmony_ci``` 1937e41f4b71Sopenharmony_ci 1938e41f4b71Sopenharmony_ci## queryAllPrintJobs<sup>(deprecated)</sup> 1939e41f4b71Sopenharmony_ci 1940e41f4b71Sopenharmony_ci> 从API version 10开始支持,从API version 11开始废弃。 1941e41f4b71Sopenharmony_ci> 建议使用[queryPrintJobList](#queryprintjoblist11)替代。 1942e41f4b71Sopenharmony_ci 1943e41f4b71Sopenharmony_ciqueryAllPrintJobs(callback: AsyncCallback<void>): void 1944e41f4b71Sopenharmony_ci 1945e41f4b71Sopenharmony_ci查询所有打印任务,使用callback异步回调。 1946e41f4b71Sopenharmony_ci 1947e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1948e41f4b71Sopenharmony_ci 1949e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1950e41f4b71Sopenharmony_ci 1951e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1952e41f4b71Sopenharmony_ci 1953e41f4b71Sopenharmony_ci**参数:** 1954e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 1955e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1956e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步查询所有打印任务之后的回调 | 1957e41f4b71Sopenharmony_ci 1958e41f4b71Sopenharmony_ci**错误码:** 1959e41f4b71Sopenharmony_ci 1960e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 1961e41f4b71Sopenharmony_ci 1962e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1963e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 1964e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1965e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1966e41f4b71Sopenharmony_ci 1967e41f4b71Sopenharmony_ci**示例:** 1968e41f4b71Sopenharmony_ci 1969e41f4b71Sopenharmony_ci```ts 1970e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 1971e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1972e41f4b71Sopenharmony_ci 1973e41f4b71Sopenharmony_ciprint.queryAllPrintJobs((err: BusinessError, data : void) => { 1974e41f4b71Sopenharmony_ci if (err) { 1975e41f4b71Sopenharmony_ci console.log('queryAllPrintJobs failed, because : ' + JSON.stringify(err)); 1976e41f4b71Sopenharmony_ci } else { 1977e41f4b71Sopenharmony_ci console.log('queryAllPrintJobs success, data : ' + JSON.stringify(data)); 1978e41f4b71Sopenharmony_ci } 1979e41f4b71Sopenharmony_ci}) 1980e41f4b71Sopenharmony_ci``` 1981e41f4b71Sopenharmony_ci 1982e41f4b71Sopenharmony_ci## queryAllPrintJobs<sup>(deprecated)</sup> 1983e41f4b71Sopenharmony_ci 1984e41f4b71Sopenharmony_ci> 从API version 10开始支持,从API version 11开始废弃。 1985e41f4b71Sopenharmony_ci> 建议使用[queryPrintJobList](#queryprintjoblist11-1)替代。 1986e41f4b71Sopenharmony_ci 1987e41f4b71Sopenharmony_ciqueryAllPrintJobs(): Promise<void> 1988e41f4b71Sopenharmony_ci 1989e41f4b71Sopenharmony_ci查询所有打印任务,使用Promise异步回调。 1990e41f4b71Sopenharmony_ci 1991e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 1992e41f4b71Sopenharmony_ci 1993e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1994e41f4b71Sopenharmony_ci 1995e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 1996e41f4b71Sopenharmony_ci 1997e41f4b71Sopenharmony_ci**返回值:** 1998e41f4b71Sopenharmony_ci| **类型** | **说明** | 1999e41f4b71Sopenharmony_ci| -------- | -------- | 2000e41f4b71Sopenharmony_ci| Promise<void> | 查询所有打印任务完成结果 | 2001e41f4b71Sopenharmony_ci 2002e41f4b71Sopenharmony_ci**错误码:** 2003e41f4b71Sopenharmony_ci 2004e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2005e41f4b71Sopenharmony_ci 2006e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2007e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2008e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2009e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2010e41f4b71Sopenharmony_ci 2011e41f4b71Sopenharmony_ci**示例:** 2012e41f4b71Sopenharmony_ci 2013e41f4b71Sopenharmony_ci```ts 2014e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2015e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2016e41f4b71Sopenharmony_ci 2017e41f4b71Sopenharmony_ciprint.queryAllPrintJobs().then((data : void) => { 2018e41f4b71Sopenharmony_ci console.log('queryAllPrintJobs success, data : ' + JSON.stringify(data)); 2019e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 2020e41f4b71Sopenharmony_ci console.log('queryAllPrintJobs failed, error : ' + JSON.stringify(error)); 2021e41f4b71Sopenharmony_ci}) 2022e41f4b71Sopenharmony_ci``` 2023e41f4b71Sopenharmony_ci 2024e41f4b71Sopenharmony_ci## queryPrintJobList<sup>11+</sup> 2025e41f4b71Sopenharmony_ci 2026e41f4b71Sopenharmony_ciqueryPrintJobList(callback: AsyncCallback<Array<PrintJob>>): void 2027e41f4b71Sopenharmony_ci 2028e41f4b71Sopenharmony_ci查询所有打印任务,使用callback异步回调。 2029e41f4b71Sopenharmony_ci 2030e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 2031e41f4b71Sopenharmony_ci 2032e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 2033e41f4b71Sopenharmony_ci 2034e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 2035e41f4b71Sopenharmony_ci 2036e41f4b71Sopenharmony_ci**参数:** 2037e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 2038e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2039e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<PrintJob>> | 是 | 异步查询所有打印任务之后的回调 | 2040e41f4b71Sopenharmony_ci 2041e41f4b71Sopenharmony_ci**错误码:** 2042e41f4b71Sopenharmony_ci 2043e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2044e41f4b71Sopenharmony_ci 2045e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2046e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2047e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2048e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2049e41f4b71Sopenharmony_ci 2050e41f4b71Sopenharmony_ci**示例:** 2051e41f4b71Sopenharmony_ci 2052e41f4b71Sopenharmony_ci```ts 2053e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2054e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2055e41f4b71Sopenharmony_ci 2056e41f4b71Sopenharmony_ciprint.queryPrintJobList((err: BusinessError, printJobs : print.PrintJob[]) => { 2057e41f4b71Sopenharmony_ci if (err) { 2058e41f4b71Sopenharmony_ci console.log('queryPrintJobList failed, because : ' + JSON.stringify(err)); 2059e41f4b71Sopenharmony_ci } else { 2060e41f4b71Sopenharmony_ci console.log('queryPrintJobList success, data : ' + JSON.stringify(printJobs)); 2061e41f4b71Sopenharmony_ci } 2062e41f4b71Sopenharmony_ci}) 2063e41f4b71Sopenharmony_ci``` 2064e41f4b71Sopenharmony_ci 2065e41f4b71Sopenharmony_ci## queryPrintJobList<sup>11+</sup> 2066e41f4b71Sopenharmony_ci 2067e41f4b71Sopenharmony_ciqueryPrintJobList(): Promise<Array<PrintJob>> 2068e41f4b71Sopenharmony_ci 2069e41f4b71Sopenharmony_ci查询所有打印任务,使用Promise异步回调。 2070e41f4b71Sopenharmony_ci 2071e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 2072e41f4b71Sopenharmony_ci 2073e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 2074e41f4b71Sopenharmony_ci 2075e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 2076e41f4b71Sopenharmony_ci 2077e41f4b71Sopenharmony_ci**返回值:** 2078e41f4b71Sopenharmony_ci| **类型** | **说明** | 2079e41f4b71Sopenharmony_ci| -------- | -------- | 2080e41f4b71Sopenharmony_ci| Promise<Array<PrintJob>> | 查询所有打印任务完成结果 | 2081e41f4b71Sopenharmony_ci 2082e41f4b71Sopenharmony_ci**错误码:** 2083e41f4b71Sopenharmony_ci 2084e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2085e41f4b71Sopenharmony_ci 2086e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2087e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2088e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2089e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2090e41f4b71Sopenharmony_ci 2091e41f4b71Sopenharmony_ci**示例:** 2092e41f4b71Sopenharmony_ci 2093e41f4b71Sopenharmony_ci```ts 2094e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2095e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2096e41f4b71Sopenharmony_ci 2097e41f4b71Sopenharmony_ciprint.queryPrintJobList().then((printJobs : print.PrintJob[]) => { 2098e41f4b71Sopenharmony_ci console.log('queryPrintJobList success, data : ' + JSON.stringify(printJobs)); 2099e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 2100e41f4b71Sopenharmony_ci console.log('queryPrintJobList failed, error : ' + JSON.stringify(error)); 2101e41f4b71Sopenharmony_ci}) 2102e41f4b71Sopenharmony_ci``` 2103e41f4b71Sopenharmony_ci 2104e41f4b71Sopenharmony_ci## queryPrintJobById<sup>11+</sup> 2105e41f4b71Sopenharmony_ci 2106e41f4b71Sopenharmony_ciqueryPrintJobById(jobId: string, callback: AsyncCallback<PrintJob>): void 2107e41f4b71Sopenharmony_ci 2108e41f4b71Sopenharmony_ci按打印任务ID查询打印任务,使用callback异步回调。 2109e41f4b71Sopenharmony_ci 2110e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 2111e41f4b71Sopenharmony_ci 2112e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 2113e41f4b71Sopenharmony_ci 2114e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 2115e41f4b71Sopenharmony_ci 2116e41f4b71Sopenharmony_ci**参数:** 2117e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 2118e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2119e41f4b71Sopenharmony_ci| jobId | string | 是 | 表示打印任务ID | 2120e41f4b71Sopenharmony_ci| callback | AsyncCallback<PrintJob> | 是 | 异步按打印任务ID查询打印任务之后的回调 | 2121e41f4b71Sopenharmony_ci 2122e41f4b71Sopenharmony_ci**错误码:** 2123e41f4b71Sopenharmony_ci 2124e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2125e41f4b71Sopenharmony_ci 2126e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2127e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2128e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2129e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2130e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 2131e41f4b71Sopenharmony_ci 2132e41f4b71Sopenharmony_ci**示例:** 2133e41f4b71Sopenharmony_ci 2134e41f4b71Sopenharmony_ci```ts 2135e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2136e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2137e41f4b71Sopenharmony_ci 2138e41f4b71Sopenharmony_cilet jobId : string = '1'; 2139e41f4b71Sopenharmony_ciprint.queryPrintJobById(jobId, (err: BusinessError, printJob : print.PrintJob) => { 2140e41f4b71Sopenharmony_ci if (err) { 2141e41f4b71Sopenharmony_ci console.log('queryPrintJobById failed, because : ' + JSON.stringify(err)); 2142e41f4b71Sopenharmony_ci } else { 2143e41f4b71Sopenharmony_ci console.log('queryPrintJobById success, data : ' + JSON.stringify(printJob)); 2144e41f4b71Sopenharmony_ci } 2145e41f4b71Sopenharmony_ci}) 2146e41f4b71Sopenharmony_ci``` 2147e41f4b71Sopenharmony_ci 2148e41f4b71Sopenharmony_ci## queryPrintJobById<sup>11+</sup> 2149e41f4b71Sopenharmony_ci 2150e41f4b71Sopenharmony_ciqueryPrintJobById(jobId: string): Promise<PrintJob> 2151e41f4b71Sopenharmony_ci 2152e41f4b71Sopenharmony_ci按打印任务ID查询打印任务,使用Promise异步回调。 2153e41f4b71Sopenharmony_ci 2154e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 2155e41f4b71Sopenharmony_ci 2156e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 2157e41f4b71Sopenharmony_ci 2158e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 2159e41f4b71Sopenharmony_ci 2160e41f4b71Sopenharmony_ci**参数:** 2161e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 2162e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2163e41f4b71Sopenharmony_ci| jobId | string | 是 | 表示打印任务ID | 2164e41f4b71Sopenharmony_ci 2165e41f4b71Sopenharmony_ci**返回值:** 2166e41f4b71Sopenharmony_ci| **类型** | **说明** | 2167e41f4b71Sopenharmony_ci| -------- | -------- | 2168e41f4b71Sopenharmony_ci| Promise<PrintJob> | 按打印任务ID查询打印任务完成结果 | 2169e41f4b71Sopenharmony_ci 2170e41f4b71Sopenharmony_ci**错误码:** 2171e41f4b71Sopenharmony_ci 2172e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2173e41f4b71Sopenharmony_ci 2174e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2175e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2176e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2177e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2178e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 2179e41f4b71Sopenharmony_ci 2180e41f4b71Sopenharmony_ci**示例:** 2181e41f4b71Sopenharmony_ci 2182e41f4b71Sopenharmony_ci```ts 2183e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2184e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2185e41f4b71Sopenharmony_ci 2186e41f4b71Sopenharmony_cilet jobId : string = '1'; 2187e41f4b71Sopenharmony_ciprint.queryPrintJobById(jobId).then((printJob : print.PrintJob) => { 2188e41f4b71Sopenharmony_ci console.log('queryPrintJobById data : ' + JSON.stringify(printJob)); 2189e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 2190e41f4b71Sopenharmony_ci console.log('queryPrintJobById error : ' + JSON.stringify(error)); 2191e41f4b71Sopenharmony_ci}) 2192e41f4b71Sopenharmony_ci``` 2193e41f4b71Sopenharmony_ci 2194e41f4b71Sopenharmony_ci## startGettingPrintFile<sup>11+</sup> 2195e41f4b71Sopenharmony_ci 2196e41f4b71Sopenharmony_cistartGettingPrintFile(jobId: string, printAttributes: PrintAttributes, fd: number, onFileStateChanged: Callback<PrintFileCreationState>): void 2197e41f4b71Sopenharmony_ci 2198e41f4b71Sopenharmony_ci开始获取打印文件,使用Callback异步回调。 2199e41f4b71Sopenharmony_ci 2200e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 2201e41f4b71Sopenharmony_ci 2202e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 2203e41f4b71Sopenharmony_ci 2204e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 2205e41f4b71Sopenharmony_ci 2206e41f4b71Sopenharmony_ci**参数:** 2207e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 2208e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2209e41f4b71Sopenharmony_ci| jobId | string | 是 | 表示打印任务ID | 2210e41f4b71Sopenharmony_ci| printAttributes | PrintAttributes | 是 | 表示打印参数 | 2211e41f4b71Sopenharmony_ci| fd | number | 是 | 表示打印文件描述符 | 2212e41f4b71Sopenharmony_ci| onFileStateChanged | Callback<PrintFileCreationState> | 是 | 表示更新文件状态的回调 | 2213e41f4b71Sopenharmony_ci 2214e41f4b71Sopenharmony_ci**错误码:** 2215e41f4b71Sopenharmony_ci 2216e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2217e41f4b71Sopenharmony_ci 2218e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2219e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2220e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2221e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2222e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 2223e41f4b71Sopenharmony_ci 2224e41f4b71Sopenharmony_ci**示例:** 2225e41f4b71Sopenharmony_ci 2226e41f4b71Sopenharmony_ci```ts 2227e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2228e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2229e41f4b71Sopenharmony_ci 2230e41f4b71Sopenharmony_cilet jobId : string= '1'; 2231e41f4b71Sopenharmony_ciclass MyPrintAttributes implements print.PrintAttributes { 2232e41f4b71Sopenharmony_ci copyNumber?: number; 2233e41f4b71Sopenharmony_ci pageRange?: print.PrintPageRange; 2234e41f4b71Sopenharmony_ci pageSize?: print.PrintPageSize | print.PrintPageType; 2235e41f4b71Sopenharmony_ci directionMode?: print.PrintDirectionMode; 2236e41f4b71Sopenharmony_ci colorMode?: print.PrintColorMode; 2237e41f4b71Sopenharmony_ci duplexMode?: print.PrintDuplexMode; 2238e41f4b71Sopenharmony_ci} 2239e41f4b71Sopenharmony_ci 2240e41f4b71Sopenharmony_ciclass MyPrintPageRange implements print.PrintPageRange { 2241e41f4b71Sopenharmony_ci startPage?: number; 2242e41f4b71Sopenharmony_ci endPage?: number; 2243e41f4b71Sopenharmony_ci pages?: Array<number>; 2244e41f4b71Sopenharmony_ci} 2245e41f4b71Sopenharmony_ci 2246e41f4b71Sopenharmony_ciclass MyPrintPageSize implements print.PrintPageSize { 2247e41f4b71Sopenharmony_ci id: string = '0'; 2248e41f4b71Sopenharmony_ci name: string = '0'; 2249e41f4b71Sopenharmony_ci width: number = 210; 2250e41f4b71Sopenharmony_ci height: number = 297; 2251e41f4b71Sopenharmony_ci} 2252e41f4b71Sopenharmony_ci 2253e41f4b71Sopenharmony_cilet printAttributes = new MyPrintAttributes(); 2254e41f4b71Sopenharmony_ciprintAttributes.copyNumber = 2; 2255e41f4b71Sopenharmony_ciprintAttributes.pageRange = new MyPrintPageRange(); 2256e41f4b71Sopenharmony_ciprintAttributes.pageRange.startPage = 0; 2257e41f4b71Sopenharmony_ciprintAttributes.pageRange.endPage = 5; 2258e41f4b71Sopenharmony_ciprintAttributes.pageRange.pages = [1, 3]; 2259e41f4b71Sopenharmony_ciprintAttributes.pageSize = print.PrintPageType.PAGE_ISO_A3; 2260e41f4b71Sopenharmony_ciprintAttributes.directionMode = print.PrintDirectionMode.DIRECTION_MODE_AUTO; 2261e41f4b71Sopenharmony_ciprintAttributes.colorMode = print.PrintColorMode.COLOR_MODE_MONOCHROME; 2262e41f4b71Sopenharmony_ciprintAttributes.duplexMode = print.PrintDuplexMode.DUPLEX_MODE_NONE; 2263e41f4b71Sopenharmony_ci 2264e41f4b71Sopenharmony_cilet fd : number = 1; 2265e41f4b71Sopenharmony_ciprint.startGettingPrintFile(jobId, printAttributes, fd, (state: print.PrintFileCreationState) => { 2266e41f4b71Sopenharmony_ci console.log('onFileStateChanged success, data : ' + JSON.stringify(state)); 2267e41f4b71Sopenharmony_ci}) 2268e41f4b71Sopenharmony_ci``` 2269e41f4b71Sopenharmony_ci 2270e41f4b71Sopenharmony_ci## notifyPrintService<sup>11+</sup> 2271e41f4b71Sopenharmony_ci 2272e41f4b71Sopenharmony_cinotifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started', callback: AsyncCallback<void>): void 2273e41f4b71Sopenharmony_ci 2274e41f4b71Sopenharmony_ci将spooler关闭信息通知打印服务,使用callback异步回调。 2275e41f4b71Sopenharmony_ci 2276e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 2277e41f4b71Sopenharmony_ci 2278e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 2279e41f4b71Sopenharmony_ci 2280e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 2281e41f4b71Sopenharmony_ci 2282e41f4b71Sopenharmony_ci**参数:** 2283e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 2284e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2285e41f4b71Sopenharmony_ci| jobId | string | 是 | 表示打印任务ID | 2286e41f4b71Sopenharmony_ci| type | 'spooler_closed_for_cancelled' \| 'spooler_closed_for_started' | 是 | 表示spooler关闭信息 | 2287e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 异步将spooler关闭信息通知打印服务之后的回调 | 2288e41f4b71Sopenharmony_ci 2289e41f4b71Sopenharmony_ci**错误码:** 2290e41f4b71Sopenharmony_ci 2291e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2292e41f4b71Sopenharmony_ci 2293e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2294e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2295e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2296e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2297e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 2298e41f4b71Sopenharmony_ci 2299e41f4b71Sopenharmony_ci**示例:** 2300e41f4b71Sopenharmony_ci 2301e41f4b71Sopenharmony_ci```ts 2302e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2303e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2304e41f4b71Sopenharmony_ci 2305e41f4b71Sopenharmony_cilet jobId : string = '1'; 2306e41f4b71Sopenharmony_ciprint.notifyPrintService(jobId, 'spooler_closed_for_started', (err: BusinessError, data : void) => { 2307e41f4b71Sopenharmony_ci if (err) { 2308e41f4b71Sopenharmony_ci console.log('notifyPrintService failed, because : ' + JSON.stringify(err)); 2309e41f4b71Sopenharmony_ci } else { 2310e41f4b71Sopenharmony_ci console.log('notifyPrintService success, data : ' + JSON.stringify(data)); 2311e41f4b71Sopenharmony_ci } 2312e41f4b71Sopenharmony_ci}) 2313e41f4b71Sopenharmony_ci``` 2314e41f4b71Sopenharmony_ci 2315e41f4b71Sopenharmony_ci## notifyPrintService<sup>11+</sup> 2316e41f4b71Sopenharmony_ci 2317e41f4b71Sopenharmony_cinotifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started'): Promise<void> 2318e41f4b71Sopenharmony_ci 2319e41f4b71Sopenharmony_ci将spooler关闭信息通知打印服务,使用Promise异步回调。 2320e41f4b71Sopenharmony_ci 2321e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 2322e41f4b71Sopenharmony_ci 2323e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 2324e41f4b71Sopenharmony_ci 2325e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 2326e41f4b71Sopenharmony_ci 2327e41f4b71Sopenharmony_ci**参数:** 2328e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 2329e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2330e41f4b71Sopenharmony_ci| jobId | string | 是 | 表示打印任务ID | 2331e41f4b71Sopenharmony_ci| type | 'spooler_closed_for_cancelled' \| 'spooler_closed_for_started' | 是 | 表示spooler关闭信息 | 2332e41f4b71Sopenharmony_ci 2333e41f4b71Sopenharmony_ci**返回值:** 2334e41f4b71Sopenharmony_ci| **类型** | **说明** | 2335e41f4b71Sopenharmony_ci| -------- | -------- | 2336e41f4b71Sopenharmony_ci| Promise<void> | 将spooler关闭信息通知打印服务后的完成结果 | 2337e41f4b71Sopenharmony_ci 2338e41f4b71Sopenharmony_ci**错误码:** 2339e41f4b71Sopenharmony_ci 2340e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2341e41f4b71Sopenharmony_ci 2342e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2343e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2344e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2345e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2346e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 2347e41f4b71Sopenharmony_ci 2348e41f4b71Sopenharmony_ci**示例:** 2349e41f4b71Sopenharmony_ci 2350e41f4b71Sopenharmony_ci```ts 2351e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2352e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2353e41f4b71Sopenharmony_ci 2354e41f4b71Sopenharmony_cilet jobId : string = '1'; 2355e41f4b71Sopenharmony_ciprint.notifyPrintService(jobId, 'spooler_closed_for_started').then((data : void) => { 2356e41f4b71Sopenharmony_ci console.log('notifyPrintService data : ' + JSON.stringify(data)); 2357e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 2358e41f4b71Sopenharmony_ci console.log('notifyPrintService error : ' + JSON.stringify(error)); 2359e41f4b71Sopenharmony_ci}) 2360e41f4b71Sopenharmony_ci``` 2361e41f4b71Sopenharmony_ci 2362e41f4b71Sopenharmony_ci## getAddedPrinters<sup>12+</sup> 2363e41f4b71Sopenharmony_ci 2364e41f4b71Sopenharmony_cigetAddedPrinters(): Promise<Array<string>> 2365e41f4b71Sopenharmony_ci 2366e41f4b71Sopenharmony_ci获取cups已添加打印机列表,使用Promise异步回调。 2367e41f4b71Sopenharmony_ci 2368e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 2369e41f4b71Sopenharmony_ci 2370e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 2371e41f4b71Sopenharmony_ci 2372e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 2373e41f4b71Sopenharmony_ci 2374e41f4b71Sopenharmony_ci**返回值:** 2375e41f4b71Sopenharmony_ci| **类型** | **说明** | 2376e41f4b71Sopenharmony_ci| -------- | -------- | 2377e41f4b71Sopenharmony_ci| Promise<Array<string>> | 获取cups已添加打印机列表的完成结果回调 | 2378e41f4b71Sopenharmony_ci 2379e41f4b71Sopenharmony_ci**错误码:** 2380e41f4b71Sopenharmony_ci 2381e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2382e41f4b71Sopenharmony_ci 2383e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2384e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2385e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2386e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2387e41f4b71Sopenharmony_ci 2388e41f4b71Sopenharmony_ci**示例:** 2389e41f4b71Sopenharmony_ci 2390e41f4b71Sopenharmony_ci```ts 2391e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2392e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2393e41f4b71Sopenharmony_ci 2394e41f4b71Sopenharmony_ciprint.getAddedPrinters().then((printers: string[]) => { 2395e41f4b71Sopenharmony_ci console.log('getAddedPrinters success ' + JSON.stringify(printers)); 2396e41f4b71Sopenharmony_ci // ... 2397e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 2398e41f4b71Sopenharmony_ci console.log('failed to getAddedPrinters bacause ' + JSON.stringify(error)); 2399e41f4b71Sopenharmony_ci}) 2400e41f4b71Sopenharmony_ci``` 2401e41f4b71Sopenharmony_ci 2402e41f4b71Sopenharmony_ci## getPrinterInfoById<sup>12+</sup> 2403e41f4b71Sopenharmony_ci 2404e41f4b71Sopenharmony_cigetPrinterInfoById(printerId: string): Promise<PrinterInfo> 2405e41f4b71Sopenharmony_ci 2406e41f4b71Sopenharmony_ci根据打印机id获取打印机信息,使用Promise异步回调。 2407e41f4b71Sopenharmony_ci 2408e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 2409e41f4b71Sopenharmony_ci 2410e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 2411e41f4b71Sopenharmony_ci 2412e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 2413e41f4b71Sopenharmony_ci 2414e41f4b71Sopenharmony_ci**参数:** 2415e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 2416e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2417e41f4b71Sopenharmony_ci| printerId | string | 是 | 表示打印机ID | 2418e41f4b71Sopenharmony_ci 2419e41f4b71Sopenharmony_ci**返回值:** 2420e41f4b71Sopenharmony_ci| **类型** | **说明** | 2421e41f4b71Sopenharmony_ci| -------- | -------- | 2422e41f4b71Sopenharmony_ci| Promise<PrinterInfo> | 根据打印机id获取打印机信息后的完成结果回调 | 2423e41f4b71Sopenharmony_ci 2424e41f4b71Sopenharmony_ci**错误码:** 2425e41f4b71Sopenharmony_ci 2426e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2427e41f4b71Sopenharmony_ci 2428e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2429e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2430e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2431e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2432e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 2433e41f4b71Sopenharmony_ci 2434e41f4b71Sopenharmony_ci**示例:** 2435e41f4b71Sopenharmony_ci 2436e41f4b71Sopenharmony_ci```ts 2437e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2438e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2439e41f4b71Sopenharmony_ci 2440e41f4b71Sopenharmony_cilet printerId : string = '1'; 2441e41f4b71Sopenharmony_ciprint.getPrinterInfoById(printerId).then((printerInfo : print.PrinterInfo) => { 2442e41f4b71Sopenharmony_ci console.log('getPrinterInfoById data : ' + JSON.stringify(printerInfo)); 2443e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 2444e41f4b71Sopenharmony_ci console.log('getPrinterInfoById error : ' + JSON.stringify(error)); 2445e41f4b71Sopenharmony_ci}) 2446e41f4b71Sopenharmony_ci``` 2447e41f4b71Sopenharmony_ci 2448e41f4b71Sopenharmony_ci## notifyPrintServiceEvent<sup>12+</sup> 2449e41f4b71Sopenharmony_ci 2450e41f4b71Sopenharmony_cinotifyPrintServiceEvent(event: ApplicationEvent): Promise<void> 2451e41f4b71Sopenharmony_ci 2452e41f4b71Sopenharmony_ci将打印应用相关事件通知打印服务,使用Promise异步回调。 2453e41f4b71Sopenharmony_ci 2454e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.MANAGE_PRINT_JOB 2455e41f4b71Sopenharmony_ci 2456e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 2457e41f4b71Sopenharmony_ci 2458e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Print.PrintFramework 2459e41f4b71Sopenharmony_ci 2460e41f4b71Sopenharmony_ci**参数:** 2461e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** | 2462e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2463e41f4b71Sopenharmony_ci| event | ApplicationEvent | 是 | 表示打印应用事件 | 2464e41f4b71Sopenharmony_ci 2465e41f4b71Sopenharmony_ci**返回值:** 2466e41f4b71Sopenharmony_ci| **类型** | **说明** | 2467e41f4b71Sopenharmony_ci| -------- | -------- | 2468e41f4b71Sopenharmony_ci| Promise<void> | 将打印应用相关事件通知打印服务后的完成结果回调 | 2469e41f4b71Sopenharmony_ci 2470e41f4b71Sopenharmony_ci**错误码:** 2471e41f4b71Sopenharmony_ci 2472e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。 2473e41f4b71Sopenharmony_ci 2474e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2475e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 2476e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 2477e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 2478e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 2479e41f4b71Sopenharmony_ci 2480e41f4b71Sopenharmony_ci**示例:** 2481e41f4b71Sopenharmony_ci 2482e41f4b71Sopenharmony_ci```ts 2483e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 2484e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 2485e41f4b71Sopenharmony_ci 2486e41f4b71Sopenharmony_cilet event : print.ApplicationEvent = print.ApplicationEvent.APPLICATION_CREATED; 2487e41f4b71Sopenharmony_ciprint.notifyPrintServiceEvent(event).then((data : void) => { 2488e41f4b71Sopenharmony_ci console.log('notifyPrintServiceEvent data : ' + JSON.stringify(data)); 2489e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 2490e41f4b71Sopenharmony_ci console.log('notifyPrintServiceEvent error : ' + JSON.stringify(error)); 2491e41f4b71Sopenharmony_ci}) 2492e41f4b71Sopenharmony_ci```