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 listeners 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<void> | 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<void>): 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<void> | 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<void>): 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<void> | 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<void>): 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<void> | 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<void>): 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<void> | 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<void>): 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<void> | 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<void>): 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<void> | 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<void>): 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<void> | 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## PrintDocumentAdapter<sup>11+</sup> 284 285Provides information about the document to print. This API must be implemented by a third-party application. 286 287### onStartLayoutWrite 288 289onStartLayoutWrite(jobId: string, oldAttrs: PrintAttributes, newAttrs: PrintAttributes, fd: number, writeResultCallback: (jobId: string, writeResult: PrintFileCreationState) => void): void 290 291Updates the file to be printed. This API uses **writeResultCallback** as the callback. 292 293**Required permissions**: ohos.permission.PRINT 294 295**System capability**: SystemCapability.Print.PrintFramework 296 297**Parameters** 298| **Name**| **Type**| **Mandatory**| **Description**| 299| -------- | -------- | -------- | -------- | 300| jobId | string | Yes| ID of the print job.| 301| oldAttrs | PrintAttributes | Yes| Old print attributes.| 302| newAttrs | PrintAttributes | Yes| New print attributes.| 303| fd | number | Yes| File descriptor.| 304| writeResultCallback | (jobId: string, writeResult: PrintFileCreationState) | Yes| Callback used to return the result.| 305 306**Example** 307 308```ts 309import print from '@ohos.print'; 310import { BusinessError } from '@ohos.base'; 311 312class MyPrintDocumentAdapter implements print.PrintDocumentAdapter { 313 onStartLayoutWrite(jobId: string, oldAttrs: print.PrintAttributes, newAttrs: print.PrintAttributes, fd: number, 314 writeResultCallback: (jobId: string, writeResult: print.PrintFileCreationState) => void) { 315 writeResultCallback(jobId, print.PrintFileCreationState.PRINT_FILE_CREATED); 316 }; 317 onJobStateChanged(jobId: string, state: print.PrintDocumentAdapterState) { 318 if (state == print.PrintDocumentAdapterState.PREVIEW_DESTROY) { 319 console.log('PREVIEW_DESTROY'); 320 } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_SUCCEED) { 321 console.log('PRINT_TASK_SUCCEED'); 322 } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_FAIL) { 323 console.log('PRINT_TASK_FAIL'); 324 } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_CANCEL) { 325 console.log('PRINT_TASK_CANCEL'); 326 } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_BLOCK) { 327 console.log('PRINT_TASK_BLOCK'); 328 } 329 } 330} 331``` 332 333### onJobStateChanged 334 335onJobStateChanged(jobId: string, state: PrintDocumentAdapterState): void 336 337Registers a listener for print job state changes. 338 339**Required permissions**: ohos.permission.PRINT 340 341**System capability**: SystemCapability.Print.PrintFramework 342 343**Parameters** 344| **Name**| **Type**| **Mandatory**| **Description**| 345| -------- | -------- | -------- | -------- | 346| jobId | string | Yes| ID of the print job.| 347| state | PrintDocumentAdapterState | Yes| New state of the print job.| 348 349**Example** 350 351```ts 352import print from '@ohos.print'; 353import { BusinessError } from '@ohos.base'; 354 355class MyPrintDocumentAdapter implements print.PrintDocumentAdapter { 356 onStartLayoutWrite(jobId: string, oldAttrs: print.PrintAttributes, newAttrs: print.PrintAttributes, fd: number, 357 writeResultCallback: (jobId: string, writeResult: print.PrintFileCreationState) => void) { 358 writeResultCallback(jobId, print.PrintFileCreationState.PRINT_FILE_CREATED); 359 }; 360 onJobStateChanged(jobId: string, state: print.PrintDocumentAdapterState) { 361 if (state == print.PrintDocumentAdapterState.PREVIEW_DESTROY) { 362 console.log('PREVIEW_DESTROY'); 363 } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_SUCCEED) { 364 console.log('PRINT_TASK_SUCCEED'); 365 } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_FAIL) { 366 console.log('PRINT_TASK_FAIL'); 367 } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_CANCEL) { 368 console.log('PRINT_TASK_CANCEL'); 369 } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_BLOCK) { 370 console.log('PRINT_TASK_BLOCK'); 371 } 372 } 373} 374``` 375 376## print 377 378print(files: Array<string>, callback: AsyncCallback<PrintTask>): void 379 380Prints files. This API uses an asynchronous callback to return the result. 381 382**Required permissions**: ohos.permission.PRINT 383 384**System capability**: SystemCapability.Print.PrintFramework 385 386**Parameters** 387| **Name**| **Type**| **Mandatory**| **Description**| 388| -------- | -------- | -------- | -------- | 389| file | Array<string> | Yes| List of files to print. Images in .jpg, .png, .gif, .bmp, or .webp format are supported.| 390| callback | AsyncCallback<PrintTask> | Yes| Callback used to return the result.| 391 392**Example** 393 394```ts 395import print from '@ohos.print'; 396import { BusinessError } from '@ohos.base'; 397 398// Pass in the URIs of the files. 399let file = ['file://data/print/a.png', 'file://data/print/b.png']; 400// Alternatively, pass in the file IDs. 401//let file = ['fd://1', 'fd://2']; 402print.print(file, (err: BusinessError, printTask: print.PrintTask) => { 403 if (err) { 404 console.log('print err ' + JSON.stringify(err)); 405 } else { 406 printTask.on('succeed', () => { 407 console.log('print state is succeed'); 408 }) 409 // ... 410 } 411}) 412``` 413 414## print 415 416print(files: Array<string>): Promise<PrintTask> 417 418Prints files. This API uses a promise to return the result. 419 420**Required permissions**: ohos.permission.PRINT 421 422**System capability**: SystemCapability.Print.PrintFramework 423 424**Parameters** 425| **Name**| **Type**| **Mandatory**| **Description**| 426| -------- | -------- | -------- | -------- | 427| file | Array<string> | Yes| List of files to print. Images in .jpg, .png, .gif, .bmp, or .webp format are supported.| 428 429**Return value** 430| **Type**| **Description**| 431| -------- | -------- | 432| Promise<PrintTask> | Print result.| 433 434**Example** 435 436```ts 437import print from '@ohos.print'; 438import { BusinessError } from '@ohos.base'; 439 440// Pass in the URIs of the files. 441let file = ['file://data/print/a.png', 'file://data/print/b.png']; 442// Alternatively, pass in the file IDs. 443//let file = ['fd://1', 'fd://2']; 444print.print(file).then((printTask: print.PrintTask) => { 445 printTask.on('succeed', () => { 446 console.log('print state is succeed'); 447 }) 448 // ... 449}).catch((error: BusinessError) => { 450 console.log('print err ' + JSON.stringify(error)); 451}) 452``` 453 454## print<sup>11+</sup> 455 456print(files: Array<string>, context: Context, callback: AsyncCallback<PrintTask>): void 457 458Prints files. This API uses an asynchronous callback to return the result. 459 460**Required permissions**: ohos.permission.PRINT 461 462**System capability**: SystemCapability.Print.PrintFramework 463 464**Parameters** 465| **Name**| **Type**| **Mandatory**| **Description**| 466| -------- | -------- | -------- | -------- | 467| file | Array<string> | Yes| List of files to print. Images in .jpg, .png, .gif, .bmp, or .webp format are supported.| 468| context | Context | Yes| UIAbility context used to start printing.| 469| callback | AsyncCallback<PrintTask> | Yes| Callback used to return the result.| 470 471**Example** 472 473```ts 474import print from '@ohos.print'; 475import { BusinessError } from '@ohos.base'; 476 477// Pass in the URIs of the files. 478let file = ['file://data/print/a.png', 'file://data/print/b.png']; 479// Alternatively, pass in the file IDs. 480//let file = ['fd://1', 'fd://2']; 481let context = getContext(this); 482print.print(file, context, (err: BusinessError, printTask: print.PrintTask) => { 483 if (err) { 484 console.log('print err ' + JSON.stringify(err)); 485 } else { 486 printTask.on('succeed', () => { 487 console.log('print state is succeed'); 488 }) 489 // ... 490 } 491}) 492``` 493 494## print<sup>11+</sup> 495 496print(files: Array<string>, context: Context): Promise<PrintTask> 497 498Prints files. This API uses a promise to return the result. 499 500**Required permissions**: ohos.permission.PRINT 501 502**System capability**: SystemCapability.Print.PrintFramework 503 504**Parameters** 505| **Name**| **Type**| **Mandatory**| **Description**| 506| -------- | -------- | -------- | -------- | 507| file | Array<string> | Yes| List of files to print. Images in .jpg, .png, .gif, .bmp, or .webp format are supported.| 508| context | Context | Yes| UIAbility context used to start printing.| 509 510**Return value** 511| **Type**| **Description**| 512| -------- | -------- | 513| Promise<PrintTask> | Print result.| 514 515**Example** 516 517```ts 518import print from '@ohos.print'; 519import { BusinessError } from '@ohos.base'; 520 521// Pass in the URIs of the files. 522let file = ['file://data/print/a.png', 'file://data/print/b.png']; 523// Alternatively, pass in the file IDs. 524//let file = ['fd://1', 'fd://2']; 525let context = getContext(this); 526print.print(file, context).then((printTask: print.PrintTask) => { 527 printTask.on('succeed', () => { 528 console.log('print state is succeed'); 529 }) 530 // ... 531}).catch((error: BusinessError) => { 532 console.log('print err ' + JSON.stringify(error)); 533}) 534``` 535 536## print<sup>11+</sup> 537 538print(jobName: string, printAdapter: PrintDocumentAdapter, printAttributes: PrintAttributes, context: Context): Promise<PrintTask> 539 540Prints a file. This API uses a promise to return the result. 541 542**Required permissions**: ohos.permission.PRINT 543 544**System capability**: SystemCapability.Print.PrintFramework 545 546**Parameters** 547| **Name**| **Type**| **Mandatory**| **Description**| 548| -------- | -------- | -------- | -------- | 549| jobName | string | Yes| Name of the file to print.| 550| printAdapter | PrintDocumentAdapter | Yes| Feature implemented by a third-party application.| 551| printAttributes | PrintAttributes | Yes| Print attributes.| 552| context | Context | Yes| UIAbility context used to start printing.| 553 554**Return value** 555| **Type**| **Description**| 556| -------- | -------- | 557| Promise<PrintTask> | Print result.| 558 559**Example** 560 561```ts 562import print from '@ohos.print'; 563import { BusinessError } from '@ohos.base'; 564 565let jobName : string = "jobName"; 566let printAdapter : print.PrintDocumentAdapter | null = null; 567let printAttributes : print.PrintAttributes = { 568 copyNumber: 1, 569 pageRange: { 570 startPage: 0, 571 endPage: 5, 572 pages: [] 573 }, 574 pageSize: print.PrintPageType.PAGE_ISO_A3, 575 directionMode: print.PrintDirectionMode.DIRECTION_MODE_AUTO, 576 colorMode: print.PrintColorMode.COLOR_MODE_MONOCHROME, 577 duplexMode: print.PrintDuplexMode.DUPLEX_MODE_NONE 578} 579let context = getContext(); 580 581print.print(jobName, printAdapter, printAttributes, context).then((printTask: print.PrintTask) => { 582 printTask.on('succeed', () => { 583 console.log('print state is succeed'); 584 }) 585 // ... 586}).catch((error: BusinessError) => { 587 console.log('print err ' + JSON.stringify(error)); 588}) 589``` 590 591## PrintAttributes<sup>11+</sup> 592 593Defines the print attributes. 594 595**System capability**: SystemCapability.Print.PrintFramework 596 597**Attributes** 598| **Name**| **Type**| **Mandatory**| **Description**| 599| -------- | -------- | -------- | -------- | 600| copyNumber | number | No| Copy of the file list.| 601| pageRange | PrintPageRange | No| Range of pages to print.| 602| pageSize | PrintPageSize \| PrintPageType | No| Page size of the files to print.| 603| directionMode | PrintDirectionMode | No| Print direction mode.| 604| colorMode | PrintColorMode | No| Color mode of the files to print.| 605| duplexMode | PrintDuplexMode | No| Duplex mode of the files to print.| 606 607## PrintPageRange<sup>11+</sup> 608 609Defines the print range. 610 611**System capability**: SystemCapability.Print.PrintFramework 612 613**Attributes** 614| **Name**| **Type**| **Mandatory**| **Description**| 615| -------- | -------- | -------- | -------- | 616| startPage | number | No| Start page.| 617| endPage | number | No| End page.| 618| pages | Array<number> | No| Discrete pages.| 619 620## PrintMargin 621 622Defines the page margins for printing. 623 624**System API**: This is a system API. 625 626**System capability**: SystemCapability.Print.PrintFramework 627 628**Attributes** 629| **Name**| **Type**| **Mandatory**| **Description**| 630| -------- | -------- | -------- | -------- | 631| top | number | No| Top margin of the page.| 632| bottom | number | No| Bottom margin of the page.| 633| left | number | No| Left margin of the page.| 634| right | number | No| Right margin of the page.| 635 636## PrinterRange 637 638Defines the print range. 639 640**System API**: This is a system API. 641 642**System capability**: SystemCapability.Print.PrintFramework 643 644**Attributes** 645| **Name**| **Type**| **Mandatory**| **Description**| 646| -------- | -------- | -------- | -------- | 647| startPage | number | No| Start page.| 648| endPage | number | No| End page.| 649| pages | Array<number> | No| Discrete pages.| 650 651## PreviewAttribute 652 653Defines the print preview attributes. 654 655**System API**: This is a system API. 656 657**System capability**: SystemCapability.Print.PrintFramework 658 659**Attributes** 660| **Name**| **Type**| **Mandatory**| **Description**| 661| -------- | -------- | -------- | -------- | 662| previewRange | PrinterRange | Yes| Preview page range.| 663| result | number | No| Print preview result.| 664 665## PrintResolution 666 667Defines the resolution for printing. 668 669**System API**: This is a system API. 670 671**System capability**: SystemCapability.Print.PrintFramework 672 673**Attributes** 674| **Name**| **Type**| **Mandatory**| **Description**| 675| -------- | -------- | -------- | -------- | 676| id | string | Yes| Resolution ID.| 677| horizontalDpi | number | Yes| Horizontal DPI.| 678| verticalDpi | number | Yes| Vertical DPI.| 679 680## PrintPageSize<sup>11+</sup> 681 682Defines the size of the printed page. 683 684**System capability**: SystemCapability.Print.PrintFramework 685 686**Attributes** 687| **Name**| **Type**| **Mandatory**| **Description**| 688| -------- | -------- | -------- | -------- | 689| id | string | Yes| Page size ID.| 690| name | string | Yes| Page size name.| 691| width | number | Yes| Page width, in millimeters.| 692| height | number | Yes| Page height, in millimeters.| 693 694## PrinterCapability 695 696Defines the printer capabilities. 697 698**System API**: This is a system API. 699 700**System capability**: SystemCapability.Print.PrintFramework 701 702**Attributes** 703| **Name**| **Type**| **Mandatory**| **Description**| 704| -------- | -------- | -------- | -------- | 705| colorMode | number | Yes| Color mode.| 706| duplexMode | number | Yes| Single-sided or double-sided printing mode.| 707| pageSize | Array<PrintPageSize> | Yes| List of page sizes supported by the printer.| 708| resolution | Array<PrintResolution> | No| List of resolutions supported by the printer.| 709| minMargin | PrintMargin | No| Minimum margin of the printer.| 710| options<sup>11+</sup> | Object | No| Printer options. The value is a JSON object string.| 711 712## PrinterInfo 713 714Provides the printer information. 715 716**System API**: This is a system API. 717 718**System capability**: SystemCapability.Print.PrintFramework 719 720**Attributes** 721| **Name**| **Type**| **Mandatory**| **Description**| 722| -------- | -------- | -------- | -------- | 723| printerId | string | Yes| Printer ID.| 724| printerName | string | Yes| Printer name.| 725| printerState | PrinterState | Yes| Printer state.| 726| printerIcon | number | No| Resource ID of the printer icon.| 727| description | string | No| Printer description.| 728| capability | PrinterCapability | No| Printer capability.| 729| options | Object | No| Printer options. The value is a JSON object string.| 730 731## PrintJob 732 733Defines a print job. 734 735**System API**: This is a system API. 736 737**System capability**: SystemCapability.Print.PrintFramework 738 739**Attributes** 740| **Name**| **Type**| **Mandatory**| **Description**| 741| -------- | -------- | -------- | -------- | 742| fdList | Array<number> | Yes| FD list of files to print.| 743| jobId | string | Yes| ID of the print job.| 744| printerId | string | Yes| ID of the printer used for printing.| 745| jobState | PrintJobState | Yes| State of the print job.| 746| jobSubstate<sup>11+</sup> | PrintJobSubState | Yes| Substate of the print job.| 747| copyNumber | number | Yes| Copy of the file list.| 748| pageRange | PrinterRange | Yes| Print range.| 749| isSequential | boolean | Yes| Whether to enable sequential printing.| 750| pageSize | PrintPageSize | Yes| Selected page size.| 751| isLandscape | boolean | Yes| Whether to print in landscape mode.| 752| colorMode | number | Yes| Color mode.| 753| duplexMode | number | Yes| Single-sided or double-sided printing mode.| 754| margin | PrintMargin | No| Current page margin.| 755| preview | PreviewAttribute | No| Preview settings.| 756| options | Object | No| Printer options. The value is a JSON object string.| 757 758## PrintDirectionMode<sup>11+</sup> 759 760Enumerates the print direction modes. 761 762**System capability**: SystemCapability.Print.PrintFramework 763 764| **Name**| **Value**| **Description**| 765| -------- | -------- | -------- | 766| DIRECTION_MODE_AUTO | 0 | Automatic.| 767| DIRECTION_MODE_PORTRAIT | 1 | Portrait mode.| 768| DIRECTION_MODE_LANDSCAPE | 2 | Landscape mode.| 769 770## PrintColorMode<sup>11+</sup> 771 772Enumerates the color modes. 773 774**System capability**: SystemCapability.Print.PrintFramework 775 776| **Name**| **Value**| **Description**| 777| -------- | -------- | -------- | 778| COLOR_MODE_MONOCHROME | 0 | Black and white.| 779| COLOR_MODE_COLOR | 1 | Color.| 780 781## PrintDuplexMode<sup>11+</sup> 782 783Enumerates the duplex modes. 784 785**System capability**: SystemCapability.Print.PrintFramework 786 787| **Name**| **Value**| **Description**| 788| -------- | -------- | -------- | 789| DUPLEX_MODE_NONE | 0 | Simplex (single-sided).| 790| DUPLEX_MODE_LONG_EDGE | 1 | Duplex (double-sided) with flipping on long edge.| 791| DUPLEX_MODE_SHORT_EDGE | 2 | Duplex (double-sided) with flipping on short edge.| 792 793## PrintPageType<sup>11+</sup> 794 795Enumerates the print page types. 796 797**System capability**: SystemCapability.Print.PrintFramework 798 799| **Name**| **Value**| **Description**| 800| -------- | -------- | -------- | 801| PAGE_ISO_A3 | 0 | A3.| 802| PAGE_ISO_A4 | 1 | A4.| 803| PAGE_ISO_A5 | 2 | A5.| 804| PAGE_JIS_B5 | 3 | B5.| 805| PAGE_ISO_C5 | 4 | C5.| 806| PAGE_ISO_DL | 5 | DL.| 807| PAGE_LETTER | 6 | Letter.| 808| PAGE_LEGAL | 7 | Legal.| 809| PAGE_PHOTO_4X6 | 8 | 4 x 6 photo paper.| 810| PAGE_PHOTO_5X7 | 9 | 5 x 7 photo paper.| 811| PAGE_INT_DL_ENVELOPE | 10 | International envelope DL.| 812| PAGE_B_TABLOID | 11 | B Tabloid.| 813 814## PrintDocumentAdapterState<sup>11+</sup> 815 816Enumerates the print job states. 817 818**System capability**: SystemCapability.Print.PrintFramework 819 820| **Name**| **Value**| **Description**| 821| -------- | -------- | -------- | 822| PREVIEW_DESTROY | 0 | The preview fails.| 823| PRINT_TASK_SUCCEED | 1 | The print job is successful.| 824| PRINT_TASK_FAIL | 2 | The print job failed.| 825| PRINT_TASK_CANCEL | 3 | The print job is canceled.| 826| PRINT_TASK_BLOCK | 4 | The print job is blocked.| 827 828## PrintFileCreationState<sup>11+</sup> 829 830Enumerates the print file creation status. 831 832**System capability**: SystemCapability.Print.PrintFramework 833 834| **Name**| **Value**| **Description**| 835| -------- | -------- | -------- | 836| PRINT_FILE_CREATED | 0 | The print file is created successfully.| 837| PRINT_FILE_CREATION_FAILED | 1 | The print file fails to be created.| 838| PRINT_FILE_CREATED_UNRENDERED | 2 | The print file is successfully created but not rendered.| 839 840## PrinterState 841 842Enumerates the printer states. 843 844**System API**: This is a system API. 845 846**System capability**: SystemCapability.Print.PrintFramework 847 848| **Name**| **Value**| **Description**| 849| -------- | -------- | -------- | 850| PRINTER_ADDED | 0 | A new printer is added.| 851| PRINTER_REMOVED | 1 | The printer is removed.| 852| PRINTER_CAPABILITY_UPDATED | 2 | The printer is updated.| 853| PRINTER_CONNECTED | 3 | The printer is connected.| 854| PRINTER_DISCONNECTED | 4 | The printer is disconnected.| 855| PRINTER_RUNNING | 5 | The printer is running.| 856 857## PrintJobState 858 859Enumerates the print job states. 860 861**System API**: This is a system API. 862 863**System capability**: SystemCapability.Print.PrintFramework 864 865| **Name**| **Value**| **Description**| 866| -------- | -------- | -------- | 867| PRINT_JOB_PREPARE | 0 | The printer is prepared for the print job.| 868| PRINT_JOB_QUEUED | 1 | The print job is on the print queue of the printer.| 869| PRINT_JOB_RUNNING | 2 | The print job is being executed.| 870| PRINT_JOB_BLOCKED | 3 | The print job is blocked.| 871| PRINT_JOB_COMPLETED | 4 | The print job is complete.| 872 873## PrintJobSubState 874 875Enumerates the print job substates. 876 877**System API**: This is a system API. 878 879**System capability**: SystemCapability.Print.PrintFramework 880 881| **Name**| **Value**| **Description**| 882| -------- | -------- | -------- | 883| PRINT_JOB_COMPLETED_SUCCESS | 0 | The print job is successful.| 884| PRINT_JOB_COMPLETED_FAILED | 1 | The print job failed.| 885| PRINT_JOB_COMPLETED_CANCELLED | 2 | The print job is canceled.| 886| PRINT_JOB_COMPLETED_FILE_CORRUPTED | 3 | The print job is corrupted.| 887| PRINT_JOB_BLOCK_OFFLINE | 4 | The printer is offline.| 888| PRINT_JOB_BLOCK_BUSY | 5 | The printer is occupied by another process.| 889| PRINT_JOB_BLOCK_CANCELLED | 6 | The print job is canceled.| 890| PRINT_JOB_BLOCK_OUT_OF_PAPER | 7 | The printer is out of paper.| 891| PRINT_JOB_BLOCK_OUT_OF_INK | 8 | The printer is out of ink.| 892| PRINT_JOB_BLOCK_OUT_OF_TONER | 9 | The printer is out of toner.| 893| PRINT_JOB_BLOCK_JAMMED | 10 | The printer is in a paper jam.| 894| PRINT_JOB_BLOCK_DOOR_OPEN | 11 | The printer door is open.| 895| PRINT_JOB_BLOCK_SERVICE_REQUEST | 12 | Print service request.| 896| PRINT_JOB_BLOCK_LOW_ON_INK | 13 | The printer is low on ink.| 897| PRINT_JOB_BLOCK_LOW_ON_TONER | 14 | The printer is low on toner.| 898| PRINT_JOB_BLOCK_REALLY_LOW_ON_INK | 15 | The printer is extremely low on ink.| 899| PRINT_JOB_BLOCK_BAD_CERTIFICATE | 16 | The print certificate is incorrect.| 900| PRINT_JOB_BLOCK_ACCOUNT_ERROR<sup>11+</sup> | 18 | There is an error with the printer account.| 901| PRINT_JOB_BLOCK_PRINT_PERMISSION_ERROR<sup>11+</sup> | 19 | There is an error with the printer permission.| 902| PRINT_JOB_BLOCK_PRINT_COLOR_PERMISSION_ERROR<sup>11+</sup> | 20 | There is an error with the color print permission.| 903| PRINT_JOB_BLOCK_NETWORK_ERROR<sup>11+</sup> | 21 | The printer is not connected to the network.| 904| PRINT_JOB_BLOCK_SERVER_CONNECTION_ERROR<sup>11+</sup> | 22 | The printer could not be connected to the server.| 905| PRINT_JOB_BLOCK_LARGE_FILE_ERROR<sup>11+</sup> | 23 | An error occurs when a large file is printed.| 906| PRINT_JOB_BLOCK_FILE_PARSING_ERROR<sup>11+</sup> | 24 | There is an error with file parsing.| 907| PRINT_JOB_BLOCK_SLOW_FILE_CONVERSION<sup>11+</sup> | 25 | The file conversion is slow.| 908| PRINT_JOB_RUNNING_UPLOADING_FILES<sup>11+</sup> | 26 | The file is being uploaded.| 909| PRINT_JOB_RUNNING_CONVERTING_FILES<sup>11+</sup> | 27 | The file is being converted.| 910| PRINT_JOB_BLOCK_UNKNOWN | 99 | An unknown print error occurs.| 911 912## PrintErrorCode 913 914Enumerates the print error codes. 915 916**System API**: This is a system API. 917 918**System capability**: SystemCapability.Print.PrintFramework 919 920| **Name**| **Value**| **Description**| 921| -------- | -------- | -------- | 922| E_PRINT_NONE | 0 | No error.| 923| E_PRINT_NO_PERMISSION | 201 | No permission.| 924| E_PRINT_INVALID_PARAMETER | 401 | Invalid parameter.| 925| E_PRINT_GENERIC_FAILURE | 13100001 | Printing failure.| 926| E_PRINT_RPC_FAILURE | 13100002 | RPC failure.| 927| E_PRINT_SERVER_FAILURE | 13100003 | Print service failure.| 928| E_PRINT_INVALID_EXTENSION | 13100004 | Invalid printer extension.| 929| E_PRINT_INVALID_PRINTER | 13100005 | Invalid printer.| 930| E_PRINT_INVALID_PRINT_JOB | 13100006 | Invalid print job.| 931| E_PRINT_FILE_IO | 13100007 | Incorrect file input/output.| 932 933## PrinterExtensionInfo 934 935Provides the printer extension information. 936 937**System API**: This is a system API. 938 939**System capability**: SystemCapability.Print.PrintFramework 940 941**Attributes** 942| **Name**| **Type**| **Mandatory**| **Description**| 943| -------- | -------- | -------- | -------- | 944| extensionId | string | Yes| ID of the printer extension.| 945| vendorId | string | Yes| Vendor ID of the printer extension.| 946| vendorName | string | Yes| Vendor name of the printer extension.| 947| vendorIcon | number | Yes| Vendor icon of the printer extension.| 948| version | string | Yes| Version of the printer extension.| 949 950## queryAllPrinterExtensionInfos 951 952queryAllPrinterExtensionInfos(callback: AsyncCallback<Array<PrinterExtensionInfo>>): void 953 954Obtains the information of all installed printer extensions. This API uses an asynchronous callback to return the result. 955 956**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 957 958**System API**: This is a system API. 959 960**System capability**: SystemCapability.Print.PrintFramework 961 962**Parameters** 963| **Name**| **Type**| **Mandatory**| **Description**| 964| -------- | -------- | -------- | -------- | 965| callback | AsyncCallback<Array<PrinterExtensionInfo>> | Yes| Callback used to return the result.| 966 967**Example** 968 969```ts 970import print from '@ohos.print'; 971import { BusinessError } from '@ohos.base'; 972 973print.queryAllPrinterExtensionInfos((err: BusinessError, extensionInfos: print.PrinterExtensionInfo[]) => { 974 if (err) { 975 console.log('queryAllPrinterExtensionInfos err ' + JSON.stringify(err)); 976 } else { 977 console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos)); 978 } 979}) 980``` 981 982## queryAllPrinterExtensionInfos 983 984queryAllPrinterExtensionInfos(): Promise<Array<PrinterExtensionInfo>> 985 986Obtains the information of all installed printer extensions. This API uses a promise to return the result. 987 988**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 989 990**System API**: This is a system API. 991 992**System capability**: SystemCapability.Print.PrintFramework 993 994**Return value** 995| **Type**| **Description**| 996| -------- | -------- | 997| Promise<Array<PrinterExtensionInfo>> | Promise used to return the result.used to return the result.| 998 999**Example** 1000 1001```ts 1002import print from '@ohos.print'; 1003import { BusinessError } from '@ohos.base'; 1004 1005print.queryAllPrinterExtensionInfos().then((extensionInfos: print.PrinterExtensionInfo[]) => { 1006 console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos)); 1007 // ... 1008}).catch((error: BusinessError) => { 1009 console.log('failed to get AllPrinterExtension bacause ' + JSON.stringify(error)); 1010}) 1011``` 1012 1013## startDiscoverPrinter 1014 1015startDiscoverPrinter(extensionList: Array<string>, callback: AsyncCallback<void>): void 1016 1017Starts discovering printers with the specified printer extensions. This API uses an asynchronous callback to return the result. 1018 1019**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1020 1021**System API**: This is a system API. 1022 1023**System capability**: SystemCapability.Print.PrintFramework 1024 1025**Parameters** 1026| **Name**| **Type**| **Mandatory**| **Description**| 1027| -------- | -------- | -------- | -------- | 1028| extensionList | Array<string> | Yes| List of printer extensions to load.| 1029| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1030 1031**Example** 1032 1033```ts 1034import print from '@ohos.print'; 1035import { BusinessError } from '@ohos.base'; 1036 1037let extensionList: string[] = []; 1038// If there is no information in extensionList, all extensions are used for printer discovery. 1039print.startDiscoverPrinter(extensionList, (err: BusinessError, data : void) => { 1040 if (err) { 1041 console.log('failed to start Discover Printer because : ' + JSON.stringify(err)); 1042 } else { 1043 console.log('start Discover Printer success data : ' + JSON.stringify(data)); 1044 } 1045}) 1046``` 1047 1048## startDiscoverPrinter 1049 1050startDiscoverPrinter(extensionList: Array<string>): Promise<void> 1051 1052Starts discovering printers with the specified printer extensions. This API uses a promise to return the result. 1053 1054**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1055 1056**System API**: This is a system API. 1057 1058**System capability**: SystemCapability.Print.PrintFramework 1059 1060**Return value** 1061| **Type**| **Description**| 1062| -------- | -------- | 1063| Promise<void> | Promise used to return the result.| 1064 1065**Example** 1066 1067```ts 1068import print from '@ohos.print'; 1069import { BusinessError } from '@ohos.base'; 1070 1071let extensionList: string[] = []; 1072// If there is no information in extensionList, all extensions are used for printer discovery. 1073print.startDiscoverPrinter(extensionList).then((data : void) => { 1074 console.log('start Discovery success data : ' + JSON.stringify(data)); 1075}).catch((error: BusinessError) => { 1076 console.log('failed to start Discovery because : ' + JSON.stringify(error)); 1077}) 1078``` 1079 1080## stopDiscoverPrinter 1081 1082stopDiscoverPrinter(callback: AsyncCallback<void>): void 1083 1084Stops discovering printers with the specified printer extensions. This API uses an asynchronous callback to return the result. 1085 1086**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1087 1088**System API**: This is a system API. 1089 1090**System capability**: SystemCapability.Print.PrintFramework 1091 1092**Parameters** 1093| **Name**| **Type**| **Mandatory**| **Description**| 1094| -------- | -------- | -------- | -------- | 1095| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1096 1097**Example** 1098 1099```ts 1100import print from '@ohos.print'; 1101import { BusinessError } from '@ohos.base'; 1102 1103print.stopDiscoverPrinter((err: BusinessError, data : void) => { 1104 if (err) { 1105 console.log('failed to stop Discover Printer because : ' + JSON.stringify(err)); 1106 } else { 1107 console.log('stop Discover Printer success data : ' + JSON.stringify(data)); 1108 } 1109}) 1110``` 1111 1112## stopDiscoverPrinter 1113 1114stopDiscoverPrinter(): Promise<void> 1115 1116Stops discovering printers with the specified printer extensions. This API uses a promise to return the result. 1117 1118**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1119 1120**System API**: This is a system API. 1121 1122**System capability**: SystemCapability.Print.PrintFramework 1123 1124**Return value** 1125| **Type**| **Description**| 1126| -------- | -------- | 1127| Promise<void> | Promise used to return the result.| 1128 1129**Example** 1130 1131```ts 1132import print from '@ohos.print'; 1133import { BusinessError } from '@ohos.base'; 1134 1135print.stopDiscoverPrinter().then((data : void) => { 1136 console.log('stop Discovery success data : ' + JSON.stringify(data)); 1137}).catch((error: BusinessError) => { 1138 console.log('failed to stop Discovery because : ' + JSON.stringify(error)); 1139}) 1140``` 1141 1142## connectPrinter 1143 1144connectPrinter(printerId: string, callback: AsyncCallback<void>): void 1145 1146Connects to the specified printer. This API uses an asynchronous callback to return the result. 1147 1148**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1149 1150**System API**: This is a system API. 1151 1152**System capability**: SystemCapability.Print.PrintFramework 1153 1154**Parameters** 1155| **Name**| **Type**| **Mandatory**| **Description**| 1156| -------- | -------- | -------- | -------- | 1157| printerId | string | Yes| Printer ID.| 1158| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1159 1160**Example** 1161 1162```ts 1163import print from '@ohos.print'; 1164import { BusinessError } from '@ohos.base'; 1165 1166let printerId: string = 'printerId_32'; 1167print.connectPrinter(printerId, (err: BusinessError, data : void) => { 1168 if (err) { 1169 console.log('failed to connect Printer because : ' + JSON.stringify(err)); 1170 } else { 1171 console.log('start connect Printer success data : ' + JSON.stringify(data)); 1172 } 1173}) 1174``` 1175 1176## connectPrinter 1177 1178connectPrinter(printerId: string): Promise<void> 1179 1180Connects to the specified printer. This API uses a promise to return the result. 1181 1182**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1183 1184**System API**: This is a system API. 1185 1186**System capability**: SystemCapability.Print.PrintFramework 1187 1188**Parameters** 1189| **Name**| **Type**| **Mandatory**| **Description**| 1190| -------- | -------- | -------- | -------- | 1191| printerId | string | Yes| Printer ID.| 1192 1193**Return value** 1194| **Type**| **Description**| 1195| -------- | -------- | 1196| Promise<void> | Promise used to return the result.| 1197 1198**Example** 1199 1200```ts 1201import print from '@ohos.print'; 1202import { BusinessError } from '@ohos.base'; 1203 1204let printerId: string = 'printerId_32'; 1205print.connectPrinter(printerId).then((data : void) => { 1206 console.log('start connect Printer success data : ' + JSON.stringify(data)); 1207}).catch((error: BusinessError) => { 1208 console.log('failed to connect Printer because : ' + JSON.stringify(error)); 1209}) 1210``` 1211 1212## disconnectPrinter 1213 1214disconnectPrinter(printerId: string, callback: AsyncCallback<void>): void 1215 1216Disconnects from the specified printer. This API uses an asynchronous callback to return the result. 1217 1218**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1219 1220**System API**: This is a system API. 1221 1222**System capability**: SystemCapability.Print.PrintFramework 1223 1224**Parameters** 1225| **Name**| **Type**| **Mandatory**| **Description**| 1226| -------- | -------- | -------- | -------- | 1227| printerId | string | Yes| Printer ID.| 1228| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1229 1230**Example** 1231 1232```ts 1233import print from '@ohos.print'; 1234import { BusinessError } from '@ohos.base'; 1235 1236let printerId: string = 'printerId_32'; 1237print.disconnectPrinter(printerId, (err: BusinessError, data : void) => { 1238 if (err) { 1239 console.log('failed to disconnect Printer because : ' + JSON.stringify(err)); 1240 } else { 1241 console.log('start disconnect Printer success data : ' + JSON.stringify(data)); 1242 } 1243}) 1244``` 1245 1246## disconnectPrinter 1247 1248disconnectPrinter(printerId: string): Promise<void> 1249 1250Disconnects from the specified printer. This API uses a promise to return the result. 1251 1252**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1253 1254**System API**: This is a system API. 1255 1256**System capability**: SystemCapability.Print.PrintFramework 1257 1258**Parameters** 1259| **Name**| **Type**| **Mandatory**| **Description**| 1260| -------- | -------- | -------- | -------- | 1261| printerId | string | Yes| Printer ID.| 1262 1263**Return value** 1264| **Type**| **Description**| 1265| -------- | -------- | 1266| Promise<void> | Promise used to return the result.| 1267 1268**Example** 1269 1270```ts 1271import print from '@ohos.print'; 1272import { BusinessError } from '@ohos.base'; 1273 1274let printerId: string = 'printerId_32'; 1275print.disconnectPrinter(printerId).then((data : void) => { 1276 console.log('start disconnect Printer success data : ' + JSON.stringify(data)); 1277}).catch((error: BusinessError) => { 1278 console.log('failed to disconnect Printer because : ' + JSON.stringify(error)); 1279}) 1280``` 1281 1282## queryPrinterCapability 1283 1284queryPrinterCapability(printerId: string, callback: AsyncCallback<void>): void 1285 1286Queries the printer capability. This API uses an asynchronous callback to return the result. 1287 1288**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1289 1290**System API**: This is a system API. 1291 1292**System capability**: SystemCapability.Print.PrintFramework 1293 1294**Parameters** 1295| **Name**| **Type**| **Mandatory**| **Description**| 1296| -------- | -------- | -------- | -------- | 1297| printerId | string | Yes| Printer ID.| 1298| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1299 1300**Example** 1301 1302```ts 1303import print from '@ohos.print'; 1304import { BusinessError } from '@ohos.base'; 1305 1306let printerId: string = 'printerId_32'; 1307print.queryPrinterCapability(printerId, (err: BusinessError, data : void) => { 1308 if (err) { 1309 console.log('failed to query Printer Capability because : ' + JSON.stringify(err)); 1310 } else { 1311 console.log('start query Printer Capability success data : ' + JSON.stringify(data)); 1312 } 1313}) 1314``` 1315 1316## queryPrinterCapability 1317 1318queryPrinterCapability(printerId: string): Promise<void> 1319 1320Queries the printer capability. This API uses a promise to return the result. 1321 1322**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1323 1324**System API**: This is a system API. 1325 1326**System capability**: SystemCapability.Print.PrintFramework 1327 1328**Parameters** 1329| **Name**| **Type**| **Mandatory**| **Description**| 1330| -------- | -------- | -------- | -------- | 1331| printerId | string | Yes| Printer ID.| 1332 1333**Return value** 1334| **Type**| **Description**| 1335| -------- | -------- | 1336| Promise<void> | Promise used to return the result.| 1337 1338**Example** 1339 1340```ts 1341import print from '@ohos.print'; 1342import { BusinessError } from '@ohos.base'; 1343 1344let printerId: string = 'printerId_32'; 1345print.queryPrinterCapability(printerId).then((data : void) => { 1346 console.log('start query Printer success data : ' + JSON.stringify(data)); 1347}).catch((error: BusinessError) => { 1348 console.log('failed to query Printer Capability because : ' + JSON.stringify(error)); 1349}) 1350``` 1351 1352## startPrintJob 1353 1354startPrintJob(jobInfo: PrintJob, callback: AsyncCallback<void>): void 1355 1356Starts the specified print job. This API uses an asynchronous callback to return the result. 1357 1358**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1359 1360**System API**: This is a system API. 1361 1362**System capability**: SystemCapability.Print.PrintFramework 1363 1364**Parameters** 1365| **Name**| **Type**| **Mandatory**| **Description**| 1366| -------- | -------- | -------- | -------- | 1367| jobInfo | PrintJob | Yes| Information about the print job.| 1368| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1369 1370**Example** 1371 1372```ts 1373import print from '@ohos.print'; 1374import { BusinessError } from '@ohos.base'; 1375 1376let jobInfo : print.PrintJob = { 1377 fdList : [0,1], 1378 jobId : 'jobId_12', 1379 printerId : 'printerId_32', 1380 jobState : 3, 1381 jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, 1382 copyNumber : 1, 1383 pageRange : {}, 1384 isSequential : false, 1385 pageSize : {id : '', name : '', width : 10, height : 20}, 1386 isLandscape : false, 1387 colorMode : 6, 1388 duplexMode : 6, 1389 margin : undefined, 1390 preview : undefined, 1391 options : undefined 1392}; 1393print.startPrintJob(jobInfo, (err: BusinessError, data : void) => { 1394 if (err) { 1395 console.log('failed to start Print Job because : ' + JSON.stringify(err)); 1396 } else { 1397 console.log('start Print Job success data : ' + JSON.stringify(data)); 1398 } 1399}) 1400``` 1401 1402## startPrintJob 1403 1404startPrintJob(jobInfo: PrintJob): Promise<void> 1405 1406Starts the specified print job. This API uses a promise to return the result. 1407 1408**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1409 1410**System API**: This is a system API. 1411 1412**System capability**: SystemCapability.Print.PrintFramework 1413 1414**Parameters** 1415| **Name**| **Type**| **Mandatory**| **Description**| 1416| -------- | -------- | -------- | -------- | 1417| jobInfo | PrintJob | Yes| Information about the print job.| 1418 1419**Return value** 1420| **Type**| **Description**| 1421| -------- | -------- | 1422| Promise<void> | Promise used to return the result.| 1423 1424**Example** 1425 1426```ts 1427import print from '@ohos.print'; 1428import { BusinessError } from '@ohos.base'; 1429 1430let jobInfo : print.PrintJob = { 1431 fdList : [0,1], 1432 jobId : 'jobId_12', 1433 printerId : 'printerId_32', 1434 jobState : 3, 1435 jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, 1436 copyNumber : 1, 1437 pageRange : {}, 1438 isSequential : false, 1439 pageSize : {id : '', name : '', width : 10, height : 20}, 1440 isLandscape : false, 1441 colorMode : 6, 1442 duplexMode : 6, 1443 margin : undefined, 1444 preview : undefined, 1445 options : undefined 1446}; 1447print.startPrintJob(jobInfo).then((data : void) => { 1448 console.log('start Print success data : ' + JSON.stringify(data)); 1449}).catch((error: BusinessError) => { 1450 console.log('failed to start Print because : ' + JSON.stringify(error)); 1451}) 1452``` 1453 1454## cancelPrintJob 1455 1456cancelPrintJob(jobId: string, callback: AsyncCallback<void>): void 1457 1458Cancels the specified print job, which is on the print queue of the printer. This API uses an asynchronous callback 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| Print job ID.| 1470| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1471 1472**Example** 1473 1474```ts 1475import print from '@ohos.print'; 1476import { BusinessError } from '@ohos.base'; 1477 1478let jobId : string = '121212'; 1479print.cancelPrintJob(jobId, (err: BusinessError, data : void) => { 1480 if (err) { 1481 console.log('cancelPrintJob failed, because : ' + JSON.stringify(err)); 1482 } else { 1483 console.log('cancelPrintJob success, data: ' + JSON.stringify(data)); 1484 } 1485}) 1486``` 1487 1488## cancelPrintJob 1489 1490cancelPrintJob(jobId: string): Promise<void> 1491 1492Cancels the specified print job, which is on the print queue of the printer. This API uses a promise to return the result. 1493 1494**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1495 1496**System API**: This is a system API. 1497 1498**System capability**: SystemCapability.Print.PrintFramework 1499 1500**Parameters** 1501| **Name**| **Type**| **Mandatory**| **Description**| 1502| -------- | -------- | -------- | -------- | 1503| jobId | string | Yes| Print job ID.| 1504 1505**Return value** 1506| **Type**| **Description**| 1507| -------- | -------- | 1508| Promise<void> | Promise used to return the result.| 1509 1510**Example** 1511 1512```ts 1513import print from '@ohos.print'; 1514import { BusinessError } from '@ohos.base'; 1515 1516let jobId : string = '121212'; 1517print.cancelPrintJob(jobId).then((data : void) => { 1518 console.log('cancelPrintJob success, data : ' + JSON.stringify(data)); 1519}).catch((error: BusinessError) => { 1520 console.log('cancelPrintJob failed, because : ' + JSON.stringify(error)); 1521}) 1522``` 1523 1524## requestPrintPreview 1525 1526requestPrintPreview(jobInfo: PrintJob, callback: Callback<number>): void 1527 1528Requests print preview data. This API uses a callback to return the result. 1529 1530**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1531 1532**System API**: This is a system API. 1533 1534**System capability**: SystemCapability.Print.PrintFramework 1535 1536**Parameters** 1537| **Name**| **Type**| **Mandatory**| **Description**| 1538| -------- | -------- | -------- | -------- | 1539| jobInfo | PrintJob | Yes| Information about the print job.| 1540| callback | Callback<number> | Yes| Callback used to return the result.| 1541 1542**Example** 1543 1544```ts 1545import print from '@ohos.print'; 1546 1547let jobInfo : print.PrintJob = { 1548 fdList : [0,1], 1549 jobId : 'jobId_12', 1550 printerId : 'printerId_32', 1551 jobState : 3, 1552 jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, 1553 copyNumber : 1, 1554 pageRange : {}, 1555 isSequential : false, 1556 pageSize : {id : '', name : '', width : 10, height : 20}, 1557 isLandscape : false, 1558 colorMode : 6, 1559 duplexMode : 6, 1560 margin : undefined, 1561 preview : undefined, 1562 options : undefined 1563}; 1564print.requestPrintPreview(jobInfo, (num : number) => { 1565 console.log('requestPrintPreview success, num : ' + JSON.stringify(num)); 1566 1567}) 1568``` 1569 1570## requestPrintPreview 1571 1572requestPrintPreview(jobInfo: PrintJob): Promise<number> 1573 1574Requests print preview data. This API uses a promise to return the result. 1575 1576**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1577 1578**System API**: This is a system API. 1579 1580**System capability**: SystemCapability.Print.PrintFramework 1581 1582**Parameters** 1583| **Name**| **Type**| **Mandatory**| **Description**| 1584| -------- | -------- | -------- | -------- | 1585| jobInfo | PrintJob | Yes| Information about the print job.| 1586 1587**Return value** 1588| **Type**| **Description**| 1589| -------- | -------- | 1590| Promise<number> | Promise used to return the result.| 1591 1592**Example** 1593 1594```ts 1595import print from '@ohos.print'; 1596import { BusinessError } from '@ohos.base'; 1597 1598let jobInfo : print.PrintJob = { 1599 fdList : [0,1], 1600 jobId : 'jobId_12', 1601 printerId : 'printerId_32', 1602 jobState : 3, 1603 jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, 1604 copyNumber : 1, 1605 pageRange : {}, 1606 isSequential : false, 1607 pageSize : {id : '', name : '', width : 10, height : 20}, 1608 isLandscape : false, 1609 colorMode : 6, 1610 duplexMode : 6, 1611 margin : undefined, 1612 preview : undefined, 1613 options : undefined 1614}; 1615print.requestPrintPreview(jobInfo).then((num: number) => { 1616 console.log('requestPrintPreview success, num : ' + JSON.stringify(num)); 1617}).catch((error: BusinessError) => { 1618 console.log('requestPrintPreview failed, because : ' + JSON.stringify(error)); 1619}) 1620``` 1621 1622## on 1623 1624on(type: 'printerStateChange', callback: (state: PrinterState, info: PrinterInfo) => void): void 1625 1626Registers a listener for printer state change events. This API uses a callback to return the result. 1627 1628**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1629 1630**System API**: This is a system API. 1631 1632**System capability**: SystemCapability.Print.PrintFramework 1633 1634**Parameters** 1635| **Name**| **Type**| **Mandatory**| **Description**| 1636| -------- | -------- | -------- | -------- | 1637| type | 'printerStateChange' | Yes| Listening type. The value is fixed at **'printerStateChange'**.| 1638| callback | (state: PrinterState, info: PrinterInfo) => void | Yes| Callback used to return the result.| 1639 1640**Example** 1641 1642```ts 1643import print from '@ohos.print'; 1644 1645print.on('printerStateChange', (state: print.PrinterState, info: print.PrinterInfo) => { 1646 if (state === null || info === null) { 1647 console.log('printer state changed state is null or info is null'); 1648 return; 1649 } else { 1650 console.log('on printer state changed, state : ' + JSON.stringify(state)); 1651 console.log('on printer state changed, info : ' + JSON.stringify(info)); 1652 } 1653}) 1654``` 1655 1656## off 1657 1658off(type: 'printerStateChange', callback?: Callback<boolean>): void 1659 1660Unregisters the listener for printer state change events. This API uses a callback to return the result. 1661 1662**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1663 1664**System API**: This is a system API. 1665 1666**System capability**: SystemCapability.Print.PrintFramework 1667 1668**Parameters** 1669| **Name**| **Type**| **Mandatory**| **Description**| 1670| -------- | -------- | -------- | -------- | 1671| type | 'printerStateChange' | Yes| Listening type. The value is fixed at **'printerStateChange'**.| 1672| callback | Callback<boolean> | No| Callback used to return the result.| 1673 1674**Example** 1675 1676```ts 1677import print from '@ohos.print'; 1678 1679print.off('printerStateChange', (data: boolean) => { 1680 console.log('off printerStateChange data : ' + JSON.stringify(data)); 1681}) 1682``` 1683 1684## on 1685 1686on(type: 'jobStateChange', callback: (state: PrintJobState, job: PrintJob) => void): void 1687 1688Registers a listener for print job state change events. This API uses a callback to return the result. 1689 1690**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1691 1692**System API**: This is a system API. 1693 1694**System capability**: SystemCapability.Print.PrintFramework 1695 1696**Parameters** 1697| **Name**| **Type**| **Mandatory**| **Description**| 1698| -------- | -------- | -------- | -------- | 1699| type | 'jobStateChange' | Yes| Listening type. The value is fixed at **'jobStateChange'**.| 1700| callback | (state: PrintJobState, job: PrintJob) => void | Yes| Callback used to return the result.| 1701 1702**Example** 1703 1704```ts 1705import print from '@ohos.print'; 1706 1707print.on('jobStateChange', (state: print.PrintJobState, job: print.PrintJob) => { 1708 console.log('onJobStateChange, state : ' + JSON.stringify(state) + ', job : ' + JSON.stringify(job)); 1709}) 1710``` 1711 1712## off 1713 1714off(type: 'jobStateChange', callback?: Callback<boolean>): void 1715 1716Unregisters the listener for print job state change events. This API uses a callback to return the result. 1717 1718**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1719 1720**System API**: This is a system API. 1721 1722**System capability**: SystemCapability.Print.PrintFramework 1723 1724**Parameters** 1725| **Name**| **Type**| **Mandatory**| **Description**| 1726| -------- | -------- | -------- | -------- | 1727| type | 'jobStateChange' | Yes| Listening type. The value is fixed at **'jobStateChange'**.| 1728| callback | Callback<boolean> | No| Callback used to return the result.| 1729 1730**Example** 1731 1732```ts 1733import print from '@ohos.print'; 1734 1735print.off('jobStateChange', (data: boolean) => { 1736 console.log('offJobStateChanged data : ' + JSON.stringify(data)); 1737}) 1738``` 1739 1740## on 1741 1742on(type: 'extInfoChange', callback: (extensionId: string, info: string) => void): void 1743 1744Registers a listener for printer extension information change events. This API uses a callback to return the result. 1745 1746**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1747 1748**System API**: This is a system API. 1749 1750**System capability**: SystemCapability.Print.PrintFramework 1751 1752**Parameters** 1753| **Name**| **Type**| **Mandatory**| **Description**| 1754| -------- | -------- | -------- | -------- | 1755| type | 'extInfoChange' | Yes| Listening type. The value is fixed at **'extInfoChange'**.| 1756| callback | (extensionId: string, info: string) => void | Yes| Callback used to return the result.| 1757 1758**Example** 1759 1760```ts 1761import print from '@ohos.print'; 1762 1763print.on('extInfoChange', (extensionId: string, info: string) => { 1764 console.log('onExtInfoChange, entensionId : ' + JSON.stringify(extensionId) + ', info : ' + JSON.stringify(info)); 1765}) 1766``` 1767 1768## off 1769 1770off(type: 'extInfoChange', callback?: Callback<boolean>): void 1771 1772Unregisters the listener for printer extension information change events. This API uses a callback to return the result. 1773 1774**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1775 1776**System API**: This is a system API. 1777 1778**System capability**: SystemCapability.Print.PrintFramework 1779 1780**Parameters** 1781| **Name**| **Type**| **Mandatory**| **Description**| 1782| -------- | -------- | -------- | -------- | 1783| type | 'extInfoChange' | Yes| Listening type. The value is fixed at **'extInfoChange'**.| 1784| callback | Callback<boolean> | No| Callback used to return the result.| 1785 1786**Example** 1787 1788```ts 1789import print from '@ohos.print'; 1790 1791print.off('extInfoChange', (data: boolean) => { 1792 console.log('offExtInfoChange data : ' + JSON.stringify(data)); 1793}) 1794``` 1795 1796## addPrinters 1797 1798addPrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void 1799 1800Adds printers. This API uses an asynchronous callback to return the result. 1801 1802**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1803 1804**System API**: This is a system API. 1805 1806**System capability**: SystemCapability.Print.PrintFramework 1807 1808**Parameters** 1809| **Name**| **Type**| **Mandatory**| **Description**| 1810| -------- | -------- | -------- | -------- | 1811| printers | Array<PrinterInfo> | Yes| List of printers to add.| 1812| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1813 1814**Example** 1815 1816```ts 1817import print from '@ohos.print'; 1818import { BusinessError } from '@ohos.base'; 1819 1820let printerInfo : print.PrinterInfo = { 1821 printerId : '3232', 1822 printerName : 'hhhhh', 1823 printerState : 0, 1824 printerIcon : 12, 1825 description : 'str', 1826 capability : undefined, 1827 options : 'opt' 1828}; 1829print.addPrinters([printerInfo], (err: BusinessError, data : void) => { 1830 if (err) { 1831 console.log('addPrinters failed, because : ' + JSON.stringify(err)); 1832 } else { 1833 console.log('addPrinters success, data : ' + JSON.stringify(data)); 1834 } 1835}) 1836``` 1837 1838## addPrinters 1839 1840addPrinters(printers: Array<PrinterInfo>): Promise<void> 1841 1842Adds printers. This API uses a promise to return the result. 1843 1844**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1845 1846**System API**: This is a system API. 1847 1848**System capability**: SystemCapability.Print.PrintFramework 1849 1850**Parameters** 1851| **Name**| **Type**| **Mandatory**| **Description**| 1852| -------- | -------- | -------- | -------- | 1853| printers | Array<PrinterInfo> | Yes| List of printers to add.| 1854 1855**Return value** 1856| **Type**| **Description**| 1857| -------- | -------- | 1858| Promise<void> | Promise used to return the result.| 1859 1860**Example** 1861 1862```ts 1863import print from '@ohos.print'; 1864import { BusinessError } from '@ohos.base'; 1865 1866let printerInfo : print.PrinterInfo = { 1867 printerId : '3232', 1868 printerName : 'hhhhh', 1869 printerState : 0, 1870 printerIcon : 12, 1871 description : 'str', 1872 capability : undefined, 1873 options : 'opt' 1874}; 1875print.addPrinters([printerInfo]).then((data : void) => { 1876 console.log('add printers data : ' + JSON.stringify(data)); 1877}).catch((error: BusinessError) => { 1878 console.log('add printers error : ' + JSON.stringify(error)); 1879}) 1880``` 1881 1882## removePrinters 1883 1884removePrinters(printerIds: Array<string>, callback: AsyncCallback<void>): void 1885 1886Removes printers. This API uses an asynchronous callback to return the result. 1887 1888**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1889 1890**System API**: This is a system API. 1891 1892**System capability**: SystemCapability.Print.PrintFramework 1893 1894**Parameters** 1895| **Name**| **Type**| **Mandatory**| **Description**| 1896| -------- | -------- | -------- | -------- | 1897| printerIds | Array<string> | Yes| List of printers to remove.| 1898| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1899 1900**Example** 1901 1902```ts 1903import print from '@ohos.print'; 1904import { BusinessError } from '@ohos.base'; 1905 1906let printerId : string = '1212'; 1907print.removePrinters([printerId], (err: BusinessError, data : void) => { 1908 if (err) { 1909 console.log('removePrinters failed, because : ' + JSON.stringify(err)); 1910 } else { 1911 console.log('removePrinters success, data : ' + JSON.stringify(data)); 1912 } 1913}) 1914``` 1915 1916## removePrinters 1917 1918removePrinters(printerIds: Array<string>): Promise<void> 1919 1920Removes printers. This API uses a promise to return the result. 1921 1922**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1923 1924**System API**: This is a system API. 1925 1926**System capability**: SystemCapability.Print.PrintFramework 1927 1928**Parameters** 1929| **Name**| **Type**| **Mandatory**| **Description**| 1930| -------- | -------- | -------- | -------- | 1931| printerIds | Array<string> | Yes| List of printers to remove.| 1932 1933**Return value** 1934| **Type**| **Description**| 1935| -------- | -------- | 1936| Promise<void> | Promise used to return the result.| 1937 1938**Example** 1939 1940```ts 1941import print from '@ohos.print'; 1942import { BusinessError } from '@ohos.base'; 1943 1944let printerId : string = '1212'; 1945print.removePrinters([printerId]).then((data : void) => { 1946 console.log('remove printers data : ' + JSON.stringify(data)); 1947}).catch((error: BusinessError) => { 1948 console.log('remove printers error : ' + JSON.stringify(error)); 1949}) 1950``` 1951 1952## updatePrinters 1953 1954updatePrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void 1955 1956Updates information about the specified printers. This API uses an asynchronous callback to return the result. 1957 1958**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 1959 1960**System API**: This is a system API. 1961 1962**System capability**: SystemCapability.Print.PrintFramework 1963 1964**Parameters** 1965| **Name**| **Type**| **Mandatory**| **Description**| 1966| -------- | -------- | -------- | -------- | 1967| printers | Array<PrinterInfo> | Yes| List of printers whose information is to be updated.| 1968| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1969 1970**Example** 1971 1972```ts 1973import print from '@ohos.print'; 1974import { BusinessError } from '@ohos.base'; 1975 1976let printerInfo : print.PrinterInfo = { 1977 printerId : '3232', 1978 printerName : 'hhhhh', 1979 printerState : 0, 1980 printerIcon : 12, 1981 description : 'str', 1982 capability : undefined, 1983 options : 'opt' 1984}; 1985print.updatePrinters([printerInfo], (err: BusinessError, data : void) => { 1986 if (err) { 1987 console.log('updataPrinters failed, because : ' + JSON.stringify(err)); 1988 } else { 1989 console.log('updataPrinters success, data : ' + JSON.stringify(data)); 1990 } 1991}) 1992``` 1993 1994## updatePrinters 1995 1996updatePrinters(printers: Array<PrinterInfo>): Promise<void> 1997 1998Updates information about the specified printers. This API uses a promise to return the result. 1999 2000**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2001 2002**System API**: This is a system API. 2003 2004**System capability**: SystemCapability.Print.PrintFramework 2005 2006**Parameters** 2007| **Name**| **Type**| **Mandatory**| **Description**| 2008| -------- | -------- | -------- | -------- | 2009| printers | Array<PrinterInfo> | Yes| List of printers whose information is to be updated.| 2010 2011**Return value** 2012| **Type**| **Description**| 2013| -------- | -------- | 2014| Promise<void> | Promise used to return the result.| 2015 2016**Example** 2017 2018```ts 2019import print from '@ohos.print'; 2020import { BusinessError } from '@ohos.base'; 2021 2022let printerInfo : print.PrinterInfo = { 2023 printerId : '3232', 2024 printerName : 'hhhhh', 2025 printerState : 0, 2026 printerIcon : 12, 2027 description : 'str', 2028 capability : undefined, 2029 options : 'opt' 2030}; 2031print.updatePrinters([printerInfo]).then((data : void) => { 2032 console.log('update printers data : ' + JSON.stringify(data)); 2033}).catch((error: BusinessError) => { 2034 console.log('update printers error : ' + JSON.stringify(error)); 2035}) 2036``` 2037 2038## updatePrinterState 2039 2040updatePrinterState(printerId: string, state: PrinterState, callback: AsyncCallback<void>): void 2041 2042Updates the printer state. This API uses an asynchronous callback to return the result. 2043 2044**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2045 2046**System API**: This is a system API. 2047 2048**System capability**: SystemCapability.Print.PrintFramework 2049 2050**Parameters** 2051| **Name**| **Type**| **Mandatory**| **Description**| 2052| -------- | -------- | -------- | -------- | 2053| printerId | string | Yes| Printer ID.| 2054| state | PrinterState | Yes| Printer state.| 2055| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 2056 2057**Example** 2058 2059```ts 2060import print from '@ohos.print'; 2061import { BusinessError } from '@ohos.base'; 2062 2063let printerId : string = '1212'; 2064let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED; 2065print.updatePrinterState(printerId, state, (err: BusinessError, data : void) => { 2066 if (err) { 2067 console.log('updataPrinterState failed, because : ' + JSON.stringify(err)); 2068 } else { 2069 console.log('updataPrinterState success, data : ' + JSON.stringify(data)); 2070 } 2071}) 2072``` 2073 2074## updatePrinterState 2075 2076updatePrinterState(printerId: string, state: PrinterState): Promise<void> 2077 2078Updates the printer state. This API uses a promise to return the result. 2079 2080**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2081 2082**System API**: This is a system API. 2083 2084**System capability**: SystemCapability.Print.PrintFramework 2085 2086**Parameters** 2087| **Name**| **Type**| **Mandatory**| **Description**| 2088| -------- | -------- | -------- | -------- | 2089| printerId | string | Yes| Printer ID.| 2090| state | PrinterState | Yes| Printer state.| 2091 2092**Return value** 2093| **Type**| **Description**| 2094| -------- | -------- | 2095| Promise<void> | Promise used to return the result.| 2096 2097**Example** 2098 2099```ts 2100import print from '@ohos.print'; 2101import { BusinessError } from '@ohos.base'; 2102 2103let printerId : string = '1212'; 2104let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED; 2105print.updatePrinterState(printerId, state).then((data : void) => { 2106 console.log('update printer state data : ' + JSON.stringify(data)); 2107}).catch((error: BusinessError) => { 2108 console.log('update printer state error : ' + JSON.stringify(error)); 2109}) 2110``` 2111 2112## updatePrintJobState 2113 2114updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState, callback: AsyncCallback<void>): void 2115 2116Updates the print job state. This API uses an asynchronous callback to return the result. 2117 2118**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2119 2120**System API**: This is a system API. 2121 2122**System capability**: SystemCapability.Print.PrintFramework 2123 2124**Parameters** 2125| **Name**| **Type**| **Mandatory**| **Description**| 2126| -------- | -------- | -------- | -------- | 2127| jobId | string | Yes| ID of the print job.| 2128| state | PrintJobState | Yes| State of the print job.| 2129| subState | PrintJobSubState | Yes| Substate of the print job.| 2130| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 2131 2132**Example** 2133 2134```ts 2135import print from '@ohos.print'; 2136import { BusinessError } from '@ohos.base'; 2137 2138let jobId : string = '3434'; 2139let state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE; 2140let subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS; 2141print.updatePrintJobState(jobId, state, subState, (err: BusinessError, data : void) => { 2142 if (err) { 2143 console.log('updataPrintJobState failed, because : ' + JSON.stringify(err)); 2144 } else { 2145 console.log('updatePrintJobState success, data : ' + JSON.stringify(data)); 2146 } 2147}) 2148``` 2149 2150## updatePrintJobState 2151 2152updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState): Promise<void> 2153 2154Updates the print job state. This API uses a promise to return the result. 2155 2156**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2157 2158**System API**: This is a system API. 2159 2160**System capability**: SystemCapability.Print.PrintFramework 2161 2162**Parameters** 2163| **Name**| **Type**| **Mandatory**| **Description**| 2164| -------- | -------- | -------- | -------- | 2165| jobId | string | Yes| ID of the print job.| 2166| state | PrintJobState | Yes| State of the print job.| 2167| subState | PrintJobSubState | Yes| Substate of the print job.| 2168 2169**Return value** 2170| **Type**| **Description**| 2171| -------- | -------- | 2172| Promise<void> | Promise used to return the result.| 2173 2174**Example** 2175 2176```ts 2177import print from '@ohos.print'; 2178import { BusinessError } from '@ohos.base'; 2179 2180let jobId : string = '3434'; 2181let state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE; 2182let subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS; 2183print.updatePrintJobState(jobId, state, subState).then((data : void) => { 2184 console.log('update print job state data : ' + JSON.stringify(data)); 2185}).catch((error: BusinessError) => { 2186 console.log('update print job state error : ' + JSON.stringify(error)); 2187}) 2188``` 2189 2190## updateExtensionInfo 2191 2192updateExtensionInfo(info: string, callback: AsyncCallback<void>): void 2193 2194Updates the printer extension information. This API uses an asynchronous callback to return the result. 2195 2196**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2197 2198**System API**: This is a system API. 2199 2200**System capability**: SystemCapability.Print.PrintFramework 2201 2202**Parameters** 2203| **Name**| **Type**| **Mandatory**| **Description**| 2204| -------- | -------- | -------- | -------- | 2205| info | string | Yes| New printer extension information.| 2206| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 2207 2208**Example** 2209 2210```ts 2211import print from '@ohos.print'; 2212import { BusinessError } from '@ohos.base'; 2213 2214let info : string = 'WIFI_INACTIVE'; 2215print.updateExtensionInfo(info, (err: BusinessError, data : void) => { 2216 if (err) { 2217 console.log('updateExtensionInfo failed, because : ' + JSON.stringify(err)); 2218 } else { 2219 console.log('updateExtensionInfo success, data : ' + JSON.stringify(data)); 2220 } 2221}) 2222``` 2223 2224## updateExtensionInfo 2225 2226updateExtensionInfo(info: string): Promise<void> 2227 2228Updates the printer extension information. This API uses a promise to return the result. 2229 2230**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2231 2232**System API**: This is a system API. 2233 2234**System capability**: SystemCapability.Print.PrintFramework 2235 2236**Parameters** 2237| **Name**| **Type**| **Mandatory**| **Description**| 2238| -------- | -------- | -------- | -------- | 2239| info | string | Yes| New printer extension information.| 2240 2241**Return value** 2242| **Type**| **Description**| 2243| -------- | -------- | 2244| Promise<void> | Promise used to return the result.| 2245 2246**Example** 2247 2248```ts 2249import print from '@ohos.print'; 2250import { BusinessError } from '@ohos.base'; 2251 2252let info : string = 'WIFI_INACTIVE'; 2253print.updateExtensionInfo(info).then((data : void) => { 2254 console.log('update print job state data : ' + JSON.stringify(data)); 2255}).catch((error: BusinessError) => { 2256 console.log('update print job state error : ' + JSON.stringify(error)); 2257}) 2258``` 2259 2260## queryAllPrintJobs<sup>(deprecated)</sup> 2261 2262> This API is supported since API version 10 and deprecated since API version 11. 2263> You are advised to use [queryPrintJobList](#queryprintjoblist11) instead. 2264 2265queryAllPrintJobs(callback: AsyncCallback<void>): void 2266 2267Queries all print jobs. This API uses an asynchronous callback to return the result. 2268 2269**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2270 2271**System API**: This is a system API. 2272 2273**System capability**: SystemCapability.Print.PrintFramework 2274 2275**Parameters** 2276| **Name**| **Type**| **Mandatory**| **Description**| 2277| -------- | -------- | -------- | -------- | 2278| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 2279 2280**Example** 2281 2282```ts 2283import print from '@ohos.print'; 2284import { BusinessError } from '@ohos.base'; 2285 2286print.queryAllPrintJobs((err: BusinessError, data : void) => { 2287 if (err) { 2288 console.log('queryAllPrintJobs failed, because : ' + JSON.stringify(err)); 2289 } else { 2290 console.log('queryAllPrintJobs success, data : ' + JSON.stringify(data)); 2291 } 2292}) 2293``` 2294 2295## queryAllPrintJobs<sup>(deprecated)</sup> 2296 2297> This API is supported since API version 10 and deprecated since API version 11. 2298> You are advised to use [queryPrintJobList](#queryprintjoblist11-1) instead. 2299 2300queryAllPrintJobs(): Promise<void> 2301 2302Queries all print jobs. This API uses a promise used to return the result. 2303 2304**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2305 2306**System API**: This is a system API. 2307 2308**System capability**: SystemCapability.Print.PrintFramework 2309 2310**Return value** 2311| **Type**| **Description**| 2312| -------- | -------- | 2313| Promise<void> | Promise used to return the result.| 2314 2315**Example** 2316 2317```ts 2318import print from '@ohos.print'; 2319import { BusinessError } from '@ohos.base'; 2320 2321print.queryAllPrintJobs().then((data : void) => { 2322 console.log('queryAllPrintJobs success, data : ' + JSON.stringify(data)); 2323}).catch((error: BusinessError) => { 2324 console.log('queryAllPrintJobs failed, error : ' + JSON.stringify(error)); 2325}) 2326``` 2327 2328## queryPrintJobList<sup>11+</sup> 2329 2330queryPrintJobList(callback: AsyncCallback<Array<PrintJob>>): void 2331 2332Queries all print jobs. This API uses an asynchronous callback to return the result. 2333 2334**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2335 2336**System API**: This is a system API. 2337 2338**System capability**: SystemCapability.Print.PrintFramework 2339 2340**Parameters** 2341| **Name**| **Type**| **Mandatory**| **Description**| 2342| -------- | -------- | -------- | -------- | 2343| callback | AsyncCallback<Array<PrintJob>> | Yes| Callback used to return the result.| 2344 2345**Example** 2346 2347```ts 2348import print from '@ohos.print'; 2349import { BusinessError } from '@ohos.base'; 2350 2351print.queryPrintJobList((err: BusinessError, printJobs : print.PrintJob[]) => { 2352 if (err) { 2353 console.log('queryPrintJobList failed, because : ' + JSON.stringify(err)); 2354 } else { 2355 console.log('queryPrintJobList success, data : ' + JSON.stringify(printJobs)); 2356 } 2357}) 2358``` 2359 2360## queryPrintJobList<sup>11+</sup> 2361 2362queryPrintJobList(): Promise<Array<PrintJob>> 2363 2364Queries all print jobs. This API uses a promise used to return the result. 2365 2366**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2367 2368**System API**: This is a system API. 2369 2370**System capability**: SystemCapability.Print.PrintFramework 2371 2372**Return value** 2373| **Type**| **Description**| 2374| -------- | -------- | 2375| Promise<Array<PrintJob>> | Promise used to return the result.| 2376 2377**Example** 2378 2379```ts 2380import print from '@ohos.print'; 2381import { BusinessError } from '@ohos.base'; 2382 2383print.queryPrintJobList().then((printJobs : print.PrintJob[]) => { 2384 console.log('queryPrintJobList success, data : ' + JSON.stringify(printJobs)); 2385}).catch((error: BusinessError) => { 2386 console.log('queryPrintJobList failed, error : ' + JSON.stringify(error)); 2387}) 2388``` 2389 2390## queryPrintJobById<sup>11+</sup> 2391 2392queryPrintJobById(jobId: string, callback: AsyncCallback<PrintJob>): void 2393 2394Queries a print job by ID. This API uses an asynchronous callback to return the result. 2395 2396**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2397 2398**System API**: This is a system API. 2399 2400**System capability**: SystemCapability.Print.PrintFramework 2401 2402**Parameters** 2403| **Name**| **Type**| **Mandatory**| **Description**| 2404| -------- | -------- | -------- | -------- | 2405| jobId | string | Yes| ID of the print job.| 2406| callback | AsyncCallback<PrintJob> | Yes| Callback used to return the result.| 2407 2408**Example** 2409 2410```ts 2411import print from '@ohos.print'; 2412import { BusinessError } from '@ohos.base'; 2413 2414let jobId : string = '1'; 2415print.queryPrintJobById(jobId, (err: BusinessError, printJob : print.PrintJob) => { 2416 if (err) { 2417 console.log('queryPrintJobById failed, because : ' + JSON.stringify(err)); 2418 } else { 2419 console.log('queryPrintJobById success, data : ' + JSON.stringify(printJob)); 2420 } 2421}) 2422``` 2423 2424## queryPrintJobById<sup>11+</sup> 2425 2426queryPrintJobById(jobId: string): Promise<PrintJob> 2427 2428Queries a print job by ID. This API uses a promise to return the result. 2429 2430**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2431 2432**System API**: This is a system API. 2433 2434**System capability**: SystemCapability.Print.PrintFramework 2435 2436**Parameters** 2437| **Name**| **Type**| **Mandatory**| **Description**| 2438| -------- | -------- | -------- | -------- | 2439| jobId | string | Yes| ID of the print job.| 2440 2441**Return value** 2442| **Type**| **Description**| 2443| -------- | -------- | 2444| Promise<PrintJob> | Promise used to return the result.| 2445 2446**Example** 2447 2448```ts 2449import print from '@ohos.print'; 2450import { BusinessError } from '@ohos.base'; 2451 2452let jobId : string = '1'; 2453print.queryPrintJobById(jobId).then((printJob : print.PrintJob) => { 2454 console.log('queryPrintJobById data : ' + JSON.stringify(printJob)); 2455}).catch((error: BusinessError) => { 2456 console.log('queryPrintJobById error : ' + JSON.stringify(error)); 2457}) 2458``` 2459 2460## startGettingPrintFile<sup>11+</sup> 2461 2462startGettingPrintFile(jobId: string, printAttributes: PrintAttributes, fd: number, onFileStateChanged: Callback<PrintFileCreationState>): void 2463 2464Starts to obtain the print file. This API uses an asynchronous callback to return the result. 2465 2466**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2467 2468**System API**: This is a system API. 2469 2470**System capability**: SystemCapability.Print.PrintFramework 2471 2472**Parameters** 2473| **Name**| **Type**| **Mandatory**| **Description**| 2474| -------- | -------- | -------- | -------- | 2475| jobId | string | Yes| ID of the print job.| 2476| printAttributes | PrintAttributes | Yes| Print attributes.| 2477| fd | number | Yes| File descriptor.| 2478| onFileStateChanged | Callback<PrintFileCreationState> | Yes| Callback for updating the file state.| 2479 2480**Example** 2481 2482```ts 2483import print from '@ohos.print'; 2484import { BusinessError } from '@ohos.base'; 2485 2486let jobId : string= '1'; 2487class MyPrintAttributes implements print.PrintAttributes { 2488 copyNumber?: number; 2489 pageRange?: print.PrintPageRange; 2490 pageSize?: print.PrintPageSize | print.PrintPageType; 2491 directionMode?: print.PrintDirectionMode; 2492 colorMode?: print.PrintColorMode; 2493 duplexMode?: print.PrintDuplexMode; 2494} 2495 2496class MyPrintPageRange implements print.PrintPageRange { 2497 startPage?: number; 2498 endPage?: number; 2499 pages?: Array<number>; 2500} 2501 2502class MyPrintPageSize implements print.PrintPageSize { 2503 id: string = '0'; 2504 name: string = '0'; 2505 width: number = 210; 2506 height: number = 297; 2507} 2508 2509let printAttributes = new MyPrintAttributes(); 2510printAttributes.copyNumber = 2; 2511printAttributes.pageRange = new MyPrintPageRange(); 2512printAttributes.pageRange.startPage = 0; 2513printAttributes.pageRange.endPage = 5; 2514printAttributes.pageRange.pages = [1, 3]; 2515printAttributes.pageSize = print.PrintPageType.PAGE_ISO_A3; 2516printAttributes.directionMode = print.PrintDirectionMode.DIRECTION_MODE_AUTO; 2517printAttributes.colorMode = print.PrintColorMode.COLOR_MODE_MONOCHROME; 2518printAttributes.duplexMode = print.PrintDuplexMode.DUPLEX_MODE_NONE; 2519 2520let fd : number = 1; 2521print.startGettingPrintFile(jobId, printAttributes, fd, (state: print.PrintFileCreationState) => { 2522 console.log('onFileStateChanged success, data : ' + JSON.stringify(state)); 2523}) 2524``` 2525 2526## notifyPrintService<sup>11+</sup> 2527 2528notifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started', callback: AsyncCallback<void>): void 2529 2530Notifies the print service of the spooler shutdown information. This API uses an asynchronous callback to return the result. 2531 2532**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2533 2534**System API**: This is a system API. 2535 2536**System capability**: SystemCapability.Print.PrintFramework 2537 2538**Parameters** 2539| **Name**| **Type**| **Mandatory**| **Description**| 2540| -------- | -------- | -------- | -------- | 2541| jobId | string | Yes| ID of the print job.| 2542| type | 'spooler_closed_for_cancelled' \| 'spooler_closed_for_started' | Yes| Spooler shutdown information.| 2543| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 2544 2545**Example** 2546 2547```ts 2548import print from '@ohos.print'; 2549import { BusinessError } from '@ohos.base'; 2550 2551let jobId : string = '1'; 2552print.notifyPrintService(jobId, 'spooler_closed_for_started', (err: BusinessError, data : void) => { 2553 if (err) { 2554 console.log('notifyPrintService failed, because : ' + JSON.stringify(err)); 2555 } else { 2556 console.log('notifyPrintService success, data : ' + JSON.stringify(data)); 2557 } 2558}) 2559``` 2560 2561## notifyPrintService<sup>11+</sup> 2562 2563notifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started'): Promise<void> 2564 2565Notifies the print service of the print spooler shutdown information. This API uses a promise to return the result. 2566 2567**Required permissions**: ohos.permission.MANAGE_PRINT_JOB 2568 2569**System API**: This is a system API. 2570 2571**System capability**: SystemCapability.Print.PrintFramework 2572 2573**Parameters** 2574| **Name**| **Type**| **Mandatory**| **Description**| 2575| -------- | -------- | -------- | -------- | 2576| jobId | string | Yes| ID of the print job.| 2577| type | 'spooler_closed_for_cancelled' \| 'spooler_closed_for_started' | Yes| Spooler shutdown information.| 2578 2579**Return value** 2580| **Type**| **Description**| 2581| -------- | -------- | 2582| Promise<void> | Promise used to return the result.| 2583 2584**Example** 2585 2586```ts 2587import print from '@ohos.print'; 2588import { BusinessError } from '@ohos.base'; 2589 2590let jobId : string = '1'; 2591print.notifyPrintService(jobId, 'spooler_closed_for_started').then((data : void) => { 2592 console.log('notifyPrintService data : ' + JSON.stringify(data)); 2593}).catch((error: BusinessError) => { 2594 console.log('notifyPrintService error : ' + JSON.stringify(error)); 2595}) 2596``` 2597