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