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