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