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