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