• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.print (打印)
2
3该模块为基本打印的操作API,提供调用基础打印功能的接口。
4
5> **说明:**
6> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
7
8## 导入模块
9
10```ts
11import print from '@ohos.print';
12```
13
14## PrintTask
15
16打印任务完成后的事件监听回调接口类
17
18### on
19
20on(type: 'block', callback: Callback<void>): void
21
22注册打印完成后的监听,使用callback回调。
23
24**需要权限:** ohos.permission.PRINT
25
26**系统能力:** SystemCapability.Print.PrintFramework
27
28**参数:**
29| **参数名** | **类型** | **必填** | **说明** |
30| -------- | -------- | -------- | -------- |
31| type | string | 是 | 注册监听,<br/>监听字段:block,<br/>表示打印阻塞 |
32| callback | Callback&lt;void&gt; | 是 | 打印完成后处于响应状态的回调 |
33
34**示例:**
35
36```ts
37import print from '@ohos.print';
38import { BusinessError } from '@ohos.base';
39
40let file = ['file://data/print/a.png', 'file://data/print/b.png'];
41print.print(file).then((printTask: print.PrintTask) => {
42    printTask.on('block', () => {
43        console.log('print state is block');
44    })
45    // ...
46}).catch((error: BusinessError) => {
47    console.log('print err ' + JSON.stringify(error));
48})
49```
50
51### on
52
53on(type: 'succeed', callback: Callback&lt;void&gt;): void
54
55注册打印完成后的监听,使用callback回调。
56
57**需要权限:** ohos.permission.PRINT
58
59**系统能力:** SystemCapability.Print.PrintFramework
60
61**参数:**
62| **参数名** | **类型** | **必填** | **说明** |
63| -------- | -------- | -------- | -------- |
64| type | string | 是 | 注册监听,<br/>监听字段:succeed,<br/>表示打印成功 |
65| callback | Callback&lt;void&gt; | 是 | 打印完成后处于响应状态的回调 |
66
67**示例:**
68
69```ts
70import print from '@ohos.print';
71import { BusinessError } from '@ohos.base';
72
73let file = ['file://data/print/a.png', 'file://data/print/b.png'];
74print.print(file).then((printTask: print.PrintTask) => {
75    printTask.on('succeed', () => {
76        console.log('print state is succeed');
77    })
78    // ...
79}).catch((error: BusinessError) => {
80    console.log('print err ' + JSON.stringify(error));
81})
82```
83
84### on
85
86on(type: 'fail', callback: Callback&lt;void&gt;): void
87
88注册打印完成后的监听,使用callback回调。
89
90**需要权限:** ohos.permission.PRINT
91
92**系统能力:** SystemCapability.Print.PrintFramework
93
94**参数:**
95| **参数名** | **类型** | **必填** | **说明** |
96| -------- | -------- | -------- | -------- |
97| type | string | 是 | 注册监听,<br/>监听字段:fail,<br/>表示打印失败 |
98| callback | Callback&lt;void&gt; | 是 | 打印完成后处于响应状态的回调 |
99
100**示例:**
101
102```ts
103import print from '@ohos.print';
104import { BusinessError } from '@ohos.base';
105
106let file = ['file://data/print/a.png', 'file://data/print/b.png'];
107print.print(file).then((printTask: print.PrintTask) => {
108    printTask.on('fail', () => {
109        console.log('print state is fail');
110    })
111    // ...
112}).catch((error: BusinessError) => {
113    console.log('print err ' + JSON.stringify(error));
114})
115```
116
117### on
118
119on(type: 'cancel', callback: Callback&lt;void&gt;): void
120
121注册打印完成后的监听,使用callback回调。
122
123**需要权限:** ohos.permission.PRINT
124
125**系统能力:** SystemCapability.Print.PrintFramework
126
127**参数:**
128| **参数名** | **类型** | **必填** | **说明** |
129| -------- | -------- | -------- | -------- |
130| type | string | 是 | 注册监听,<br/>监听字段:cancel,<br/>表示打印取消 |
131| callback | Callback&lt;void&gt; | 是 | 打印完成后处于响应状态的回调 |
132
133**示例:**
134
135```ts
136import print from '@ohos.print';
137import { BusinessError } from '@ohos.base';
138
139let file = ['file://data/print/a.png', 'file://data/print/b.png'];
140print.print(file).then((printTask: print.PrintTask) => {
141    printTask.on('cancel', () => {
142        console.log('print state is cancel');
143    })
144    // ...
145}).catch((error: BusinessError) => {
146    console.log('print err ' + JSON.stringify(error));
147})
148```
149
150### off
151
152off(type: 'block', callback?: Callback&lt;void&gt;): void
153
154取消打印完成后的监听,使用callback回调。
155
156**需要权限:** ohos.permission.PRINT
157
158**系统能力:** SystemCapability.Print.PrintFramework
159
160**参数:**
161| **参数名** | **类型** | **必填** | **说明** |
162| -------- | -------- | -------- | -------- |
163| type | string | 是 | 取消监听,<br/>监听字段:block,<br/>表示打印阻塞 |
164| callback | Callback&lt;void&gt; | 否 | 取消相应状态监听成功后的回调 |
165
166**示例:**
167
168```ts
169import print from '@ohos.print';
170import { BusinessError } from '@ohos.base';
171
172let file = ['file://data/print/a.png', 'file://data/print/b.png'];
173print.print(file).then((printTask: print.PrintTask) => {
174    printTask.off('block', () => {
175        console.log('unregister state block');
176    })
177    // ...
178}).catch((error: BusinessError) => {
179    console.log('print err ' + JSON.stringify(error));
180})
181```
182
183### off
184
185off(type: 'succeed', callback?: Callback&lt;void&gt;): void
186
187取消打印完成后的监听,使用callback回调。
188
189**需要权限:** ohos.permission.PRINT
190
191**系统能力:** SystemCapability.Print.PrintFramework
192
193**参数:**
194| **参数名** | **类型** | **必填** | **说明** |
195| -------- | -------- | -------- | -------- |
196| type | string | 是 | 取消监听,<br/>监听字段:succeed,<br/>表示打印成功 |
197| callback | Callback&lt;void&gt; | 否 | 取消相应状态监听成功后的回调 |
198
199**示例:**
200
201```ts
202import print from '@ohos.print';
203import { BusinessError } from '@ohos.base';
204
205let file = ['file://data/print/a.png', 'file://data/print/b.png'];
206print.print(file).then((printTask: print.PrintTask) => {
207    printTask.off('succeed', () => {
208        console.log('unregister state succeed');
209    })
210    // ...
211}).catch((error: BusinessError) => {
212    console.log('print err ' + JSON.stringify(error));
213})
214```
215
216### off
217
218off(type: 'fail', callback?: Callback&lt;void&gt;): void
219
220取消打印完成后的监听,使用callback回调。
221
222**需要权限:** ohos.permission.PRINT
223
224**系统能力:** SystemCapability.Print.PrintFramework
225
226**参数:**
227| **参数名** | **类型** | **必填** | **说明** |
228| -------- | -------- | -------- | -------- |
229| type | string | 是 | 取消监听,<br/>监听字段:fail,<br/>表示打印失败 |
230| callback | Callback&lt;void&gt; | 否 | 取消相应状态监听成功后的回调 |
231
232**示例:**
233
234```ts
235import print from '@ohos.print';
236import { BusinessError } from '@ohos.base';
237
238let file = ['file://data/print/a.png', 'file://data/print/b.png'];
239print.print(file).then((printTask: print.PrintTask) => {
240    printTask.off('fail', () => {
241        console.log('unregister state fail');
242    })
243    // ...
244}).catch((error: BusinessError) => {
245    console.log('print err ' + JSON.stringify(error));
246})
247```
248
249### off
250
251off(type: 'cancel', callback?: Callback&lt;void&gt;): void
252
253取消打印完成后的监听,使用callback回调。
254
255**需要权限:** ohos.permission.PRINT
256
257**系统能力:** SystemCapability.Print.PrintFramework
258
259**参数:**
260| **参数名** | **类型** | **必填** | **说明** |
261| -------- | -------- | -------- | -------- |
262| type | string | 是 | 取消监听,<br/>监听字段:cancel,<br/>表示打印取消 |
263| callback | Callback&lt;void&gt; | 否 | 取消相应状态监听成功后的回调 |
264
265**示例:**
266
267```ts
268import print from '@ohos.print';
269import { BusinessError } from '@ohos.base';
270
271let file = ['file://data/print/a.png', 'file://data/print/b.png'];
272print.print(file).then((printTask: print.PrintTask) => {
273    printTask.off('cancel', () => {
274        console.log('unregister state cancel');
275    })
276    // ...
277}).catch((error: BusinessError) => {
278    console.log('print err ' + JSON.stringify(error));
279})
280```
281
282## print
283
284print(files: Array&lt;string&gt;, callback: AsyncCallback&lt;PrintTask&gt;): void
285
286打印接口,传入文件进行打印,使用callback异步回调。
287
288**需要权限:** ohos.permission.PRINT
289
290**系统能力:** SystemCapability.Print.PrintFramework
291
292**参数:**
293| **参数名** | **类型** | **必填** | **说明** |
294| -------- | -------- | -------- | -------- |
295| file | Array&lt;string&gt; | 是 | 待打印文件列表,支持图片(.jpg .png .gif .bmp .webp) |
296| callback | AsyncCallback&lt;PrintTask&gt; | 是 | 异步获取打印完成之后的回调 |
297
298**示例:**
299
300```ts
301import print from '@ohos.print';
302import { BusinessError } from '@ohos.base';
303
304//传入文件的uri
305let file = ['file://data/print/a.png', 'file://data/print/b.png'];
306//或者传入id
307//let file = ['fd://1', 'fd://2'];
308print.print(file, (err: BusinessError, printTask: print.PrintTask) => {
309    if (err) {
310        console.log('print err ' + JSON.stringify(err));
311    } else {
312        printTask.on('succeed', () => {
313            console.log('print state is succeed');
314        })
315        // ...
316    }
317})
318```
319
320## print
321
322print(files: Array&lt;string&gt;): Promise&lt;PrintTask&gt;
323
324打印接口,传入文件进行打印,使用Promise异步回调。
325
326**需要权限:** ohos.permission.PRINT
327
328**系统能力:** SystemCapability.Print.PrintFramework
329
330**参数:**
331| **参数名** | **类型** | **必填** | **说明** |
332| -------- | -------- | -------- | -------- |
333| file | Array&lt;string&gt; | 是 | 待打印文件列表,支持图片(.jpg .png .gif .bmp .webp) |
334
335**返回值:**
336| **类型** | **说明** |
337| -------- | -------- |
338| Promise&lt;PrintTask&gt; | 打印完成结果 |
339
340**示例:**
341
342```ts
343import print from '@ohos.print';
344import { BusinessError } from '@ohos.base';
345
346//传入文件的uri
347let file = ['file://data/print/a.png', 'file://data/print/b.png'];
348//或者传入id
349//let file = ['fd://1', 'fd://2'];
350print.print(file).then((printTask: print.PrintTask) => {
351    printTask.on('succeed', () => {
352        console.log('print state is succeed');
353    })
354    // ...
355}).catch((error: BusinessError) => {
356    console.log('print err ' + JSON.stringify(error));
357})
358```
359
360## PrintMargin
361
362定义打印页边距的接口
363
364**系统接口:** 此接口为系统接口。
365
366**系统能力:** SystemCapability.Print.PrintFramework
367
368**属性:**
369| **名称** | **类型** | **必填** | **说明** |
370| -------- | -------- | -------- | -------- |
371| top | number | 否 | 表示页面上边距 |
372| bottom | number | 否 | 表示页面下边距 |
373| left | number | 否 | 表示页面左边距 |
374| right | number | 否 | 表示页面右边距 |
375
376## PrinterRange
377
378定义打印范围的接口
379
380**系统接口:** 此接口为系统接口。
381
382**系统能力:** SystemCapability.Print.PrintFramework
383
384**属性:**
385| **名称** | **类型** | **必填** | **说明** |
386| -------- | -------- | -------- | -------- |
387| startPage | number | 否 | 表示起始页 |
388| endPage | number | 否 | 表示结束页 |
389| pages | Array&lt;number&gt; | 否 | 表示离散页面 |
390
391## PreviewAttribute
392
393定义打印预览属性的接口
394
395**系统接口:** 此接口为系统接口。
396
397**系统能力:** SystemCapability.Print.PrintFramework
398
399**属性:**
400| **名称** | **类型** | **必填** | **说明** |
401| -------- | -------- | -------- | -------- |
402| previewRange | PrinterRange | 是 | 表示预览页面范围 |
403| result | number | 否 | 表示预览文件结果 |
404
405## PrintResolution
406
407定义打印分辨率的接口
408
409**系统接口:** 此接口为系统接口。
410
411**系统能力:** SystemCapability.Print.PrintFramework
412
413**属性:**
414| **名称** | **类型** | **必填** | **说明** |
415| -------- | -------- | -------- | -------- |
416| id | string | 是 | 表示分辨率ID |
417| horizontalDpi | number | 是 | 表示水平DPI |
418| verticalDpi | number | 是 | 表示垂直DPI |
419
420## PrintPageSize
421
422定义打印页面尺寸的接口
423
424**系统接口:** 此接口为系统接口。
425
426**系统能力:** SystemCapability.Print.PrintFramework
427
428**属性:**
429| **名称** | **类型** | **必填** | **说明** |
430| -------- | -------- | -------- | -------- |
431| id | string | 是 | 表示页面尺寸ID |
432| name | string | 是 | 表示页面尺寸名称 |
433| width | number | 是 | 表示页面宽度,单位:毫米 |
434| height | number | 是 | 表示页面高度,单位:毫米 |
435
436## PrinterCapability
437
438定义打印能力的接口
439
440**系统接口:** 此接口为系统接口。
441
442**系统能力:** SystemCapability.Print.PrintFramework
443
444**属性:**
445| **名称** | **类型** | **必填** | **说明** |
446| -------- | -------- | -------- | -------- |
447| colorMode | number | 是 | 表示色彩模式 |
448| duplexMode | number | 是 | 表示单双面打印模式 |
449| pageSize | Array&lt;PrintPageSize&gt; | 是 | 表示打印机支持的页面尺寸列表 |
450| resolution | Array&lt;PrintResolution&gt; | 否 | 表示打印机支持的分辨率列表 |
451| minMargin | PrintMargin | 否 | 表示打印机最小边距 |
452
453## PrinterInfo
454
455定义打印信息的接口
456
457**系统接口:** 此接口为系统接口。
458
459**系统能力:** SystemCapability.Print.PrintFramework
460
461**属性:**
462| **名称** | **类型** | **必填** | **说明** |
463| -------- | -------- | -------- | -------- |
464| printerId | string | 是 | 表示打印机ID |
465| printerName | string | 是 | 表示打印机名称 |
466| printerState | PrinterState | 是 | 表示当前打印机状态 |
467| printerIcon | number | 否 | 表示打印机图标的资源ID |
468| description | string | 否 | 表示打印机说明 |
469| capability | PrinterCapability | 否 | 表示打印机功能 |
470| options | Object | 否 | 表示JSON对象字符串 |
471
472## PrintJob
473
474定义打印任务的接口
475
476**系统接口:** 此接口为系统接口。
477
478**系统能力:** SystemCapability.Print.PrintFramework
479
480**属性:**
481| **名称** | **类型** | **必填** | **说明** |
482| -------- | -------- | -------- | -------- |
483| fdList | Array&lt;number&gt; | 是 | 表示待打印文件fd列表 |
484| jobId | string | 是 | 表示打印任务ID |
485| printerId | string | 是 | 表示负责打印的打印机ID |
486| jobState | PrintJobState | 是 | 表示当前打印任务状态 |
487| copyNumber | number | 是 | 表示文件列表副本 |
488| pageRange | PrinterRange | 是 | 表示打印范围大小 |
489| isSequential | boolean | 是 | 表示连续打印 |
490| pageSize | PrintPageSize | 是 | 表示选定的页面尺寸 |
491| isLandscape | boolean | 是 | 表示垂直打印 |
492| colorMode | number | 是 | 表示色彩模式 |
493| duplexMode | number | 是 | 表示单双面打印模式 |
494| margin | PrintMargin | 否 | 表示当前页边距设置 |
495| preview | PreviewAttribute | 否 | 表示预览设置 |
496| options | Object | 否 | 表示JSON对象字符串 |
497
498## PrinterState
499
500打印机状态的枚举
501
502**系统接口:** 此接口为系统接口。
503
504**系统能力:** SystemCapability.Print.PrintFramework
505
506| **名称** | **值** | **说明** |
507| -------- | -------- | -------- |
508| PRINTER_ADDED | 0 | 表示新打印机到达 |
509| PRINTER_REMOVED | 1 | 表示打印机丢失 |
510| PRINTER_CAPABILITY_UPDATED | 2 | 表示打印机更新 |
511| PRINTER_CONNECTED | 3 | 表示打印机已连接 |
512| PRINTER_DISCONNECTED | 4 | 表示打印机已断开连接 |
513| PRINTER_RUNNING | 5 | 表示打印机正在运行 |
514
515## PrintJobState
516
517打印任务状态的枚举
518
519**系统接口:** 此接口为系统接口。
520
521**系统能力:** SystemCapability.Print.PrintFramework
522
523| **名称** | **值** | **说明** |
524| -------- | -------- | -------- |
525| PRINT_JOB_PREPARE | 0 | 表示打印任务的初始状态 |
526| PRINT_JOB_QUEUED | 1 | 表示打印任务传送到打印机 |
527| PRINT_JOB_RUNNING | 2 | 表示执行打印任务|
528| PRINT_JOB_BLOCKED | 3 | 表示打印任务已被阻止 |
529| PRINT_JOB_COMPLETED | 4 | 表示打印任务完成 |
530
531## PrintJobSubState
532
533打印任务子状态的枚举
534
535**系统接口:** 此接口为系统接口。
536
537**系统能力:** SystemCapability.Print.PrintFramework
538
539| **名称** | **值** | **说明** |
540| -------- | -------- | -------- |
541| PRINT_JOB_COMPLETED_SUCCESS | 0 | 表示打印任务成功 |
542| PRINT_JOB_COMPLETED_FAILED | 1 | 表示打印任务失败 |
543| PRINT_JOB_COMPLETED_CANCELLED | 2 | 表示打印任务已取消|
544| PRINT_JOB_COMPLETED_FILE_CORRUPTED | 3 | 表示打印任务已损坏 |
545| PRINT_JOB_BLOCK_OFFLINE | 4 | 表示打印处于离线状态 |
546| PRINT_JOB_BLOCK_BUSY | 5 | 表示打印被其他进程占用 |
547| PRINT_JOB_BLOCK_CANCELLED | 6 | 表示打印任务已取消 |
548| PRINT_JOB_BLOCK_OUT_OF_PAPER | 7 | 表示打印纸张用完 |
549| PRINT_JOB_BLOCK_OUT_OF_INK | 8 | 表示打印墨水用完 |
550| PRINT_JOB_BLOCK_OUT_OF_TONER | 9 | 表示打印墨粉用完 |
551| PRINT_JOB_BLOCK_JAMMED | 10 | 表示打印卡纸 |
552| PRINT_JOB_BLOCK_DOOR_OPEN | 11 | 表示打印盖开启 |
553| PRINT_JOB_BLOCK_SERVICE_REQUEST | 12 | 表示打印服务请求 |
554| PRINT_JOB_BLOCK_LOW_ON_INK | 13 | 表示打印墨水不足 |
555| PRINT_JOB_BLOCK_LOW_ON_TONER | 14 | 表示打印墨粉不足 |
556| PRINT_JOB_BLOCK_REALLY_LOW_ON_INK | 15 | 表示打印墨水量非常低 |
557| PRINT_JOB_BLOCK_BAD_CERTIFICATE | 16 | 表示打印证书有误 |
558| PRINT_JOB_BLOCK_UNKNOWN | 99 | 表示打印未知问题 |
559
560## PrintErrorCode
561
562打印错误代码的枚举
563
564**系统接口:** 此接口为系统接口。
565
566**系统能力:** SystemCapability.Print.PrintFramework
567
568| **名称** | **值** | **说明** |
569| -------- | -------- | -------- |
570| E_PRINT_NONE | 0 | 表示没有错误 |
571| E_PRINT_NO_PERMISSION | 201 | 表示没有许可 |
572| E_PRINT_INVALID_PARAMETER | 401 | 表示无效的参数|
573| E_PRINT_GENERIC_FAILURE | 13100001 | 表示一般打印失败 |
574| E_PRINT_RPC_FAILURE | 13100002 | 表示RPC失败 |
575| E_PRINT_SERVER_FAILURE | 13100003 | 表示打印服务失败 |
576| E_PRINT_INVALID_EXTENSION | 13100004 | 表示打印扩展无效 |
577| E_PRINT_INVALID_PRINTER | 13100005 | 表示打印机无效 |
578| E_PRINT_INVALID_PRINT_JOB | 13100006 | 表示打印任务无效 |
579| E_PRINT_FILE_IO | 13100007 | 表示文件输入/输出错误 |
580
581## PrinterExtensionInfo
582
583定义打印扩展信息的接口
584
585**系统接口:** 此接口为系统接口。
586
587**系统能力:** SystemCapability.Print.PrintFramework
588
589**属性:**
590| **名称** | **类型** | **必填** | **说明** |
591| -------- | -------- | -------- | -------- |
592| extensionId | string | 是 | 表示打印机扩展的扩展ID |
593| vendorId | string | 是 | 表示扩展的供应商ID |
594| vendorName | string | 是 | 表示供应商名称 |
595| vendorIcon | number | 是 | 表示供应商图标 |
596| version | string | 是 | 表示当前打印机扩展的版本 |
597
598## queryAllPrinterExtensionInfos
599
600queryAllPrinterExtensionInfos(callback: AsyncCallback&lt;Array&lt;PrinterExtensionInfo&gt;&gt;): void
601
602查询所有已安装的打印机扩展服务,使用callback异步回调。
603
604**需要权限:** ohos.permission.MANAGE_PRINT_JOB
605
606**系统接口:** 此接口为系统接口。
607
608**系统能力:** SystemCapability.Print.PrintFramework
609
610**参数:**
611| **参数名** | **类型** | **必填** | **说明** |
612| -------- | -------- | -------- | -------- |
613| callback | AsyncCallback&lt;Array&lt;PrinterExtensionInfo&gt;&gt; | 是 | 异步查询所有已安装的打印机扩展服务之后的回调 |
614
615**示例:**
616
617```ts
618import print from '@ohos.print';
619import { BusinessError } from '@ohos.base';
620
621print.queryAllPrinterExtensionInfos((err: BusinessError, extensionInfos: print.PrinterExtensionInfo[]) => {
622    if (err) {
623        console.log('queryAllPrinterExtensionInfos err ' + JSON.stringify(err));
624    } else {
625        console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos));
626    }
627})
628```
629
630## queryAllPrinterExtensionInfos
631
632queryAllPrinterExtensionInfos(): Promise&lt;Array&lt;PrinterExtensionInfo&gt;&gt;
633
634查询所有已安装的打印机扩展服务,使用Promise异步回调。
635
636**需要权限:** ohos.permission.MANAGE_PRINT_JOB
637
638**系统接口:** 此接口为系统接口。
639
640**系统能力:** SystemCapability.Print.PrintFramework
641
642**返回值:**
643| **类型** | **说明** |
644| -------- | -------- |
645| Promise&lt;Array&lt;PrinterExtensionInfo&gt;&gt; | 查询所有已安装的打印机扩展服务完成结果 |
646
647**示例:**
648
649```ts
650import print from '@ohos.print';
651import { BusinessError } from '@ohos.base';
652
653print.queryAllPrinterExtensionInfos().then((extensionInfos: print.PrinterExtensionInfo[]) => {
654    console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos));
655    // ...
656}).catch((error: BusinessError) => {
657    console.log('failed to get AllPrinterExtension bacause ' + JSON.stringify(error));
658})
659```
660
661## startDiscoverPrinter
662
663startDiscoverPrinter(extensionList: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
664
665加载特定的打印机扩展并开始发现打印机,使用callback异步回调。
666
667**需要权限:** ohos.permission.MANAGE_PRINT_JOB
668
669**系统接口:** 此接口为系统接口。
670
671**系统能力:** SystemCapability.Print.PrintFramework
672
673**参数:**
674| **参数名** | **类型** | **必填** | **说明** |
675| -------- | -------- | -------- | -------- |
676| extensionList | Array&lt;string&gt; | 是 | 要加载的打印机扩展列表 |
677| callback | AsyncCallback&lt;void&gt; | 是 | 异步开始发现打印机之后的回调 |
678
679**示例:**
680
681```ts
682import print from '@ohos.print';
683import { BusinessError } from '@ohos.base';
684
685let extensionList: string[] = [];
686//extensionList内无信息表示发现所有扩展
687print.startDiscoverPrinter(extensionList, (err: BusinessError, data : void) => {
688    if (err) {
689        console.log('failed to start Discover Printer because : ' + JSON.stringify(err));
690    } else {
691        console.log('start Discover Printer success data : ' + JSON.stringify(data));
692    }
693})
694```
695
696## startDiscoverPrinter
697
698startDiscoverPrinter(extensionList: Array&lt;string&gt;): Promise&lt;void&gt;
699
700加载特定的打印机扩展并开始发现打印机,使用Promise异步回调。
701
702**需要权限:** ohos.permission.MANAGE_PRINT_JOB
703
704**系统接口:** 此接口为系统接口。
705
706**系统能力:** SystemCapability.Print.PrintFramework
707
708**返回值:**
709| **类型** | **说明** |
710| -------- | -------- |
711| Promise&lt;void&gt; | 加载特定的打印机扩展并开始发现打印机完成结果 |
712
713**示例:**
714
715```ts
716import print from '@ohos.print';
717import { BusinessError } from '@ohos.base';
718
719let extensionList: string[] = [];
720//extensionList内无信息表示发现所有扩展
721print.startDiscoverPrinter(extensionList).then((data : void) => {
722    console.log('start Discovery success data : ' + JSON.stringify(data));
723}).catch((error: BusinessError) => {
724    console.log('failed to start Discovery because : ' + JSON.stringify(error));
725})
726```
727
728## stopDiscoverPrinter
729
730stopDiscoverPrinter(callback: AsyncCallback&lt;void&gt;): void
731
732停止发现具有特定打印机扩展的打印机,使用callback异步回调。
733
734**需要权限:** ohos.permission.MANAGE_PRINT_JOB
735
736**系统接口:** 此接口为系统接口。
737
738**系统能力:** SystemCapability.Print.PrintFramework
739
740**参数:**
741| **参数名** | **类型** | **必填** | **说明** |
742| -------- | -------- | -------- | -------- |
743| callback | AsyncCallback&lt;void&gt; | 是 | 异步停止发现具有特定打印机扩展的打印机之后的回调 |
744
745**示例:**
746
747```ts
748import print from '@ohos.print';
749import { BusinessError } from '@ohos.base';
750
751print.stopDiscoverPrinter((err: BusinessError, data : void) => {
752    if (err) {
753        console.log('failed to stop Discover Printer because : ' + JSON.stringify(err));
754    } else {
755        console.log('stop Discover Printer success data : ' + JSON.stringify(data));
756    }
757})
758```
759
760## stopDiscoverPrinter
761
762stopDiscoverPrinter(): Promise&lt;void&gt;
763
764停止发现具有特定打印机扩展的打印机,使用Promise异步回调。
765
766**需要权限:** ohos.permission.MANAGE_PRINT_JOB
767
768**系统接口:** 此接口为系统接口。
769
770**系统能力:** SystemCapability.Print.PrintFramework
771
772**返回值:**
773| **类型** | **说明** |
774| -------- | -------- |
775| Promise&lt;void&gt; | 停止发现具有特定打印机扩展的打印机完成结果 |
776
777**示例:**
778
779```ts
780import print from '@ohos.print';
781import { BusinessError } from '@ohos.base';
782
783print.stopDiscoverPrinter().then((data : void) => {
784    console.log('stop Discovery success data : ' + JSON.stringify(data));
785}).catch((error: BusinessError) => {
786    console.log('failed to stop Discovery because : ' + JSON.stringify(error));
787})
788```
789
790## connectPrinter
791
792connectPrinter(printerId: string, 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| printerId | string | 是 | 打印机ID |
806| callback | AsyncCallback&lt;void&gt; | 是 | 异步连接特定打印机之后的回调 |
807
808**示例:**
809
810```ts
811import print from '@ohos.print';
812import { BusinessError } from '@ohos.base';
813
814let printerId: string = 'printerId_32';
815print.connectPrinter(printerId, (err: BusinessError, data : void) => {
816    if (err) {
817        console.log('failed to connect Printer because : ' + JSON.stringify(err));
818    } else {
819        console.log('start connect Printer success data : ' + JSON.stringify(data));
820    }
821})
822```
823
824## connectPrinter
825
826connectPrinter(printerId: string): Promise&lt;void&gt;
827
828连接特定打印机,使用Promise异步回调。
829
830**需要权限:** ohos.permission.MANAGE_PRINT_JOB
831
832**系统接口:** 此接口为系统接口。
833
834**系统能力:** SystemCapability.Print.PrintFramework
835
836**参数:**
837| **参数名** | **类型** | **必填** | **说明** |
838| -------- | -------- | -------- | -------- |
839| printerId | string | 是 | 打印机ID |
840
841**返回值:**
842| **类型** | **说明** |
843| -------- | -------- |
844| Promise&lt;void&gt; | 连接特定打印机完成结果 |
845
846**示例:**
847
848```ts
849import print from '@ohos.print';
850import { BusinessError } from '@ohos.base';
851
852let printerId: string = 'printerId_32';
853print.connectPrinter(printerId).then((data : void) => {
854    console.log('start connect Printer success data : ' + JSON.stringify(data));
855}).catch((error: BusinessError) => {
856    console.log('failed to connect Printer because : ' + JSON.stringify(error));
857})
858```
859
860## disconnectPrinter
861
862disconnectPrinter(printerId: string, callback: AsyncCallback&lt;void&gt;): void
863
864断开特定打印机的连接,使用callback异步回调。
865
866**需要权限:** ohos.permission.MANAGE_PRINT_JOB
867
868**系统接口:** 此接口为系统接口。
869
870**系统能力:** SystemCapability.Print.PrintFramework
871
872**参数:**
873| **参数名** | **类型** | **必填** | **说明** |
874| -------- | -------- | -------- | -------- |
875| printerId | string | 是 | 打印机ID |
876| callback | AsyncCallback&lt;void&gt; | 是 | 异步断开特定打印机的连接之后的回调 |
877
878**示例:**
879
880```ts
881import print from '@ohos.print';
882import { BusinessError } from '@ohos.base';
883
884let printerId: string = 'printerId_32';
885print.disconnectPrinter(printerId, (err: BusinessError, data : void) => {
886    if (err) {
887        console.log('failed to disconnect Printer because : ' + JSON.stringify(err));
888    } else {
889        console.log('start disconnect Printer success data : ' + JSON.stringify(data));
890    }
891})
892```
893
894## disconnectPrinter
895
896disconnectPrinter(printerId: string): Promise&lt;void&gt;
897
898断开特定打印机的连接,使用Promise异步回调。
899
900**需要权限:** ohos.permission.MANAGE_PRINT_JOB
901
902**系统接口:** 此接口为系统接口。
903
904**系统能力:** SystemCapability.Print.PrintFramework
905
906**参数:**
907| **参数名** | **类型** | **必填** | **说明** |
908| -------- | -------- | -------- | -------- |
909| printerId | string | 是 | 打印机ID |
910
911**返回值:**
912| **类型** | **说明** |
913| -------- | -------- |
914| Promise&lt;void&gt; | 断开特定打印机的连接完成结果 |
915
916**示例:**
917
918```ts
919import print from '@ohos.print';
920import { BusinessError } from '@ohos.base';
921
922let printerId: string = 'printerId_32';
923print.disconnectPrinter(printerId).then((data : void) => {
924    console.log('start disconnect Printer success data : ' + JSON.stringify(data));
925}).catch((error: BusinessError) => {
926    console.log('failed to disconnect Printer because : ' + JSON.stringify(error));
927})
928```
929
930## queryPrinterCapability
931
932queryPrinterCapability(printerId: string, callback: AsyncCallback&lt;void&gt;): void
933
934查询打印机能力,使用callback异步回调。
935
936**需要权限:** ohos.permission.MANAGE_PRINT_JOB
937
938**系统接口:** 此接口为系统接口。
939
940**系统能力:** SystemCapability.Print.PrintFramework
941
942**参数:**
943| **参数名** | **类型** | **必填** | **说明** |
944| -------- | -------- | -------- | -------- |
945| printerId | string | 是 | 打印机ID |
946| callback | AsyncCallback&lt;void&gt; | 是 | 异步查询打印机能力之后的回调 |
947
948**示例:**
949
950```ts
951import print from '@ohos.print';
952import { BusinessError } from '@ohos.base';
953
954let printerId: string = 'printerId_32';
955print.queryPrinterCapability(printerId, (err: BusinessError, data : void) => {
956    if (err) {
957        console.log('failed to query Printer Capability because : ' + JSON.stringify(err));
958    } else {
959        console.log('start query Printer Capability success data : ' + JSON.stringify(data));
960    }
961})
962```
963
964## queryPrinterCapability
965
966queryPrinterCapability(printerId: string): Promise&lt;void&gt;
967
968查询打印机能力,使用Promise异步回调。
969
970**需要权限:** ohos.permission.MANAGE_PRINT_JOB
971
972**系统接口:** 此接口为系统接口。
973
974**系统能力:** SystemCapability.Print.PrintFramework
975
976**参数:**
977| **参数名** | **类型** | **必填** | **说明** |
978| -------- | -------- | -------- | -------- |
979| printerId | string | 是 | 打印机ID |
980
981**返回值:**
982| **类型** | **说明** |
983| -------- | -------- |
984| Promise&lt;void&gt; | 查询打印机能力完成结果 |
985
986**示例:**
987
988```ts
989import print from '@ohos.print';
990import { BusinessError } from '@ohos.base';
991
992let printerId: string = 'printerId_32';
993print.queryPrinterCapability(printerId).then((data : void) => {
994    console.log('start query Printer success data : ' + JSON.stringify(data));
995}).catch((error: BusinessError) => {
996    console.log('failed to query Printer Capability because : ' + JSON.stringify(error));
997})
998```
999
1000## startPrintJob
1001
1002startPrintJob(jobInfo: PrintJob, callback: AsyncCallback&lt;void&gt;): void
1003
1004开始打印任务,使用callback异步回调。
1005
1006**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1007
1008**系统接口:** 此接口为系统接口。
1009
1010**系统能力:** SystemCapability.Print.PrintFramework
1011
1012**参数:**
1013| **参数名** | **类型** | **必填** | **说明** |
1014| -------- | -------- | -------- | -------- |
1015| jobInfo | PrintJob | 是 | 打印任务信息 |
1016| callback | AsyncCallback&lt;void&gt; | 是 | 异步开始打印任务之后的回调 |
1017
1018**示例:**
1019
1020```ts
1021import print from '@ohos.print';
1022import { BusinessError } from '@ohos.base';
1023
1024let jobInfo : print.PrintJob = {
1025    fdList : [0,1],
1026    jobId : 'jobId_12',
1027    printerId : 'printerId_32',
1028    jobState : 3,
1029    copyNumber : 1,
1030    pageRange : {},
1031    isSequential : false,
1032    pageSize : {id : '', name : '', width : 10, height : 20},
1033    isLandscape : false,
1034    colorMode : 6,
1035    duplexMode : 6,
1036    margin : undefined,
1037    preview : undefined,
1038    options : undefined
1039};
1040print.startPrintJob(jobInfo, (err: BusinessError, data : void) => {
1041    if (err) {
1042        console.log('failed to start Print Job because : ' + JSON.stringify(err));
1043    } else {
1044        console.log('start Print Job success data : ' + JSON.stringify(data));
1045    }
1046})
1047```
1048
1049## startPrintJob
1050
1051startPrintJob(jobInfo: PrintJob): Promise&lt;void&gt;
1052
1053开始打印任务,使用Promise异步回调。
1054
1055**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1056
1057**系统接口:** 此接口为系统接口。
1058
1059**系统能力:** SystemCapability.Print.PrintFramework
1060
1061**参数:**
1062| **参数名** | **类型** | **必填** | **说明** |
1063| -------- | -------- | -------- | -------- |
1064| jobInfo | PrintJob | 是 | 打印任务信息 |
1065
1066**返回值:**
1067| **类型** | **说明** |
1068| -------- | -------- |
1069| Promise&lt;void&gt; | 开始打印任务完成结果 |
1070
1071**示例:**
1072
1073```ts
1074import print from '@ohos.print';
1075import { BusinessError } from '@ohos.base';
1076
1077let jobInfo : print.PrintJob = {
1078    fdList : [0,1],
1079    jobId : 'jobId_12',
1080    printerId : 'printerId_32',
1081    jobState : 3,
1082    copyNumber : 1,
1083    pageRange : {},
1084    isSequential : false,
1085    pageSize : {id : '', name : '', width : 10, height : 20},
1086    isLandscape : false,
1087    colorMode : 6,
1088    duplexMode : 6,
1089    margin : undefined,
1090    preview : undefined,
1091    options : undefined
1092};
1093print.startPrintJob(jobInfo).then((data : void) => {
1094    console.log('start Print success data : ' + JSON.stringify(data));
1095}).catch((error: BusinessError) => {
1096    console.log('failed to start Print because : ' + JSON.stringify(error));
1097})
1098```
1099
1100## cancelPrintJob
1101
1102cancelPrintJob(jobId: string, callback: AsyncCallback&lt;void&gt;): void
1103
1104取消已发送到打印机的打印任务,使用callback异步回调。
1105
1106**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1107
1108**系统接口:** 此接口为系统接口。
1109
1110**系统能力:** SystemCapability.Print.PrintFramework
1111
1112**参数:**
1113| **参数名** | **类型** | **必填** | **说明** |
1114| -------- | -------- | -------- | -------- |
1115| jobId | string | 是 | 打印任务ID |
1116| callback | AsyncCallback&lt;void&gt; | 是 | 异步取消已发送到打印机的打印任务之后的回调 |
1117
1118**示例:**
1119
1120```ts
1121import print from '@ohos.print';
1122import { BusinessError } from '@ohos.base';
1123
1124let jobId : string = '121212';
1125print.cancelPrintJob(jobId, (err: BusinessError, data : void) => {
1126    if (err) {
1127        console.log('cancelPrintJob failed, because : ' + JSON.stringify(err));
1128    } else {
1129        console.log('cancelPrintJob success, data: ' + JSON.stringify(data));
1130    }
1131})
1132```
1133
1134## cancelPrintJob
1135
1136cancelPrintJob(jobId: string): Promise&lt;void&gt;
1137
1138取消已发送到打印机的打印任务,使用Promise异步回调。
1139
1140**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1141
1142**系统接口:** 此接口为系统接口。
1143
1144**系统能力:** SystemCapability.Print.PrintFramework
1145
1146**参数:**
1147| **参数名** | **类型** | **必填** | **说明** |
1148| -------- | -------- | -------- | -------- |
1149| jobId | string | 是 | 打印任务ID |
1150
1151**返回值:**
1152| **类型** | **说明** |
1153| -------- | -------- |
1154| Promise&lt;void&gt; | 取消已发送到打印机的打印任务完成结果 |
1155
1156**示例:**
1157
1158```ts
1159import print from '@ohos.print';
1160import { BusinessError } from '@ohos.base';
1161
1162let jobId : string = '121212';
1163print.cancelPrintJob(jobId).then((data : void) => {
1164    console.log('cancelPrintJob success, data : ' + JSON.stringify(data));
1165}).catch((error: BusinessError) => {
1166    console.log('cancelPrintJob failed, because : ' + JSON.stringify(error));
1167})
1168```
1169
1170## requestPrintPreview
1171
1172requestPrintPreview(jobInfo: PrintJob, callback: Callback&lt;number&gt;): void
1173
1174请求预览打印数据,使用callback回调。
1175
1176**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1177
1178**系统接口:** 此接口为系统接口。
1179
1180**系统能力:** SystemCapability.Print.PrintFramework
1181
1182**参数:**
1183| **参数名** | **类型** | **必填** | **说明** |
1184| -------- | -------- | -------- | -------- |
1185| jobInfo | PrintJob | 是 | 打印任务信息 |
1186| callback | Callback&lt;number&gt; | 是 | 请求预览打印数据之后的回调 |
1187
1188**示例:**
1189
1190```ts
1191import print from '@ohos.print';
1192
1193let jobInfo : print.PrintJob = {
1194    fdList : [0,1],
1195    jobId : 'jobId_12',
1196    printerId : 'printerId_32',
1197    jobState : 3,
1198    copyNumber : 1,
1199    pageRange : {},
1200    isSequential : false,
1201    pageSize : {id : '', name : '', width : 10, height : 20},
1202    isLandscape : false,
1203    colorMode : 6,
1204    duplexMode : 6,
1205    margin : undefined,
1206    preview : undefined,
1207    options : undefined
1208};
1209print.requestPrintPreview(jobInfo, (num : number) => {
1210    console.log('requestPrintPreview success, num : ' + JSON.stringify(num));
1211
1212})
1213```
1214
1215## requestPrintPreview
1216
1217requestPrintPreview(jobInfo: PrintJob): Promise&lt;number&gt;
1218
1219请求预览打印数据,使用Promise异步回调。
1220
1221**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1222
1223**系统接口:** 此接口为系统接口。
1224
1225**系统能力:** SystemCapability.Print.PrintFramework
1226
1227**参数:**
1228| **参数名** | **类型** | **必填** | **说明** |
1229| -------- | -------- | -------- | -------- |
1230| jobInfo | PrintJob | 是 | 打印任务信息 |
1231
1232**返回值:**
1233| **类型** | **说明** |
1234| -------- | -------- |
1235| Promise&lt;number&gt; | 请求预览打印数据完成结果 |
1236
1237**示例:**
1238
1239```ts
1240import print from '@ohos.print';
1241import { BusinessError } from '@ohos.base';
1242
1243let jobInfo : print.PrintJob = {
1244    fdList : [0,1],
1245    jobId : 'jobId_12',
1246    printerId : 'printerId_32',
1247    jobState : 3,
1248    copyNumber : 1,
1249    pageRange : {},
1250    isSequential : false,
1251    pageSize : {id : '', name : '', width : 10, height : 20},
1252    isLandscape : false,
1253    colorMode : 6,
1254    duplexMode : 6,
1255    margin : undefined,
1256    preview : undefined,
1257    options : undefined
1258};
1259print.requestPrintPreview(jobInfo).then((num: number) => {
1260    console.log('requestPrintPreview success, num : ' + JSON.stringify(num));
1261}).catch((error: BusinessError) => {
1262    console.log('requestPrintPreview failed, because : ' + JSON.stringify(error));
1263})
1264```
1265
1266## on
1267
1268on(type: 'printerStateChange', callback: (state: PrinterState, info: PrinterInfo) => void): void
1269
1270注册打印机状态变化事件回调,使用callback回调。
1271
1272**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1273
1274**系统接口:** 此接口为系统接口。
1275
1276**系统能力:** SystemCapability.Print.PrintFramework
1277
1278**参数:**
1279| **参数名** | **类型** | **必填** | **说明** |
1280| -------- | -------- | -------- | -------- |
1281| type | 'printerStateChange' | 是 | 表示打印机状态改变 |
1282| callback | (state: PrinterState, info: PrinterInfo) => void | 是 | 打印机状态改变之后的回调 |
1283
1284**示例:**
1285
1286```ts
1287import print from '@ohos.print';
1288
1289print.on('printerStateChange', (state: print.PrinterState, info: print.PrinterInfo) => {
1290    if (state === null || info === null) {
1291        console.log('printer state changed state is null or info is null');
1292        return;
1293    } else {
1294        console.log('on printer state changed, state : ' + JSON.stringify(state));
1295        console.log('on printer state changed, info : ' + JSON.stringify(info));
1296    }
1297})
1298```
1299
1300## off
1301
1302off(type: 'printerStateChange', callback?: Callback&lt;boolean&gt;): void
1303
1304取消注册打印机状态变化事件回调,使用callback回调。
1305
1306**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1307
1308**系统接口:** 此接口为系统接口。
1309
1310**系统能力:** SystemCapability.Print.PrintFramework
1311
1312**参数:**
1313| **参数名** | **类型** | **必填** | **说明** |
1314| -------- | -------- | -------- | -------- |
1315| type | 'printerStateChange' | 是 | 表示打印机状态改变 |
1316| callback | Callback&lt;boolean&gt; | 否 | 打印机状态改变之后的回调 |
1317
1318**示例:**
1319
1320```ts
1321import print from '@ohos.print';
1322import { BusinessError } from '@ohos.base';
1323
1324print.off('printerStateChange', (err: BusinessError, data: boolean) => {
1325    if (err) {
1326        console.log('off printerStateChange failed, because : ' + JSON.stringify(err));
1327    } else {
1328        console.log('off printerStateChange data : ' + JSON.stringify(data));
1329    }
1330})
1331```
1332
1333## on
1334
1335on(type: 'jobStateChange', callback: (state: PrintJobState, job: PrintJob) => void): void
1336
1337注册打印任务状态变化事件回调,使用callback回调。
1338
1339**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1340
1341**系统接口:** 此接口为系统接口。
1342
1343**系统能力:** SystemCapability.Print.PrintFramework
1344
1345**参数:**
1346| **参数名** | **类型** | **必填** | **说明** |
1347| -------- | -------- | -------- | -------- |
1348| type | 'jobStateChange' | 是 | 表示打印任务状态改变 |
1349| callback | (state: PrintJobState, job: PrintJob) => void | 是 | 打印任务状态改变之后的回调 |
1350
1351**示例:**
1352
1353```ts
1354import print from '@ohos.print';
1355
1356print.on('jobStateChange', (state: print.PrintJobState, job: print.PrintJob) => {
1357    console.log('onJobStateChange, state : ' + JSON.stringify(state) + ', job : ' + JSON.stringify(job));
1358})
1359```
1360
1361## off
1362
1363off(type: 'jobStateChange', callback?: Callback&lt;boolean&gt;): void
1364
1365取消注册打印任务状态变化事件回调,使用callback回调。
1366
1367**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1368
1369**系统接口:** 此接口为系统接口。
1370
1371**系统能力:** SystemCapability.Print.PrintFramework
1372
1373**参数:**
1374| **参数名** | **类型** | **必填** | **说明** |
1375| -------- | -------- | -------- | -------- |
1376| type | 'jobStateChange' | 是 | 表示打印任务状态改变 |
1377| callback | Callback&lt;boolean&gt; | 否 | 打印任务状态改变之后的回调 |
1378
1379**示例:**
1380
1381```ts
1382import print from '@ohos.print';
1383import { BusinessError } from '@ohos.base';
1384
1385print.off('jobStateChange', (err: BusinessError, data: boolean) => {
1386    if (err) {
1387        console.log('offJobStateChanged failed, because : ' + JSON.stringify(err));
1388    } else {
1389        console.log('offJobStateChanged data : ' + JSON.stringify(data));
1390    }
1391})
1392```
1393
1394## on
1395
1396on(type: 'extInfoChange', callback: (extensionId: string, info: string) => void): void
1397
1398注册打印扩展信息变化事件回调,使用callback回调。
1399
1400**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1401
1402**系统接口:** 此接口为系统接口。
1403
1404**系统能力:** SystemCapability.Print.PrintFramework
1405
1406**参数:**
1407| **参数名** | **类型** | **必填** | **说明** |
1408| -------- | -------- | -------- | -------- |
1409| type | 'extInfoChange' | 是 | 表示打印扩展信息改变 |
1410| callback | (extensionId: string, info: string) => void | 是 | 打印扩展信息改变之后的回调 |
1411
1412**示例:**
1413
1414```ts
1415import print from '@ohos.print';
1416
1417print.on('extInfoChange', (extensionId: string, info: string) => {
1418    console.log('onExtInfoChange, entensionId : ' + JSON.stringify(extensionId) + ', info : ' + JSON.stringify(info));
1419})
1420```
1421
1422## off
1423
1424off(type: 'extInfoChange', callback?: Callback&lt;boolean&gt;): void
1425
1426取消注册打印扩展信息变化事件回调,使用callback回调。
1427
1428**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1429
1430**系统接口:** 此接口为系统接口。
1431
1432**系统能力:** SystemCapability.Print.PrintFramework
1433
1434**参数:**
1435| **参数名** | **类型** | **必填** | **说明** |
1436| -------- | -------- | -------- | -------- |
1437| type | 'extInfoChange' | 是 | 表示打印扩展信息改变 |
1438| callback | Callback&lt;boolean&gt; | 否 | 打印任务扩展信息改变之后的回调 |
1439
1440**示例:**
1441
1442```ts
1443import print from '@ohos.print';
1444import { BusinessError } from '@ohos.base';
1445
1446print.off('extInfoChange', (err: BusinessError, data: boolean) => {
1447    if (err) {
1448        console.log('offExtInfoChange failed, because : ' + JSON.stringify(err));
1449    } else {
1450        console.log('offExtInfoChange data : ' + JSON.stringify(data));
1451    }
1452})
1453```
1454
1455## addPrinters
1456
1457addPrinters(printers: Array&lt;PrinterInfo&gt;, callback: AsyncCallback&lt;void&gt;): void
1458
1459添加打印机,使用callback异步回调。
1460
1461**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1462
1463**系统接口:** 此接口为系统接口。
1464
1465**系统能力:** SystemCapability.Print.PrintFramework
1466
1467**参数:**
1468| **参数名** | **类型** | **必填** | **说明** |
1469| -------- | -------- | -------- | -------- |
1470| printers | Array&lt;PrinterInfo&gt; | 是 | 表示新到达的打印机列表 |
1471| callback | AsyncCallback&lt;void&gt; | 是 | 异步添加打印机之后的回调 |
1472
1473**示例:**
1474
1475```ts
1476import print from '@ohos.print';
1477import { BusinessError } from '@ohos.base';
1478
1479let printerInfo : print.PrinterInfo = {
1480    printerId : '3232',
1481    printerName : 'hhhhh',
1482    printerState : 0,
1483    printerIcon : 12,
1484    description : 'str',
1485    capability : undefined,
1486    options : 'opt'
1487};
1488print.addPrinters([printerInfo], (err: BusinessError, data : void) => {
1489    if (err) {
1490        console.log('addPrinters failed, because : ' + JSON.stringify(err));
1491    } else {
1492        console.log('addPrinters success, data : ' + JSON.stringify(data));
1493    }
1494})
1495```
1496
1497## addPrinters
1498
1499addPrinters(printers: Array&lt;PrinterInfo&gt;): Promise&lt;void&gt;
1500
1501添加打印机,使用Promise异步回调。
1502
1503**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1504
1505**系统接口:** 此接口为系统接口。
1506
1507**系统能力:** SystemCapability.Print.PrintFramework
1508
1509**参数:**
1510| **参数名** | **类型** | **必填** | **说明** |
1511| -------- | -------- | -------- | -------- |
1512| printers | Array&lt;PrinterInfo&gt; | 是 | 表示新到达的打印机列表 |
1513
1514**返回值:**
1515| **类型** | **说明** |
1516| -------- | -------- |
1517| Promise&lt;void&gt; | 添加打印机完成结果 |
1518
1519**示例:**
1520
1521```ts
1522import print from '@ohos.print';
1523import { BusinessError } from '@ohos.base';
1524
1525let printerInfo : print.PrinterInfo = {
1526    printerId : '3232',
1527    printerName : 'hhhhh',
1528    printerState : 0,
1529    printerIcon : 12,
1530    description : 'str',
1531    capability : undefined,
1532    options : 'opt'
1533};
1534print.addPrinters([printerInfo]).then((data : void) => {
1535    console.log('add printers data : ' + JSON.stringify(data));
1536}).catch((error: BusinessError) => {
1537    console.log('add printers error : ' + JSON.stringify(error));
1538})
1539```
1540
1541## removePrinters
1542
1543removePrinters(printerIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
1544
1545移除打印机,使用callback异步回调。
1546
1547**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1548
1549**系统接口:** 此接口为系统接口。
1550
1551**系统能力:** SystemCapability.Print.PrintFramework
1552
1553**参数:**
1554| **参数名** | **类型** | **必填** | **说明** |
1555| -------- | -------- | -------- | -------- |
1556| printerIds | Array&lt;string&gt; | 是 | 表示需移除的打印机列表 |
1557| callback | AsyncCallback&lt;void&gt; | 是 | 异步移除打印机之后的回调 |
1558
1559**示例:**
1560
1561```ts
1562import print from '@ohos.print';
1563import { BusinessError } from '@ohos.base';
1564
1565let printerId : string = '1212';
1566print.removePrinters([printerId], (err: BusinessError, data : void) => {
1567    if (err) {
1568        console.log('removePrinters failed, because : ' + JSON.stringify(err));
1569    } else {
1570        console.log('removePrinters success, data : ' + JSON.stringify(data));
1571    }
1572})
1573```
1574
1575## removePrinters
1576
1577removePrinters(printerIds: Array&lt;string&gt;): Promise&lt;void&gt;
1578
1579移除打印机,使用Promise异步回调。
1580
1581**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1582
1583**系统接口:** 此接口为系统接口。
1584
1585**系统能力:** SystemCapability.Print.PrintFramework
1586
1587**参数:**
1588| **参数名** | **类型** | **必填** | **说明** |
1589| -------- | -------- | -------- | -------- |
1590| printerIds | Array&lt;string&gt; | 是 | 表示需移除的打印机列表 |
1591
1592**返回值:**
1593| **类型** | **说明** |
1594| -------- | -------- |
1595| Promise&lt;void&gt; | 移除打印机完成结果 |
1596
1597**示例:**
1598
1599```ts
1600import print from '@ohos.print';
1601import { BusinessError } from '@ohos.base';
1602
1603let printerId : string = '1212';
1604print.removePrinters([printerId]).then((data : void) => {
1605    console.log('remove printers data : ' + JSON.stringify(data));
1606}).catch((error: BusinessError) => {
1607    console.log('remove printers error : ' + JSON.stringify(error));
1608})
1609```
1610
1611## updatePrinters
1612
1613updatePrinters(printers: Array&lt;PrinterInfo&gt;, callback: AsyncCallback&lt;void&gt;): void
1614
1615更新特定打印机的信息,使用callback异步回调。
1616
1617**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1618
1619**系统接口:** 此接口为系统接口。
1620
1621**系统能力:** SystemCapability.Print.PrintFramework
1622
1623**参数:**
1624| **参数名** | **类型** | **必填** | **说明** |
1625| -------- | -------- | -------- | -------- |
1626| printers | Array&lt;PrinterInfo&gt; | 是 | 表示待更新的打印机列表 |
1627| callback | AsyncCallback&lt;void&gt; | 是 | 异步更新打印机信息之后的回调 |
1628
1629**示例:**
1630
1631```ts
1632import print from '@ohos.print';
1633import { BusinessError } from '@ohos.base';
1634
1635let printerInfo : print.PrinterInfo = {
1636    printerId : '3232',
1637    printerName : 'hhhhh',
1638    printerState : 0,
1639    printerIcon : 12,
1640    description : 'str',
1641    capability : undefined,
1642    options : 'opt'
1643};
1644print.updatePrinters([printerInfo], (err: BusinessError, data : void) => {
1645    if (err) {
1646        console.log('updataPrinters failed, because : ' + JSON.stringify(err));
1647    } else {
1648        console.log('updataPrinters success, data : ' + JSON.stringify(data));
1649    }
1650})
1651```
1652
1653## updatePrinters
1654
1655updatePrinters(printers: Array&lt;PrinterInfo&gt;): Promise&lt;void&gt;
1656
1657更新特定打印机的信息,使用Promise异步回调。
1658
1659**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1660
1661**系统接口:** 此接口为系统接口。
1662
1663**系统能力:** SystemCapability.Print.PrintFramework
1664
1665**参数:**
1666| **参数名** | **类型** | **必填** | **说明** |
1667| -------- | -------- | -------- | -------- |
1668| printers | Array&lt;PrinterInfo&gt; | 是 | 表示待更新的打印机列表 |
1669
1670**返回值:**
1671| **类型** | **说明** |
1672| -------- | -------- |
1673| Promise&lt;void&gt; | 更新打印机完成结果 |
1674
1675**示例:**
1676
1677```ts
1678import print from '@ohos.print';
1679import { BusinessError } from '@ohos.base';
1680
1681let printerInfo : print.PrinterInfo = {
1682    printerId : '3232',
1683    printerName : 'hhhhh',
1684    printerState : 0,
1685    printerIcon : 12,
1686    description : 'str',
1687    capability : undefined,
1688    options : 'opt'
1689};
1690print.updatePrinters([printerInfo]).then((data : void) => {
1691    console.log('update printers data : ' + JSON.stringify(data));
1692}).catch((error: BusinessError) => {
1693    console.log('update printers error : ' + JSON.stringify(error));
1694})
1695```
1696
1697## updatePrinterState
1698
1699updatePrinterState(printerId: string, state: PrinterState, callback: AsyncCallback&lt;void&gt;): void
1700
1701更新打印机状态,使用callback异步回调。
1702
1703**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1704
1705**系统接口:** 此接口为系统接口。
1706
1707**系统能力:** SystemCapability.Print.PrintFramework
1708
1709**参数:**
1710| **参数名** | **类型** | **必填** | **说明** |
1711| -------- | -------- | -------- | -------- |
1712| printerId | string | 是 | 表示打印机ID |
1713| state | PrinterState | 是 | 表示打印机状态 |
1714| callback | AsyncCallback&lt;void&gt; | 是 | 异步更新打印机状态之后的回调 |
1715
1716**示例:**
1717
1718```ts
1719import print from '@ohos.print';
1720import { BusinessError } from '@ohos.base';
1721
1722let printerId : string = '1212';
1723let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED;
1724print.updatePrinterState(printerId, state, (err: BusinessError, data : void) => {
1725    if (err) {
1726        console.log('updataPrinterState failed, because : ' + JSON.stringify(err));
1727    } else {
1728        console.log('updataPrinterState success, data : ' + JSON.stringify(data));
1729    }
1730})
1731```
1732
1733## updatePrinterState
1734
1735updatePrinterState(printerId: string, state: PrinterState): Promise&lt;void&gt;
1736
1737更新打印机状态,使用Promise异步回调。
1738
1739**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1740
1741**系统接口:** 此接口为系统接口。
1742
1743**系统能力:** SystemCapability.Print.PrintFramework
1744
1745**参数:**
1746| **参数名** | **类型** | **必填** | **说明** |
1747| -------- | -------- | -------- | -------- |
1748| printerId | string | 是 | 表示打印机ID |
1749| state | PrinterState | 是 | 表示打印机状态 |
1750
1751**返回值:**
1752| **类型** | **说明** |
1753| -------- | -------- |
1754| Promise&lt;void&gt; | 更新打印机状态完成结果 |
1755
1756**示例:**
1757
1758```ts
1759import print from '@ohos.print';
1760import { BusinessError } from '@ohos.base';
1761
1762let printerId : string = '1212';
1763let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED;
1764print.updatePrinterState(printerId, state).then((data : void) => {
1765    console.log('update printer state data : ' + JSON.stringify(data));
1766}).catch((error: BusinessError) => {
1767    console.log('update printer state error : ' + JSON.stringify(error));
1768})
1769```
1770
1771## updatePrintJobState
1772
1773updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState, callback: AsyncCallback&lt;void&gt;): void
1774
1775更新打印任务状态,使用callback异步回调。
1776
1777**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1778
1779**系统接口:** 此接口为系统接口。
1780
1781**系统能力:** SystemCapability.Print.PrintFramework
1782
1783**参数:**
1784| **参数名** | **类型** | **必填** | **说明** |
1785| -------- | -------- | -------- | -------- |
1786| jobId | string | 是 | 表示打印任务ID |
1787| state | PrintJobState | 是 | 表示打印任务状态 |
1788| subState | PrintJobSubState | 是 | 表示打印任务子状态 |
1789| callback | AsyncCallback&lt;void&gt; | 是 | 异步更新打印任务状态之后的回调 |
1790
1791**示例:**
1792
1793```ts
1794import print from '@ohos.print';
1795import { BusinessError } from '@ohos.base';
1796
1797let jobId : string = '3434';
1798let state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE;
1799let subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS;
1800print.updatePrintJobState(jobId, state, subState, (err: BusinessError, data : void) => {
1801    if (err) {
1802        console.log('updataPrintJobState failed, because : ' + JSON.stringify(err));
1803    } else {
1804        console.log('updatePrintJobState success, data : ' + JSON.stringify(data));
1805    }
1806})
1807```
1808
1809## updatePrintJobState
1810
1811updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState): Promise&lt;void&gt;
1812
1813更新打印任务状态,使用Promise异步回调。
1814
1815**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1816
1817**系统接口:** 此接口为系统接口。
1818
1819**系统能力:** SystemCapability.Print.PrintFramework
1820
1821**参数:**
1822| **参数名** | **类型** | **必填** | **说明** |
1823| -------- | -------- | -------- | -------- |
1824| jobId | string | 是 | 表示打印任务ID |
1825| state | PrintJobState | 是 | 表示打印任务状态 |
1826| subState | PrintJobSubState | 是 | 表示打印任务子状态 |
1827
1828**返回值:**
1829| **类型** | **说明** |
1830| -------- | -------- |
1831| Promise&lt;void&gt; | 更新打印任务状态完成结果 |
1832
1833**示例:**
1834
1835```ts
1836import print from '@ohos.print';
1837import { BusinessError } from '@ohos.base';
1838
1839let jobId : string = '3434';
1840let state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE;
1841let subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS;
1842print.updatePrintJobState(jobId, state, subState).then((data : void) => {
1843    console.log('update print job state data : ' + JSON.stringify(data));
1844}).catch((error: BusinessError) => {
1845    console.log('update print job state error : ' + JSON.stringify(error));
1846})
1847```
1848
1849## updateExtensionInfo
1850
1851updateExtensionInfo(info: string, callback: AsyncCallback&lt;void&gt;): void
1852
1853更新打印扩展状态,使用callback异步回调。
1854
1855**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1856
1857**系统接口:** 此接口为系统接口。
1858
1859**系统能力:** SystemCapability.Print.PrintFramework
1860
1861**参数:**
1862| **参数名** | **类型** | **必填** | **说明** |
1863| -------- | -------- | -------- | -------- |
1864| info | string | 是 | 表示打印扩展变更信息 |
1865| callback | AsyncCallback&lt;void&gt; | 是 | 异步更新打印扩展状态之后的回调 |
1866
1867**示例:**
1868
1869```ts
1870import print from '@ohos.print';
1871import { BusinessError } from '@ohos.base';
1872
1873let info : string = 'WIFI_INACTIVE';
1874print.updateExtensionInfo(info, (err: BusinessError, data : void) => {
1875    if (err) {
1876        console.log('updateExtensionInfo failed, because : ' + JSON.stringify(err));
1877    } else {
1878        console.log('updateExtensionInfo success, data : ' + JSON.stringify(data));
1879    }
1880})
1881```
1882
1883## updateExtensionInfo
1884
1885updateExtensionInfo(info: string): Promise&lt;void&gt;
1886
1887更新打印扩展状态,使用Promise异步回调。
1888
1889**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1890
1891**系统接口:** 此接口为系统接口。
1892
1893**系统能力:** SystemCapability.Print.PrintFramework
1894
1895**参数:**
1896| **参数名** | **类型** | **必填** | **说明** |
1897| -------- | -------- | -------- | -------- |
1898| info | string | 是 | 表示打印扩展变更信息 |
1899
1900**返回值:**
1901| **类型** | **说明** |
1902| -------- | -------- |
1903| Promise&lt;void&gt; | 更新打印扩展状态完成结果 |
1904
1905**示例:**
1906
1907```ts
1908import print from '@ohos.print';
1909import { BusinessError } from '@ohos.base';
1910
1911let info : string = 'WIFI_INACTIVE';
1912print.updateExtensionInfo(info).then((data : void) => {
1913    console.log('update print job state data : ' + JSON.stringify(data));
1914}).catch((error: BusinessError) => {
1915    console.log('update print job state error : ' + JSON.stringify(error));
1916})
1917```
1918
1919## queryAllPrintJobs
1920
1921queryAllPrintJobs(callback: AsyncCallback&lt;void&gt;): void
1922
1923查询所有打印任务,使用callback异步回调。
1924
1925**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1926
1927**系统接口:** 此接口为系统接口。
1928
1929**系统能力:** SystemCapability.Print.PrintFramework
1930
1931**参数:**
1932| **参数名** | **类型** | **必填** | **说明** |
1933| -------- | -------- | -------- | -------- |
1934| callback | AsyncCallback&lt;void&gt; | 是 | 异步查询所有打印任务之后的回调 |
1935
1936**示例:**
1937
1938```ts
1939import print from '@ohos.print';
1940import { BusinessError } from '@ohos.base';
1941
1942print.queryAllPrintJobs((err: BusinessError, data : void) => {
1943    if (err) {
1944        console.log('queryAllPrintJobs failed, because : ' + JSON.stringify(err));
1945    } else {
1946        console.log('queryAllPrintJobs success, data : ' + JSON.stringify(data));
1947    }
1948})
1949```
1950
1951## queryAllPrintJobs
1952
1953queryAllPrintJobs(): Promise&lt;void&gt;
1954
1955查询所有打印任务,使用Promise异步回调。
1956
1957**需要权限:** ohos.permission.MANAGE_PRINT_JOB
1958
1959**系统接口:** 此接口为系统接口。
1960
1961**系统能力:** SystemCapability.Print.PrintFramework
1962
1963**返回值:**
1964| **类型** | **说明** |
1965| -------- | -------- |
1966| Promise&lt;void&gt; | 查询所有打印任务完成结果 |
1967
1968**示例:**
1969
1970```ts
1971import print from '@ohos.print';
1972import { BusinessError } from '@ohos.base';
1973
1974print.queryAllPrintJobs().then((data : void) => {
1975    console.log('update print job state data : ' + JSON.stringify(data));
1976}).catch((error: BusinessError) => {
1977    console.log('update print job state error : ' + JSON.stringify(error));
1978})
1979```