• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.print (Print) (System API)
2
3<!--Kit: Basic Services Kit-->
4<!--Subsystem: Print-->
5<!--Owner: @guoshengbang-->
6<!--Designer: @gcw_4D6e0BBd-->
7<!--Tester: @guoshengbang-->
8<!--Adviser: @RayShih-->
9
10The **print** module provides APIs for basic print operations.
11
12> **NOTE**
13> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
14> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.print (Print)](./js-apis-print-sys.md).
15
16## Modules to Import
17
18```ts
19import { print } from '@kit.BasicServicesKit';
20```
21
22
23## PrintMargin
24
25Defines the page margins for printing.
26
27**System API**: This is a system API.
28
29**System capability**: SystemCapability.Print.PrintFramework
30
31**Attributes**
32| **Name**| **Type**| **Mandatory**| **Description**|
33| -------- | -------- | -------- | -------- |
34| top | number | No| Top margin of the page. The default value is **0**.|
35| bottom | number | No| Bottom margin of the page. The default value is **0**.|
36| left | number | No| Left margin of the page. The default value is **0**.|
37| right | number | No| Right margin of the page. The default value is **0**.|
38
39## PrinterRange
40
41Defines the print range.
42
43**System API**: This is a system API.
44
45**System capability**: SystemCapability.Print.PrintFramework
46
47**Attributes**
48| **Name**| **Type**| **Mandatory**| **Description**|
49| -------- | -------- | -------- | -------- |
50| startPage | number | No| Start page. The default value is **1**.|
51| endPage | number | No| End page. The default value is the maximum number of pages of the file to be printed.|
52| pages | Array&lt;number&gt; | No| Page range set of the file to print. The default value is empty.|
53
54## PreviewAttribute
55
56Defines the print preview attributes.
57
58**System API**: This is a system API.
59
60**System capability**: SystemCapability.Print.PrintFramework
61
62**Attributes**
63| **Name**| **Type**| **Mandatory**| **Description**|
64| -------- | -------- | -------- | -------- |
65| previewRange | [PrinterRange](#printerrange) | Yes| Preview page range.|
66| result | number | No| Print preview result. The default value is **-1**.|
67
68## PrintResolution
69
70Defines the resolution for printing.
71
72**System API**: This is a system API.
73
74**System capability**: SystemCapability.Print.PrintFramework
75
76**Attributes**
77| **Name**| **Type**| **Mandatory**| **Description**|
78| -------- | -------- | -------- | -------- |
79| id | string | Yes| Resolution ID.|
80| horizontalDpi | number | Yes| Horizontal DPI.|
81| verticalDpi | number | Yes| Vertical DPI.|
82
83
84
85## PrinterCapability
86
87Defines the printer capabilities.
88
89**System API**: This is a system API.
90
91**System capability**: SystemCapability.Print.PrintFramework
92
93**Attributes**
94| **Name**| **Type**| **Mandatory**| **Description**|
95| -------- | -------- | -------- | -------- |
96| colorMode | number | Yes| Color mode.|
97| duplexMode | number | Yes| Single-sided or double-sided printing mode.|
98| pageSize | Array&lt;[PrintPageSize](./js-apis-print.md#printpagesize11)&gt; | Yes| List of page sizes supported by the printer.|
99| resolution | Array&lt;[PrintResolution](#printresolution)&gt; | No| List of resolutions supported by the printer.|
100| minMargin | [PrintMargin](#printmargin) | No| Minimum margin of the printer.|
101| options<sup>11+</sup> | Object | No| Printer options. The value is a JSON object string.|
102
103## PrinterInfo
104
105Provides the printer information.
106
107**System API**: This is a system API.
108
109**System capability**: SystemCapability.Print.PrintFramework
110
111**Attributes**
112| **Name**| **Type**| **Mandatory**| **Description**|
113| -------- | -------- | -------- | -------- |
114| printerId | string | Yes| Printer ID.|
115| printerName | string | Yes| Printer name.|
116| printerState | [PrinterState](./js-apis-print.md#printerstate14) | Yes| Printer state.|
117| printerIcon | number | No| Resource ID of the printer icon. The default value is **-1**.|
118| description | string | No| Printer description.|
119| capability | [PrinterCapability](#printercapability) | No| Printer capability.|
120| options | Object | No| Printer options. The value is a JSON object string.|
121
122## PrintJob
123
124Defines a print job.
125
126**System API**: This is a system API.
127
128**System capability**: SystemCapability.Print.PrintFramework
129
130**Attributes**
131| **Name**| **Type**| **Mandatory**| **Description**|
132| -------- | -------- | -------- | -------- |
133| fdList | Array&lt;number&gt; | Yes| FD list of files to print.|
134| jobId | string | Yes| ID of the print job.|
135| printerId | string | Yes| ID of the printer used for printing.|
136| jobState | [PrintJobState](./js-apis-print.md#printjobstate14) | Yes| State of the print job.|
137| jobSubstate<sup>11+</sup> | [PrintJobSubState](./js-apis-print.md#printjobsubstate14) | Yes| Substate of the print job.|
138| copyNumber | number | Yes| Copy of the file list.|
139| pageRange | [PrinterRange](#printerrange) | Yes| Print range.|
140| isSequential | boolean | Yes| Whether the printing is sequential. The value **true** means that the printing is sequential; the value **false** means the opposite. The default value is **false**.|
141| pageSize | [PrintPageSize](./js-apis-print.md#printpagesize11) | Yes| Selected page size.|
142| isLandscape | boolean | Yes| Whether the printing is in landscape mode. The value **true** means that the printing is in landscape mode; the value **false** means the printing is in portrait mode The default value is **false**.|
143| colorMode | number | Yes| Color mode.|
144| duplexMode | number | Yes| Single-sided or double-sided printing mode.|
145| margin | [PrintMargin](#printmargin) | No| Current page margin.|
146| preview | [PreviewAttribute](#previewattribute) | No| Preview settings.|
147| options | Object | No| Printer options. The value is a JSON object string.|
148
149## PrinterExtensionInfo
150
151Provides the printer extension information.
152
153**System API**: This is a system API.
154
155**System capability**: SystemCapability.Print.PrintFramework
156
157**Attributes**
158| **Name**| **Type**| **Mandatory**| **Description**|
159| -------- | -------- | -------- | -------- |
160| extensionId | string | Yes| ID of the printer extension.|
161| vendorId | string | Yes| Vendor ID of the printer extension.|
162| vendorName | string | Yes| Vendor name of the printer extension.|
163| vendorIcon | number | Yes| Vendor icon of the printer extension.|
164| version | string | Yes| Version of the printer extension.|
165
166## print.queryAllPrinterExtensionInfos
167
168queryAllPrinterExtensionInfos(callback: AsyncCallback&lt;Array&lt;PrinterExtensionInfo&gt;&gt;): void
169
170Obtains the information of all installed printer extensions. This API uses an asynchronous callback to return the result.
171
172**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
173
174**System API**: This is a system API.
175
176**System capability**: SystemCapability.Print.PrintFramework
177
178**Parameters**
179| **Name**| **Type**| **Mandatory**| **Description**|
180| -------- | -------- | -------- | -------- |
181| callback | AsyncCallback&lt;Array&lt;[PrinterExtensionInfo](#printerextensioninfo)&gt;&gt; | Yes| Callback used to return the result.|
182
183**Error codes**
184
185For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
186
187| ID| Error Message                                   |
188| -------- | ------------------------------------------- |
189| 201 | the application does not have permission to call this function. |
190| 202 | not system application |
191
192**Example**
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
211Obtains the information of all installed printer extensions. This API uses a promise to return the result.
212
213**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
214
215**System API**: This is a system API.
216
217**System capability**: SystemCapability.Print.PrintFramework
218
219**Return value**
220| **Type**| **Description**|
221| -------- | -------- |
222| Promise&lt;Array&lt;[PrinterExtensionInfo](#printerextensioninfo)&gt;&gt; | Promise used to return the result.used to return the result.|
223
224**Error codes**
225
226For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
227
228| ID| Error Message                                   |
229| -------- | ------------------------------------------- |
230| 201 | the application does not have permission to call this function. |
231| 202 | not system application |
232
233**Example**
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
251Disconnects from the specified printer. This API uses an asynchronous callback to return the result.
252
253**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
254
255**System API**: This is a system API.
256
257**System capability**: SystemCapability.Print.PrintFramework
258
259**Parameters**
260| **Name**| **Type**| **Mandatory**| **Description**|
261| -------- | -------- | -------- | -------- |
262| printerId | string | Yes| Printer ID.|
263| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
264
265**Error codes**
266
267For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
268
269| ID| Error Message                                   |
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**Example**
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
295Disconnects from the specified printer. This API uses a promise to return the result.
296
297**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
298
299**System API**: This is a system API.
300
301**System capability**: SystemCapability.Print.PrintFramework
302
303**Parameters**
304| **Name**| **Type**| **Mandatory**| **Description**|
305| -------- | -------- | -------- | -------- |
306| printerId | string | Yes| Printer ID.|
307
308**Return value**
309| **Type**| **Description**|
310| -------- | -------- |
311| Promise&lt;void&gt; | Promise used to return the result.|
312
313**Error codes**
314
315For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
316
317| ID| Error Message                                   |
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**Example**
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
341Queries the printer capability. This API uses an asynchronous callback to return the result.
342
343**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
344
345**System API**: This is a system API.
346
347**System capability**: SystemCapability.Print.PrintFramework
348
349**Parameters**
350| **Name**| **Type**| **Mandatory**| **Description**|
351| -------- | -------- | -------- | -------- |
352| printerId | string | Yes| Printer ID.|
353| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
354
355**Error codes**
356
357For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
358
359| ID| Error Message                                   |
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**Example**
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
385Queries the printer capability. This API uses a promise to return the result.
386
387**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
388
389**System API**: This is a system API.
390
391**System capability**: SystemCapability.Print.PrintFramework
392
393**Parameters**
394| **Name**| **Type**| **Mandatory**| **Description**|
395| -------- | -------- | -------- | -------- |
396| printerId | string | Yes| Printer ID.|
397
398**Return value**
399| **Type**| **Description**|
400| -------- | -------- |
401| Promise&lt;void&gt; | Promise used to return the result.|
402
403**Error codes**
404
405For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
406
407| ID| Error Message                                   |
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**Example**
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
431Starts the specified print job. This API uses an asynchronous callback to return the result.
432
433**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
434
435**System API**: This is a system API.
436
437**System capability**: SystemCapability.Print.PrintFramework
438
439**Parameters**
440| **Name**| **Type**| **Mandatory**| **Description**|
441| -------- | -------- | -------- | -------- |
442| jobInfo | [PrintJob](#printjob) | Yes| Information about the print job.|
443| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
444
445**Error codes**
446
447For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
448
449| ID| Error Message                                   |
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**Example**
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
491Starts the specified print job. This API uses a promise to return the result.
492
493**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
494
495**System API**: This is a system API.
496
497**System capability**: SystemCapability.Print.PrintFramework
498
499**Parameters**
500| **Name**| **Type**| **Mandatory**| **Description**|
501| -------- | -------- | -------- | -------- |
502| jobInfo | [PrintJob](#printjob) | Yes| Information about the print job.|
503
504**Return value**
505| **Type**| **Description**|
506| -------- | -------- |
507| Promise&lt;void&gt; | Promise used to return the result.|
508
509**Error codes**
510
511For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
512
513| ID| Error Message                                   |
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**Example**
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
553Cancels the specified print job, which is on the print queue of the printer. This API uses an asynchronous callback to return the result.
554
555**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
556
557**System API**: This is a system API.
558
559**System capability**: SystemCapability.Print.PrintFramework
560
561**Parameters**
562| **Name**| **Type**| **Mandatory**| **Description**|
563| -------- | -------- | -------- | -------- |
564| jobId | string | Yes| Print job ID.|
565| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
566
567**Error codes**
568
569For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
570
571| ID| Error Message                                   |
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**Example**
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
597Cancels the specified print job, which is on the print queue of the printer. This API uses a promise to return the result.
598
599**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
600
601**System API**: This is a system API.
602
603**System capability**: SystemCapability.Print.PrintFramework
604
605**Parameters**
606| **Name**| **Type**| **Mandatory**| **Description**|
607| -------- | -------- | -------- | -------- |
608| jobId | string | Yes| Print job ID.|
609
610**Return value**
611| **Type**| **Description**|
612| -------- | -------- |
613| Promise&lt;void&gt; | Promise used to return the result.|
614
615**Error codes**
616
617For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
618
619| ID| Error Message                                   |
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**Example**
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
643Restarts a print job that has been finished before. This API uses a promise to return the result.
644
645**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
646
647**System API**: This is a system API.
648
649**System capability**: SystemCapability.Print.PrintFramework
650
651**Parameters**
652| **Name**| **Type**| **Mandatory**| **Description**|
653| -------- | -------- | -------- | -------- |
654| jobId | string | Yes| ID of a print job that has been finished before.|
655
656**Return value**
657| **Type**| **Description**|
658| -------- | -------- |
659| Promise&lt;void&gt; | Promise that returns no value.|
660
661**Error codes**
662
663For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
664
665| ID| Error Message                                   |
666| -------- | ------------------------------------------- |
667| 201 | the application does not have permission to call this function. |
668| 202 | not system application |
669
670**Example**
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
688Requests print preview data. This API uses a callback to return the result.
689
690**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
691
692**System API**: This is a system API.
693
694**System capability**: SystemCapability.Print.PrintFramework
695
696**Parameters**
697| **Name**| **Type**| **Mandatory**| **Description**|
698| -------- | -------- | -------- | -------- |
699| jobInfo | [PrintJob](#printjob) | Yes| Information about the print job.|
700| callback | Callback&lt;number&gt; | Yes| Callback used to return the result.|
701
702**Error codes**
703
704For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
705
706| ID| Error Message                                   |
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**Example**
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
744Requests print preview data. This API uses a promise to return the result.
745
746**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
747
748**System API**: This is a system API.
749
750**System capability**: SystemCapability.Print.PrintFramework
751
752**Parameters**
753| **Name**| **Type**| **Mandatory**| **Description**|
754| -------- | -------- | -------- | -------- |
755| jobInfo | [PrintJob](#printjob) | Yes| Information about the print job.|
756
757**Return value**
758| **Type**| **Description**|
759| -------- | -------- |
760| Promise&lt;number&gt; | Promise used to return the result.|
761
762**Error codes**
763
764For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
765
766| ID| Error Message                                   |
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**Example**
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
806Registers a listener for printer state change events. This API uses a callback to return the result.
807
808**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
809
810**System API**: This is a system API.
811
812**System capability**: SystemCapability.Print.PrintFramework
813
814**Parameters**
815| **Name**| **Type**| **Mandatory**| **Description**|
816| -------- | -------- | -------- | -------- |
817| type | 'printerStateChange' | Yes| Listening type. The value is fixed at **'printerStateChange'**.|
818| callback | (state: [PrinterState](./js-apis-print.md#printerstate14), info: [PrinterInfo](#printerinfo)) => void | Yes| Callback used to return the result.|
819
820**Error codes**
821
822For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
823
824| ID| Error Message                                   |
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**Example**
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
850Unregisters the listener for printer state change events. This API uses a callback to return the result.
851
852**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
853
854**System API**: This is a system API.
855
856**System capability**: SystemCapability.Print.PrintFramework
857
858**Parameters**
859| **Name**| **Type**| **Mandatory**| **Description**|
860| -------- | -------- | -------- | -------- |
861| type | 'printerStateChange' | Yes| Listening type. The value is fixed at **'printerStateChange'**.|
862| callback | Callback&lt;boolean&gt; | No| Callback used to return the result. The value **true** means that the listener for printer state change events is successfully unregistered, and **false** means the opposite.|
863
864**Error codes**
865
866For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
867
868| ID| Error Message                                   |
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**Example**
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
888Registers a listener for print job state change events. This API uses a callback to return the result.
889
890**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
891
892**System API**: This is a system API.
893
894**System capability**: SystemCapability.Print.PrintFramework
895
896**Parameters**
897| **Name**| **Type**| **Mandatory**| **Description**|
898| -------- | -------- | -------- | -------- |
899| type | 'jobStateChange' | Yes| Listening type. The value is fixed at **'jobStateChange'**.|
900| callback | (state: [PrintJobState](./js-apis-print.md#printjobstate14), job: [PrintJob](#printjob)) => void | Yes| Callback used to return the result.|
901
902**Error codes**
903
904For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
905
906| ID| Error Message                                   |
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**Example**
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
926Unregisters the listener for print job state change events. This API uses a callback to return the result.
927
928**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
929
930**System API**: This is a system API.
931
932**System capability**: SystemCapability.Print.PrintFramework
933
934**Parameters**
935| **Name**| **Type**| **Mandatory**| **Description**|
936| -------- | -------- | -------- | -------- |
937| type | 'jobStateChange' | Yes| Listening type. The value is fixed at **'jobStateChange'**.|
938| callback | Callback&lt;boolean&gt; | No| Callback used to return the result. The value **true** means that the listener for print job state change events is successfully unregistered, and **false** means the opposite.|
939
940**Error codes**
941
942For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
943
944| ID| Error Message                                   |
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**Example**
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
964Registers a listener for printer extension information change events. This API uses a callback to return the result.
965
966**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
967
968**System API**: This is a system API.
969
970**System capability**: SystemCapability.Print.PrintFramework
971
972**Parameters**
973| **Name**| **Type**| **Mandatory**| **Description**|
974| -------- | -------- | -------- | -------- |
975| type | 'extInfoChange' | Yes| Listening type. The value is fixed at **'extInfoChange'**.|
976| callback | (extensionId: string, info: string) => void | Yes| Callback used to return the result.|
977
978**Error codes**
979
980For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
981
982| ID| Error Message                                   |
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**Example**
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
1002Unregisters the listener for printer extension information change events. This API uses a callback to return the result.
1003
1004**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1005
1006**System API**: This is a system API.
1007
1008**System capability**: SystemCapability.Print.PrintFramework
1009
1010**Parameters**
1011| **Name**| **Type**| **Mandatory**| **Description**|
1012| -------- | -------- | -------- | -------- |
1013| type | 'extInfoChange' | Yes| Listening type. The value is fixed at **'extInfoChange'**.|
1014| callback | Callback&lt;boolean&gt; | No| Callback used to return the result. The value **true** means that the listener for printer extension information change events is successfully unregistered, and **false** means the opposite.|
1015
1016**Error codes**
1017
1018For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1019
1020| ID| Error Message                                   |
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**Example**
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
1040Adds printers. This API uses an asynchronous callback to return the result.
1041
1042**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1043
1044**System API**: This is a system API.
1045
1046**System capability**: SystemCapability.Print.PrintFramework
1047
1048**Parameters**
1049| **Name**| **Type**| **Mandatory**| **Description**|
1050| -------- | -------- | -------- | -------- |
1051| printers | Array&lt;[PrinterInfo](#printerinfo)&gt; | Yes| List of printers to add.|
1052| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
1053
1054**Error codes**
1055
1056For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1057
1058| ID| Error Message                                   |
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**Example**
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
1092Adds printers. This API uses a promise to return the result.
1093
1094**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1095
1096**System API**: This is a system API.
1097
1098**System capability**: SystemCapability.Print.PrintFramework
1099
1100**Parameters**
1101| **Name**| **Type**| **Mandatory**| **Description**|
1102| -------- | -------- | -------- | -------- |
1103| printers | Array&lt;[PrinterInfo](#printerinfo)&gt; | Yes| List of printers to add.|
1104
1105**Return value**
1106| **Type**| **Description**|
1107| -------- | -------- |
1108| Promise&lt;void&gt; | Promise used to return the result.|
1109
1110**Error codes**
1111
1112For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1113
1114| ID| Error Message                                   |
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**Example**
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
1146Removes printers. This API uses an asynchronous callback to return the result.
1147
1148**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1149
1150**System API**: This is a system API.
1151
1152**System capability**: SystemCapability.Print.PrintFramework
1153
1154**Parameters**
1155| **Name**| **Type**| **Mandatory**| **Description**|
1156| -------- | -------- | -------- | -------- |
1157| printerIds | Array&lt;string&gt; | Yes| List of printers to remove.|
1158| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
1159
1160**Error codes**
1161
1162For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1163
1164| ID| Error Message                                   |
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**Example**
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
1190Removes printers. This API uses a promise to return the result.
1191
1192**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1193
1194**System API**: This is a system API.
1195
1196**System capability**: SystemCapability.Print.PrintFramework
1197
1198**Parameters**
1199| **Name**| **Type**| **Mandatory**| **Description**|
1200| -------- | -------- | -------- | -------- |
1201| printerIds | Array&lt;string&gt; | Yes| List of printers to remove.|
1202
1203**Return value**
1204| **Type**| **Description**|
1205| -------- | -------- |
1206| Promise&lt;void&gt; | Promise used to return the result.|
1207
1208**Error codes**
1209
1210For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1211
1212| ID| Error Message                                   |
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**Example**
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
1236Updates information about the specified printers. This API uses an asynchronous callback to return the result.
1237
1238**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1239
1240**System API**: This is a system API.
1241
1242**System capability**: SystemCapability.Print.PrintFramework
1243
1244**Parameters**
1245| **Name**| **Type**| **Mandatory**| **Description**|
1246| -------- | -------- | -------- | -------- |
1247| printers | Array&lt;[PrinterInfo](#printerinfo)&gt; | Yes| List of printers whose information is to be updated.|
1248| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
1249
1250**Error codes**
1251
1252For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1253
1254| ID| Error Message                                   |
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**Example**
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
1288Updates information about the specified printers. This API uses a promise to return the result.
1289
1290**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1291
1292**System API**: This is a system API.
1293
1294**System capability**: SystemCapability.Print.PrintFramework
1295
1296**Parameters**
1297| **Name**| **Type**| **Mandatory**| **Description**|
1298| -------- | -------- | -------- | -------- |
1299| printers | Array&lt;[PrinterInfo](#printerinfo)&gt; | Yes| List of printers whose information is to be updated.|
1300
1301**Return value**
1302| **Type**| **Description**|
1303| -------- | -------- |
1304| Promise&lt;void&gt; | Promise used to return the result.|
1305
1306**Error codes**
1307
1308For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1309
1310| ID| Error Message                                   |
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**Example**
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
1342Updates the printer state. This API uses an asynchronous callback to return the result.
1343
1344**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1345
1346**System API**: This is a system API.
1347
1348**System capability**: SystemCapability.Print.PrintFramework
1349
1350**Parameters**
1351| **Name**| **Type**| **Mandatory**| **Description**|
1352| -------- | -------- | -------- | -------- |
1353| printerId | string | Yes| Printer ID.|
1354| state | [PrinterState](./js-apis-print.md#printerstate14) | Yes| Printer state.|
1355| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
1356
1357**Error codes**
1358
1359For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1360
1361| ID| Error Message                                   |
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**Example**
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
1388Updates the printer state. This API uses a promise to return the result.
1389
1390**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1391
1392**System API**: This is a system API.
1393
1394**System capability**: SystemCapability.Print.PrintFramework
1395
1396**Parameters**
1397| **Name**| **Type**| **Mandatory**| **Description**|
1398| -------- | -------- | -------- | -------- |
1399| printerId | string | Yes| Printer ID.|
1400| state | [PrinterState](./js-apis-print.md#printerstate14) | Yes| Printer state.|
1401
1402**Return value**
1403| **Type**| **Description**|
1404| -------- | -------- |
1405| Promise&lt;void&gt; | Promise used to return the result.|
1406
1407**Error codes**
1408
1409For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1410
1411| ID| Error Message                                   |
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**Example**
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
1436Updates the print job state. This API uses an asynchronous callback to return the result.
1437
1438**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1439
1440**System API**: This is a system API.
1441
1442**System capability**: SystemCapability.Print.PrintFramework
1443
1444**Parameters**
1445| **Name**| **Type**| **Mandatory**| **Description**|
1446| -------- | -------- | -------- | -------- |
1447| jobId | string | Yes| ID of the print job.|
1448| state | [PrintJobState](./js-apis-print.md#printjobstate14) | Yes| State of the print job.|
1449| subState | [PrintJobSubState](./js-apis-print.md#printjobsubstate14) | Yes| Substate of the print job.|
1450| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
1451
1452**Error codes**
1453
1454For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1455
1456| ID| Error Message                                   |
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**Example**
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
1484Updates the print job state. This API uses a promise to return the result.
1485
1486**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1487
1488**System API**: This is a system API.
1489
1490**System capability**: SystemCapability.Print.PrintFramework
1491
1492**Parameters**
1493| **Name**| **Type**| **Mandatory**| **Description**|
1494| -------- | -------- | -------- | -------- |
1495| jobId | string | Yes| ID of the print job.|
1496| state | [PrintJobState](./js-apis-print.md#printjobstate14) | Yes| State of the print job.|
1497| subState | [PrintJobSubState](./js-apis-print.md#printjobsubstate14) | Yes| Substate of the print job.|
1498
1499**Return value**
1500| **Type**| **Description**|
1501| -------- | -------- |
1502| Promise&lt;void&gt; | Promise used to return the result.|
1503
1504**Error codes**
1505
1506For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1507
1508| ID| Error Message                                   |
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**Example**
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
1534Updates the printer extension information. This API uses an asynchronous callback to return the result.
1535
1536**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1537
1538**System API**: This is a system API.
1539
1540**System capability**: SystemCapability.Print.PrintFramework
1541
1542**Parameters**
1543| **Name**| **Type**| **Mandatory**| **Description**|
1544| -------- | -------- | -------- | -------- |
1545| info | string | Yes| New printer extension information.|
1546| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
1547
1548**Error codes**
1549
1550For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1551
1552| ID| Error Message                                   |
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**Example**
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
1578Updates the printer extension information. This API uses a promise to return the result.
1579
1580**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1581
1582**System API**: This is a system API.
1583
1584**System capability**: SystemCapability.Print.PrintFramework
1585
1586**Parameters**
1587| **Name**| **Type**| **Mandatory**| **Description**|
1588| -------- | -------- | -------- | -------- |
1589| info | string | Yes| New printer extension information.|
1590
1591**Return value**
1592| **Type**| **Description**|
1593| -------- | -------- |
1594| Promise&lt;void&gt; | Promise used to return the result.|
1595
1596**Error codes**
1597
1598For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1599
1600| ID| Error Message                                   |
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**Example**
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> This API is supported since API version 10 and deprecated since API version 11.
1623> You are advised to use [queryPrintJobList](#printqueryprintjoblist11) instead.
1624
1625queryAllPrintJobs(callback: AsyncCallback&lt;void&gt;): void
1626
1627Queries all print jobs. This API uses an asynchronous callback to return the result.
1628
1629**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1630
1631**System API**: This is a system API.
1632
1633**System capability**: SystemCapability.Print.PrintFramework
1634
1635**Parameters**
1636| **Name**| **Type**| **Mandatory**| **Description**|
1637| -------- | -------- | -------- | -------- |
1638| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
1639
1640**Error codes**
1641
1642For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1643
1644| ID| Error Message                                   |
1645| -------- | ------------------------------------------- |
1646| 201 | the application does not have permission to call this function. |
1647| 202 | not system application |
1648
1649**Example**
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> This API is supported since API version 10 and deprecated since API version 11.
1667> You are advised to use [queryPrintJobList](#printqueryprintjoblist11-1) instead.
1668
1669queryAllPrintJobs(): Promise&lt;void&gt;
1670
1671Queries all print jobs. This API uses a promise to return the result.
1672
1673**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1674
1675**System API**: This is a system API.
1676
1677**System capability**: SystemCapability.Print.PrintFramework
1678
1679**Return value**
1680| **Type**| **Description**|
1681| -------- | -------- |
1682| Promise&lt;void&gt; | Promise used to return the result.|
1683
1684**Error codes**
1685
1686For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1687
1688| ID| Error Message                                   |
1689| -------- | ------------------------------------------- |
1690| 201 | the application does not have permission to call this function. |
1691| 202 | not system application |
1692
1693**Example**
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
1710Queries all active print jobs. This API uses a promise to return the result.
1711
1712**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1713
1714**System API**: This is a system API.
1715
1716**System capability**: SystemCapability.Print.PrintFramework
1717
1718**Return value**
1719| **Type**| **Description**|
1720| -------- | -------- |
1721| Promise&lt;[PrintJob](#printjob)[]&gt; | Promise used to return the result.|
1722
1723**Error codes**
1724
1725For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1726
1727| ID| Error Message                                   |
1728| -------- | ------------------------------------------- |
1729| 201 | the application does not have permission to call this function. |
1730| 202 | not system application |
1731
1732**Example**
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
1749Queries all print jobs. This API uses an asynchronous callback to return the result.
1750
1751**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1752
1753**System API**: This is a system API.
1754
1755**System capability**: SystemCapability.Print.PrintFramework
1756
1757**Parameters**
1758| **Name**| **Type**| **Mandatory**| **Description**|
1759| -------- | -------- | -------- | -------- |
1760| callback | AsyncCallback&lt;Array&lt;[PrintJob](#printjob)&gt;&gt; | Yes| Callback used to return the result.|
1761
1762**Error codes**
1763
1764For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1765
1766| ID| Error Message                                   |
1767| -------- | ------------------------------------------- |
1768| 201 | the application does not have permission to call this function. |
1769| 202 | not system application |
1770
1771**Example**
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
1790Queries all print jobs. This API uses a promise to return the result.
1791
1792**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1793
1794**System API**: This is a system API.
1795
1796**System capability**: SystemCapability.Print.PrintFramework
1797
1798**Return value**
1799| **Type**| **Description**|
1800| -------- | -------- |
1801| Promise&lt;Array&lt;[PrintJob](#printjob)&gt;&gt; | Promise used to return the result.|
1802
1803**Error codes**
1804
1805For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1806
1807| ID| Error Message                                   |
1808| -------- | ------------------------------------------- |
1809| 201 | the application does not have permission to call this function. |
1810| 202 | not system application |
1811
1812**Example**
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
1829Queries a print job by ID. This API uses an asynchronous callback to return the result.
1830
1831**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1832
1833**System API**: This is a system API.
1834
1835**System capability**: SystemCapability.Print.PrintFramework
1836
1837**Parameters**
1838| **Name**| **Type**| **Mandatory**| **Description**|
1839| -------- | -------- | -------- | -------- |
1840| jobId | string | Yes| ID of the print job.|
1841| callback | AsyncCallback&lt;[PrintJob](#printjob)&gt; | Yes| Callback used to return the result.|
1842
1843**Error codes**
1844
1845For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1846
1847| ID| Error Message                                   |
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**Example**
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
1873Queries a print job by ID. This API uses a promise to return the result.
1874
1875**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1876
1877**System API**: This is a system API.
1878
1879**System capability**: SystemCapability.Print.PrintFramework
1880
1881**Parameters**
1882| **Name**| **Type**| **Mandatory**| **Description**|
1883| -------- | -------- | -------- | -------- |
1884| jobId | string | Yes| ID of the print job.|
1885
1886**Return value**
1887| **Type**| **Description**|
1888| -------- | -------- |
1889| Promise&lt;[PrintJob](#printjob)&gt; | Promise used to return the result.|
1890
1891**Error codes**
1892
1893For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1894
1895| ID| Error Message                                   |
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**Example**
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
1919Starts to obtain the print file. This API uses an asynchronous callback to return the result.
1920
1921**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1922
1923**System API**: This is a system API.
1924
1925**System capability**: SystemCapability.Print.PrintFramework
1926
1927**Parameters**
1928| **Name**| **Type**| **Mandatory**| **Description**|
1929| -------- | -------- | -------- | -------- |
1930| jobId | string | Yes| ID of the print job.|
1931| printAttributes | [PrintAttributes](./js-apis-print.md#printattributes11) | Yes| Print attributes.|
1932| fd | number | Yes| File descriptor.|
1933| onFileStateChanged | Callback&lt;[PrintFileCreationState](./js-apis-print.md#printfilecreationstate11)&gt; | Yes| Callback for updating the file state.|
1934
1935**Error codes**
1936
1937For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
1938
1939| ID| Error Message                                   |
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**Example**
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
1993Notifies the print service of the spooler shutdown information. This API uses an asynchronous callback to return the result.
1994
1995**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
1996
1997**System API**: This is a system API.
1998
1999**System capability**: SystemCapability.Print.PrintFramework
2000
2001**Parameters**
2002| **Name**| **Type**| **Mandatory**| **Description**|
2003| -------- | -------- | -------- | -------- |
2004| jobId | string | Yes| ID of the print job.|
2005| type | 'spooler_closed_for_cancelled' \| 'spooler_closed_for_started' | Yes| Spooler shutdown information.|
2006| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
2007
2008**Error codes**
2009
2010For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
2011
2012| ID| Error Message                                   |
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**Example**
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
2038Notifies the print service of the spooler shutdown information. This API uses a promise to return the result.
2039
2040**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
2041
2042**System API**: This is a system API.
2043
2044**System capability**: SystemCapability.Print.PrintFramework
2045
2046**Parameters**
2047| **Name**| **Type**| **Mandatory**| **Description**|
2048| -------- | -------- | -------- | -------- |
2049| jobId | string | Yes| ID of the print job.|
2050| type | 'spooler_closed_for_cancelled' \| 'spooler_closed_for_started' | Yes| Spooler shutdown information.|
2051
2052**Return value**
2053| **Type**| **Description**|
2054| -------- | -------- |
2055| Promise&lt;void&gt; | Promise used to return the result.|
2056
2057**Error codes**
2058
2059For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
2060
2061| ID| Error Message                                   |
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**Example**
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
2085Obtains printer information based on the printer ID. This API uses a promise to return the result.
2086
2087**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
2088
2089**System API**: This is a system API.
2090
2091**System capability**: SystemCapability.Print.PrintFramework
2092
2093**Parameters**
2094| **Name**| **Type**| **Mandatory**| **Description**|
2095| -------- | -------- | -------- | -------- |
2096| printerId | string | Yes| Printer ID.|
2097
2098**Return value**
2099| **Type**| **Description**|
2100| -------- | -------- |
2101| Promise&lt;[PrinterInfo](#printerinfo)&gt; | Promise used to return the result.|
2102
2103**Error codes**
2104
2105For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
2106
2107| ID| Error Message                                   |
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**Example**
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
2131Notifies the print service of the print application events. This API uses a promise to return the result.
2132
2133**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
2134
2135**System API**: This is a system API.
2136
2137**System capability**: SystemCapability.Print.PrintFramework
2138
2139**Parameters**
2140| **Name**| **Type**| **Mandatory**| **Description**|
2141| -------- | -------- | -------- | -------- |
2142| event | [ApplicationEvent](./js-apis-print.md#applicationevent14) | Yes| Print application events.|
2143
2144**Return value**
2145| **Type**| **Description**|
2146| -------- | -------- |
2147| Promise&lt;void&gt; | Promise used to return the result.|
2148
2149**Error codes**
2150
2151For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
2152
2153| ID| Error Message                                   |
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**Example**
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
2177Updates the information of a printer in the system. This API uses a promise to return the result.
2178
2179**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
2180
2181**System API**: This is a system API.
2182
2183**System capability**: SystemCapability.Print.PrintFramework
2184
2185**Parameters**
2186| **Name**| **Type**| **Mandatory**| **Description**|
2187| -------- | -------- | -------- | -------- |
2188| printerInformation | [PrinterInformation](./js-apis-print.md#printerinformation14) | Yes| Printer whose information is to be updated.|
2189
2190**Return value**
2191| **Type**| **Description**|
2192| -------- | -------- |
2193| Promise&lt;void&gt; | Promise used to return the result of updating the printer information to the printer discovery list.|
2194
2195**Error codes**
2196
2197For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
2198
2199| ID| Error Message                                   |
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**Example**
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
2249Sets the printer preferences. This API uses a promise to return the result.
2250
2251**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
2252
2253**System API**: This is a system API.
2254
2255**System capability**: SystemCapability.Print.PrintFramework
2256
2257**Parameters**
2258| **Name**| **Type**| **Mandatory**| **Description**|
2259| -------- | -------- | -------- | -------- |
2260| printerId | string | Yes| Printer ID.|
2261| printerPreferences | [PrinterPreferences](./js-apis-print.md#printerpreferences18) | Yes| Printer preferences.|
2262
2263**Return value**
2264| **Type**| **Description**|
2265| -------- | -------- |
2266| Promise&lt;void&gt; | Promise used to return the result of setting printer preferences.|
2267
2268**Error codes**
2269
2270For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
2271
2272| ID| Error Message                                   |
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**Example**
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
2299Discovers USB printers. This API uses a promise to return the result.
2300
2301**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
2302
2303**System API**: This is a system API.
2304
2305**System capability**: SystemCapability.Print.PrintFramework
2306
2307**Return value**
2308| **Type**| **Description**|
2309| -------- | -------- |
2310| Promise&lt;Array&lt;[PrinterInformation](./js-apis-print.md#printerinformation14)&gt;&gt; | Promise used to return the discovered USB printer list.|
2311
2312**Error codes**
2313
2314For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
2315
2316| ID| Error Message                                   |
2317| -------- | ------------------------------------------- |
2318| 201 | the application does not have permission to call this function. |
2319| 202 | not system application |
2320
2321**Example**
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
2338Sets the default printer. This API uses a promise to return the result.
2339
2340**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
2341
2342**System API**: This is a system API.
2343
2344**System capability**: SystemCapability.Print.PrintFramework
2345
2346**Parameters**
2347| **Name**| **Type**| **Mandatory**| **Description**|
2348| -------- | -------- | -------- | -------- |
2349| printerId | string | Yes| Printer ID.|
2350| type | [DefaultPrinterType](./js-apis-print.md#defaultprintertype18) | Yes| Default printer type.|
2351
2352**Return value**
2353| **Type**| **Description**|
2354| -------- | -------- |
2355| Promise&lt;void&gt; | Promise used to return the result of setting the default printer.|
2356
2357**Error codes**
2358
2359For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
2360
2361| ID| Error Message                                   |
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**Example**
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
2386Notifies the print service of the print application events. This API uses a promise to return the result.
2387
2388**Required permissions**: ohos.permission.MANAGE_PRINT_JOB
2389
2390**System API**: This is a system API.
2391
2392**System capability**: SystemCapability.Print.PrintFramework
2393
2394**Parameters**
2395| **Name**| **Type**| **Mandatory**| **Description**|
2396| -------- | -------- | -------- | -------- |
2397| event | [ApplicationEvent](./js-apis-print.md#applicationevent14) | Yes| Print application events.|
2398| jobId | string | Yes| ID of the print job.|
2399
2400**Return value**
2401| **Type**| **Description**|
2402| -------- | -------- |
2403| Promise&lt;void&gt; | Promise used to return the result.|
2404
2405**Error codes**
2406
2407For details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md).
2408
2409| ID| Error Message                                   |
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**Example**
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```
2429