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