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