# @ohos.print (打å°)(系统接å£) 该模å—为基本打å°çš„æ“作API,æ供调用基础打å°åŠŸèƒ½çš„接å£ã€‚ > **说明:** > 本模å—首批接å£ä»ŽAPI version 10开始支æŒã€‚åŽç»ç‰ˆæœ¬çš„新增接å£ï¼Œé‡‡ç”¨ä¸Šè§’æ ‡å•ç‹¬æ ‡è®°æŽ¥å£çš„起始版本。 > 当å‰ç•Œé¢ä»…包å«æœ¬æ¨¡å—的系统接å£ï¼Œå…¶ä»–公开接å£å‚è§[@ohos.print (打å°)](./js-apis-print-sys.md)。 ## å¯¼å…¥æ¨¡å— ```ts import { print } from '@kit.BasicServicesKit'; ``` ## PrintMargin 定义打å°é¡µè¾¹è·çš„接å£ã€‚ **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **属性:** | **å称** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | top | number | å¦ | 表示页é¢ä¸Šè¾¹è· | | bottom | number | å¦ | 表示页é¢ä¸‹è¾¹è· | | left | number | å¦ | 表示页é¢å·¦è¾¹è· | | right | number | å¦ | 表示页é¢å³è¾¹è· | ## PrinterRange 定义打å°èŒƒå›´çš„接å£ã€‚ **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **属性:** | **å称** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | startPage | number | å¦ | 表示起始页 | | endPage | number | å¦ | 表示结æŸé¡µ | | pages | Array<number> | å¦ | è¡¨ç¤ºç¦»æ•£é¡µé¢ | ## PreviewAttribute 定义打å°é¢„览属性的接å£ã€‚ **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **属性:** | **å称** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | previewRange | PrinterRange | 是 | 表示预览页é¢èŒƒå›´ | | result | number | å¦ | 表示预览文件结果 | ## PrintResolution 定义打å°åˆ†è¾¨çŽ‡çš„接å£ã€‚ **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **属性:** | **å称** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | id | string | 是 | 表示分辨率ID | | horizontalDpi | number | 是 | 表示水平DPI | | verticalDpi | number | 是 | 表示垂直DPI | ## PrinterCapability 定义打å°èƒ½åŠ›çš„接å£ã€‚ **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **属性:** | **å称** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | colorMode | number | 是 | è¡¨ç¤ºè‰²å½©æ¨¡å¼ | | duplexMode | number | 是 | 表示å•åŒé¢æ‰“å°æ¨¡å¼ | | pageSize | Array<PrintPageSize> | 是 | 表示打å°æœºæ”¯æŒçš„页é¢å°ºå¯¸åˆ—表 | | resolution | Array<PrintResolution> | å¦ | 表示打å°æœºæ”¯æŒçš„分辨率列表 | | minMargin | PrintMargin | å¦ | 表示打å°æœºæœ€å°è¾¹è· | | options<sup>11+</sup> | Object | å¦ | 表示JSON对象å—符串 | ## PrinterInfo 定义打å°ä¿¡æ¯çš„接å£ã€‚ **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **属性:** | **å称** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerId | string | 是 | 表示打å°æœºID | | printerName | string | 是 | 表示打å°æœºå称 | | printerState | PrinterState | 是 | 表示当å‰æ‰“å°æœºçŠ¶æ€ | | printerIcon | number | å¦ | 表示打å°æœºå›¾æ ‡çš„资æºID | | description | string | å¦ | 表示打å°æœºè¯´æ˜Ž | | capability | PrinterCapability | å¦ | 表示打å°æœºåŠŸèƒ½ | | options | Object | å¦ | 表示JSON对象å—符串 | ## PrintJob 定义打å°ä»»åŠ¡çš„接å£ã€‚ **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **属性:** | **å称** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | fdList | Array<number> | 是 | 表示待打å°æ–‡ä»¶fd列表 | | jobId | string | 是 | 表示打å°ä»»åŠ¡ID | | printerId | string | 是 | 表示负责打å°çš„打å°æœºID | | jobState | PrintJobState | 是 | 表示当å‰æ‰“å°ä»»åŠ¡çŠ¶æ€ | | jobSubstate<sup>11+</sup> | PrintJobSubState | 是 | 表示当å‰æ‰“å°ä»»åŠ¡åçŠ¶æ€ | | copyNumber | number | 是 | 表示文件列表副本 | | pageRange | PrinterRange | 是 | 表示打å°èŒƒå›´å¤§å° | | isSequential | boolean | 是 | 表示连ç»æ‰“å° | | pageSize | PrintPageSize | 是 | 表示选定的页é¢å°ºå¯¸ | | isLandscape | boolean | 是 | è¡¨ç¤ºåž‚ç›´æ‰“å° | | colorMode | number | 是 | è¡¨ç¤ºè‰²å½©æ¨¡å¼ | | duplexMode | number | 是 | 表示å•åŒé¢æ‰“å°æ¨¡å¼ | | margin | PrintMargin | å¦ | 表示当å‰é¡µè¾¹è·è®¾ç½® | | preview | PreviewAttribute | å¦ | 表示预览设置 | | options | Object | å¦ | 表示JSON对象å—符串 | ## PrinterExtensionInfo 定义打å°æ‰©å±•ä¿¡æ¯çš„接å£ã€‚ **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **属性:** | **å称** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | extensionId | string | 是 | 表示打å°æœºæ‰©å±•çš„扩展ID | | vendorId | string | 是 | 表示扩展的供应商ID | | vendorName | string | 是 | 表示供应商å称 | | vendorIcon | number | 是 | è¡¨ç¤ºä¾›åº”å•†å›¾æ ‡ | | version | string | 是 | 表示当å‰æ‰“å°æœºæ‰©å±•çš„版本 | ## queryAllPrinterExtensionInfos queryAllPrinterExtensionInfos(callback: AsyncCallback<Array<PrinterExtensionInfo>>): void 查询所有已安装的打å°æœºæ‰©å±•æœåŠ¡ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<Array<PrinterExtensionInfo>> | 是 | 异æ¥æŸ¥è¯¢æ‰€æœ‰å·²å®‰è£…的打å°æœºæ‰©å±•æœåŠ¡ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; print.queryAllPrinterExtensionInfos((err: BusinessError, extensionInfos: print.PrinterExtensionInfo[]) => { if (err) { console.log('queryAllPrinterExtensionInfos err ' + JSON.stringify(err)); } else { console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos)); } }) ``` ## queryAllPrinterExtensionInfos queryAllPrinterExtensionInfos(): Promise<Array<PrinterExtensionInfo>> 查询所有已安装的打å°æœºæ‰©å±•æœåŠ¡ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<Array<PrinterExtensionInfo>> | 查询所有已安装的打å°æœºæ‰©å±•æœåŠ¡å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; print.queryAllPrinterExtensionInfos().then((extensionInfos: print.PrinterExtensionInfo[]) => { console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos)); // ... }).catch((error: BusinessError) => { console.log('failed to get AllPrinterExtension bacause ' + JSON.stringify(error)); }) ``` ## startDiscoverPrinter startDiscoverPrinter(extensionList: Array<string>, callback: AsyncCallback<void>): void åŠ è½½ç‰¹å®šçš„æ‰“å°æœºæ‰©å±•å¹¶å¼€å§‹å‘现打å°æœºï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | extensionList | Array<string> | 是 | è¦åŠ 载的打å°æœºæ‰©å±•åˆ—表 | | callback | AsyncCallback<void> | 是 | 异æ¥å¼€å§‹å‘现打å°æœºä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let extensionList: string[] = []; //extensionListå†…æ— ä¿¡æ¯è¡¨ç¤ºå‘现所有扩展 print.startDiscoverPrinter(extensionList, (err: BusinessError, data : void) => { if (err) { console.log('failed to start Discover Printer because : ' + JSON.stringify(err)); } else { console.log('start Discover Printer success data : ' + JSON.stringify(data)); } }) ``` ## startDiscoverPrinter startDiscoverPrinter(extensionList: Array<string>): Promise<void> åŠ è½½ç‰¹å®šçš„æ‰“å°æœºæ‰©å±•å¹¶å¼€å§‹å‘现打å°æœºï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | extensionList | Array<string> | 是 | è¦åŠ 载的打å°æœºæ‰©å±•åˆ—表 | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | åŠ è½½ç‰¹å®šçš„æ‰“å°æœºæ‰©å±•å¹¶å¼€å§‹å‘现打å°æœºå®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let extensionList: string[] = []; //extensionListå†…æ— ä¿¡æ¯è¡¨ç¤ºå‘现所有扩展 print.startDiscoverPrinter(extensionList).then((data : void) => { console.log('start Discovery success data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('failed to start Discovery because : ' + JSON.stringify(error)); }) ``` ## stopDiscoverPrinter stopDiscoverPrinter(callback: AsyncCallback<void>): void åœæ¢å‘现具有特定打å°æœºæ‰©å±•çš„打å°æœºï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<void> | 是 | 异æ¥åœæ¢å‘现具有特定打å°æœºæ‰©å±•çš„打å°æœºä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; print.stopDiscoverPrinter((err: BusinessError, data : void) => { if (err) { console.log('failed to stop Discover Printer because : ' + JSON.stringify(err)); } else { console.log('stop Discover Printer success data : ' + JSON.stringify(data)); } }) ``` ## stopDiscoverPrinter stopDiscoverPrinter(): Promise<void> åœæ¢å‘现具有特定打å°æœºæ‰©å±•çš„打å°æœºï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | åœæ¢å‘现具有特定打å°æœºæ‰©å±•çš„打å°æœºå®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; print.stopDiscoverPrinter().then((data : void) => { console.log('stop Discovery success data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('failed to stop Discovery because : ' + JSON.stringify(error)); }) ``` ## connectPrinter connectPrinter(printerId: string, callback: AsyncCallback<void>): void 连接特定打å°æœºï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerId | string | 是 | 打å°æœºID | | callback | AsyncCallback<void> | 是 | 异æ¥è¿žæŽ¥ç‰¹å®šæ‰“å°æœºä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId: string = 'printerId_32'; print.connectPrinter(printerId, (err: BusinessError, data : void) => { if (err) { console.log('failed to connect Printer because : ' + JSON.stringify(err)); } else { console.log('start connect Printer success data : ' + JSON.stringify(data)); } }) ``` ## connectPrinter connectPrinter(printerId: string): Promise<void> 连接特定打å°æœºï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerId | string | 是 | 打å°æœºID | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | 连接特定打å°æœºå®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId: string = 'printerId_32'; print.connectPrinter(printerId).then((data : void) => { console.log('start connect Printer success data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('failed to connect Printer because : ' + JSON.stringify(error)); }) ``` ## disconnectPrinter disconnectPrinter(printerId: string, callback: AsyncCallback<void>): void æ–开特定打å°æœºçš„连接,使用callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerId | string | 是 | 打å°æœºID | | callback | AsyncCallback<void> | 是 | 异æ¥æ–开特定打å°æœºçš„连接之åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId: string = 'printerId_32'; print.disconnectPrinter(printerId, (err: BusinessError, data : void) => { if (err) { console.log('failed to disconnect Printer because : ' + JSON.stringify(err)); } else { console.log('start disconnect Printer success data : ' + JSON.stringify(data)); } }) ``` ## disconnectPrinter disconnectPrinter(printerId: string): Promise<void> æ–开特定打å°æœºçš„连接,使用Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerId | string | 是 | 打å°æœºID | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | æ–开特定打å°æœºçš„连接完æˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId: string = 'printerId_32'; print.disconnectPrinter(printerId).then((data : void) => { console.log('start disconnect Printer success data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('failed to disconnect Printer because : ' + JSON.stringify(error)); }) ``` ## queryPrinterCapability queryPrinterCapability(printerId: string, callback: AsyncCallback<void>): void 查询打å°æœºèƒ½åŠ›ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerId | string | 是 | 打å°æœºID | | callback | AsyncCallback<void> | 是 | 异æ¥æŸ¥è¯¢æ‰“å°æœºèƒ½åŠ›ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId: string = 'printerId_32'; print.queryPrinterCapability(printerId, (err: BusinessError, data : void) => { if (err) { console.log('failed to query Printer Capability because : ' + JSON.stringify(err)); } else { console.log('start query Printer Capability success data : ' + JSON.stringify(data)); } }) ``` ## queryPrinterCapability queryPrinterCapability(printerId: string): Promise<void> 查询打å°æœºèƒ½åŠ›ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerId | string | 是 | 打å°æœºID | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | 查询打å°æœºèƒ½åŠ›å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId: string = 'printerId_32'; print.queryPrinterCapability(printerId).then((data : void) => { console.log('start query Printer success data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('failed to query Printer Capability because : ' + JSON.stringify(error)); }) ``` ## startPrintJob startPrintJob(jobInfo: PrintJob, callback: AsyncCallback<void>): void 开始打å°ä»»åŠ¡ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobInfo | PrintJob | 是 | 打å°ä»»åŠ¡ä¿¡æ¯ | | callback | AsyncCallback<void> | 是 | 异æ¥å¼€å§‹æ‰“å°ä»»åŠ¡ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobInfo : print.PrintJob = { fdList : [0,1], jobId : 'jobId_12', printerId : 'printerId_32', jobState : 3, jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, copyNumber : 1, pageRange : {}, isSequential : false, pageSize : {id : '', name : '', width : 10, height : 20}, isLandscape : false, colorMode : 6, duplexMode : 6, margin : undefined, preview : undefined, options : undefined }; print.startPrintJob(jobInfo, (err: BusinessError, data : void) => { if (err) { console.log('failed to start Print Job because : ' + JSON.stringify(err)); } else { console.log('start Print Job success data : ' + JSON.stringify(data)); } }) ``` ## startPrintJob startPrintJob(jobInfo: PrintJob): Promise<void> 开始打å°ä»»åŠ¡ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobInfo | PrintJob | 是 | 打å°ä»»åŠ¡ä¿¡æ¯ | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | 开始打å°ä»»åŠ¡å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobInfo : print.PrintJob = { fdList : [0,1], jobId : 'jobId_12', printerId : 'printerId_32', jobState : 3, jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, copyNumber : 1, pageRange : {}, isSequential : false, pageSize : {id : '', name : '', width : 10, height : 20}, isLandscape : false, colorMode : 6, duplexMode : 6, margin : undefined, preview : undefined, options : undefined }; print.startPrintJob(jobInfo).then((data : void) => { console.log('start Print success data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('failed to start Print because : ' + JSON.stringify(error)); }) ``` ## cancelPrintJob cancelPrintJob(jobId: string, callback: AsyncCallback<void>): void å–消已å‘é€åˆ°æ‰“å°æœºçš„打å°ä»»åŠ¡ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobId | string | 是 | 打å°ä»»åŠ¡ID | | callback | AsyncCallback<void> | 是 | 异æ¥å–消已å‘é€åˆ°æ‰“å°æœºçš„打å°ä»»åŠ¡ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobId : string = '121212'; print.cancelPrintJob(jobId, (err: BusinessError, data : void) => { if (err) { console.log('cancelPrintJob failed, because : ' + JSON.stringify(err)); } else { console.log('cancelPrintJob success, data: ' + JSON.stringify(data)); } }) ``` ## cancelPrintJob cancelPrintJob(jobId: string): Promise<void> å–消已å‘é€åˆ°æ‰“å°æœºçš„打å°ä»»åŠ¡ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobId | string | 是 | 打å°ä»»åŠ¡ID | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | å–消已å‘é€åˆ°æ‰“å°æœºçš„打å°ä»»åŠ¡å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobId : string = '121212'; print.cancelPrintJob(jobId).then((data : void) => { console.log('cancelPrintJob success, data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('cancelPrintJob failed, because : ' + JSON.stringify(error)); }) ``` ## requestPrintPreview requestPrintPreview(jobInfo: PrintJob, callback: Callback<number>): void 请求预览打å°æ•°æ®ï¼Œä½¿ç”¨callback回调。 **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobInfo | PrintJob | 是 | 打å°ä»»åŠ¡ä¿¡æ¯ | | callback | Callback<number> | 是 | 请求预览打å°æ•°æ®ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; let jobInfo : print.PrintJob = { fdList : [0,1], jobId : 'jobId_12', printerId : 'printerId_32', jobState : 3, jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, copyNumber : 1, pageRange : {}, isSequential : false, pageSize : {id : '', name : '', width : 10, height : 20}, isLandscape : false, colorMode : 6, duplexMode : 6, margin : undefined, preview : undefined, options : undefined }; print.requestPrintPreview(jobInfo, (num : number) => { console.log('requestPrintPreview success, num : ' + JSON.stringify(num)); }) ``` ## requestPrintPreview requestPrintPreview(jobInfo: PrintJob): Promise<number> 请求预览打å°æ•°æ®ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobInfo | PrintJob | 是 | 打å°ä»»åŠ¡ä¿¡æ¯ | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<number> | 请求预览打å°æ•°æ®å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobInfo : print.PrintJob = { fdList : [0,1], jobId : 'jobId_12', printerId : 'printerId_32', jobState : 3, jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS, copyNumber : 1, pageRange : {}, isSequential : false, pageSize : {id : '', name : '', width : 10, height : 20}, isLandscape : false, colorMode : 6, duplexMode : 6, margin : undefined, preview : undefined, options : undefined }; print.requestPrintPreview(jobInfo).then((num: number) => { console.log('requestPrintPreview success, num : ' + JSON.stringify(num)); }).catch((error: BusinessError) => { console.log('requestPrintPreview failed, because : ' + JSON.stringify(error)); }) ``` ## on on(type: 'printerStateChange', callback: (state: PrinterState, info: PrinterInfo) => void): void 注册打å°æœºçŠ¶æ€å˜åŒ–事件回调,使用callback回调。 **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | type | 'printerStateChange' | 是 | 表示打å°æœºçŠ¶æ€æ”¹å˜ | | callback | (state: PrinterState, info: PrinterInfo) => void | 是 | 打å°æœºçŠ¶æ€æ”¹å˜ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; print.on('printerStateChange', (state: print.PrinterState, info: print.PrinterInfo) => { if (state === null || info === null) { console.log('printer state changed state is null or info is null'); return; } else { console.log('on printer state changed, state : ' + JSON.stringify(state)); console.log('on printer state changed, info : ' + JSON.stringify(info)); } }) ``` ## off off(type: 'printerStateChange', callback?: Callback<boolean>): void å–消注册打å°æœºçŠ¶æ€å˜åŒ–事件回调,使用callback回调。 **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | type | 'printerStateChange' | 是 | 表示打å°æœºçŠ¶æ€æ”¹å˜ | | callback | Callback<boolean> | å¦ | 打å°æœºçŠ¶æ€æ”¹å˜ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; print.off('printerStateChange', (data: boolean) => { console.log('off printerStateChange data : ' + JSON.stringify(data)); }) ``` ## on on(type: 'jobStateChange', callback: (state: PrintJobState, job: PrintJob) => void): void 注册打å°ä»»åŠ¡çŠ¶æ€å˜åŒ–事件回调,使用callback回调。 **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | type | 'jobStateChange' | 是 | 表示打å°ä»»åŠ¡çŠ¶æ€æ”¹å˜ | | callback | (state: PrintJobState, job: PrintJob) => void | 是 | 打å°ä»»åŠ¡çŠ¶æ€æ”¹å˜ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; print.on('jobStateChange', (state: print.PrintJobState, job: print.PrintJob) => { console.log('onJobStateChange, state : ' + JSON.stringify(state) + ', job : ' + JSON.stringify(job)); }) ``` ## off off(type: 'jobStateChange', callback?: Callback<boolean>): void å–消注册打å°ä»»åŠ¡çŠ¶æ€å˜åŒ–事件回调,使用callback回调。 **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | type | 'jobStateChange' | 是 | 表示打å°ä»»åŠ¡çŠ¶æ€æ”¹å˜ | | callback | Callback<boolean> | å¦ | 打å°ä»»åŠ¡çŠ¶æ€æ”¹å˜ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; print.off('jobStateChange', (data: boolean) => { console.log('offJobStateChanged data : ' + JSON.stringify(data)); }) ``` ## on on(type: 'extInfoChange', callback: (extensionId: string, info: string) => void): void 注册打å°æ‰©å±•ä¿¡æ¯å˜åŒ–事件回调,使用callback回调。 **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | type | 'extInfoChange' | 是 | 表示打å°æ‰©å±•ä¿¡æ¯æ”¹å˜ | | callback | (extensionId: string, info: string) => void | 是 | 打å°æ‰©å±•ä¿¡æ¯æ”¹å˜ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; print.on('extInfoChange', (extensionId: string, info: string) => { console.log('onExtInfoChange, entensionId : ' + JSON.stringify(extensionId) + ', info : ' + JSON.stringify(info)); }) ``` ## off off(type: 'extInfoChange', callback?: Callback<boolean>): void å–消注册打å°æ‰©å±•ä¿¡æ¯å˜åŒ–事件回调,使用callback回调。 **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | type | 'extInfoChange' | 是 | 表示打å°æ‰©å±•ä¿¡æ¯æ”¹å˜ | | callback | Callback<boolean> | å¦ | 打å°ä»»åŠ¡æ‰©å±•ä¿¡æ¯æ”¹å˜ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; print.off('extInfoChange', (data: boolean) => { console.log('offExtInfoChange data : ' + JSON.stringify(data)); }) ``` ## addPrinters addPrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void æ·»åŠ æ‰“å°æœºï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printers | Array<PrinterInfo> | 是 | 表示新到达的打å°æœºåˆ—表 | | callback | AsyncCallback<void> | 是 | 异æ¥æ·»åŠ 打å°æœºä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerInfo : print.PrinterInfo = { printerId : '3232', printerName : 'hhhhh', printerState : 0, printerIcon : 12, description : 'str', capability : undefined, options : 'opt' }; print.addPrinters([printerInfo], (err: BusinessError, data : void) => { if (err) { console.log('addPrinters failed, because : ' + JSON.stringify(err)); } else { console.log('addPrinters success, data : ' + JSON.stringify(data)); } }) ``` ## addPrinters addPrinters(printers: Array<PrinterInfo>): Promise<void> æ·»åŠ æ‰“å°æœºï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printers | Array<PrinterInfo> | 是 | 表示新到达的打å°æœºåˆ—表 | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | æ·»åŠ æ‰“å°æœºå®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerInfo : print.PrinterInfo = { printerId : '3232', printerName : 'hhhhh', printerState : 0, printerIcon : 12, description : 'str', capability : undefined, options : 'opt' }; print.addPrinters([printerInfo]).then((data : void) => { console.log('add printers data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('add printers error : ' + JSON.stringify(error)); }) ``` ## removePrinters removePrinters(printerIds: Array<string>, callback: AsyncCallback<void>): void 移除打å°æœºï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerIds | Array<string> | 是 | 表示需移除的打å°æœºåˆ—表 | | callback | AsyncCallback<void> | 是 | 异æ¥ç§»é™¤æ‰“å°æœºä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId : string = '1212'; print.removePrinters([printerId], (err: BusinessError, data : void) => { if (err) { console.log('removePrinters failed, because : ' + JSON.stringify(err)); } else { console.log('removePrinters success, data : ' + JSON.stringify(data)); } }) ``` ## removePrinters removePrinters(printerIds: Array<string>): Promise<void> 移除打å°æœºï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerIds | Array<string> | 是 | 表示需移除的打å°æœºåˆ—表 | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | 移除打å°æœºå®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId : string = '1212'; print.removePrinters([printerId]).then((data : void) => { console.log('remove printers data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('remove printers error : ' + JSON.stringify(error)); }) ``` ## updatePrinters updatePrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void 更新特定打å°æœºçš„ä¿¡æ¯ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printers | Array<PrinterInfo> | 是 | 表示待更新的打å°æœºåˆ—表 | | callback | AsyncCallback<void> | 是 | 异æ¥æ›´æ–°æ‰“å°æœºä¿¡æ¯ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerInfo : print.PrinterInfo = { printerId : '3232', printerName : 'hhhhh', printerState : 0, printerIcon : 12, description : 'str', capability : undefined, options : 'opt' }; print.updatePrinters([printerInfo], (err: BusinessError, data : void) => { if (err) { console.log('updataPrinters failed, because : ' + JSON.stringify(err)); } else { console.log('updataPrinters success, data : ' + JSON.stringify(data)); } }) ``` ## updatePrinters updatePrinters(printers: Array<PrinterInfo>): Promise<void> 更新特定打å°æœºçš„ä¿¡æ¯ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printers | Array<PrinterInfo> | 是 | 表示待更新的打å°æœºåˆ—表 | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | 更新打å°æœºå®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerInfo : print.PrinterInfo = { printerId : '3232', printerName : 'hhhhh', printerState : 0, printerIcon : 12, description : 'str', capability : undefined, options : 'opt' }; print.updatePrinters([printerInfo]).then((data : void) => { console.log('update printers data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('update printers error : ' + JSON.stringify(error)); }) ``` ## updatePrinterState updatePrinterState(printerId: string, state: PrinterState, callback: AsyncCallback<void>): void 更新打å°æœºçŠ¶æ€ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerId | string | 是 | 表示打å°æœºID | | state | PrinterState | 是 | 表示打å°æœºçŠ¶æ€ | | callback | AsyncCallback<void> | 是 | 异æ¥æ›´æ–°æ‰“å°æœºçŠ¶æ€ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId : string = '1212'; let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED; print.updatePrinterState(printerId, state, (err: BusinessError, data : void) => { if (err) { console.log('updataPrinterState failed, because : ' + JSON.stringify(err)); } else { console.log('updataPrinterState success, data : ' + JSON.stringify(data)); } }) ``` ## updatePrinterState updatePrinterState(printerId: string, state: PrinterState): Promise<void> 更新打å°æœºçŠ¶æ€ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerId | string | 是 | 表示打å°æœºID | | state | PrinterState | 是 | 表示打å°æœºçŠ¶æ€ | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | 更新打å°æœºçŠ¶æ€å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId : string = '1212'; let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED; print.updatePrinterState(printerId, state).then((data : void) => { console.log('update printer state data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('update printer state error : ' + JSON.stringify(error)); }) ``` ## updatePrintJobState updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState, callback: AsyncCallback<void>): void 更新打å°ä»»åŠ¡çŠ¶æ€ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobId | string | 是 | 表示打å°ä»»åŠ¡ID | | state | PrintJobState | 是 | 表示打å°ä»»åŠ¡çŠ¶æ€ | | subState | PrintJobSubState | 是 | 表示打å°ä»»åŠ¡åçŠ¶æ€ | | callback | AsyncCallback<void> | 是 | 异æ¥æ›´æ–°æ‰“å°ä»»åŠ¡çŠ¶æ€ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobId : string = '3434'; let state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE; let subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS; print.updatePrintJobState(jobId, state, subState, (err: BusinessError, data : void) => { if (err) { console.log('updataPrintJobState failed, because : ' + JSON.stringify(err)); } else { console.log('updatePrintJobState success, data : ' + JSON.stringify(data)); } }) ``` ## updatePrintJobState updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState): Promise<void> 更新打å°ä»»åŠ¡çŠ¶æ€ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobId | string | 是 | 表示打å°ä»»åŠ¡ID | | state | PrintJobState | 是 | 表示打å°ä»»åŠ¡çŠ¶æ€ | | subState | PrintJobSubState | 是 | 表示打å°ä»»åŠ¡åçŠ¶æ€ | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | 更新打å°ä»»åŠ¡çŠ¶æ€å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobId : string = '3434'; let state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE; let subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS; print.updatePrintJobState(jobId, state, subState).then((data : void) => { console.log('update print job state data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('update print job state error : ' + JSON.stringify(error)); }) ``` ## updateExtensionInfo updateExtensionInfo(info: string, callback: AsyncCallback<void>): void 更新打å°æ‰©å±•çŠ¶æ€ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | info | string | 是 | 表示打å°æ‰©å±•å˜æ›´ä¿¡æ¯ | | callback | AsyncCallback<void> | 是 | 异æ¥æ›´æ–°æ‰“å°æ‰©å±•çŠ¶æ€ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let info : string = 'WIFI_INACTIVE'; print.updateExtensionInfo(info, (err: BusinessError, data : void) => { if (err) { console.log('updateExtensionInfo failed, because : ' + JSON.stringify(err)); } else { console.log('updateExtensionInfo success, data : ' + JSON.stringify(data)); } }) ``` ## updateExtensionInfo updateExtensionInfo(info: string): Promise<void> 更新打å°æ‰©å±•çŠ¶æ€ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | info | string | 是 | 表示打å°æ‰©å±•å˜æ›´ä¿¡æ¯ | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | 更新打å°æ‰©å±•çŠ¶æ€å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let info : string = 'WIFI_INACTIVE'; print.updateExtensionInfo(info).then((data : void) => { console.log('update print job state data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('update print job state error : ' + JSON.stringify(error)); }) ``` ## queryAllPrintJobs<sup>(deprecated)</sup> > 从API version 10开始支æŒï¼Œä»ŽAPI version 11开始废弃。 > 建议使用[queryPrintJobList](#queryprintjoblist11)替代。 queryAllPrintJobs(callback: AsyncCallback<void>): void 查询所有打å°ä»»åŠ¡ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<void> | 是 | 异æ¥æŸ¥è¯¢æ‰€æœ‰æ‰“å°ä»»åŠ¡ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; print.queryAllPrintJobs((err: BusinessError, data : void) => { if (err) { console.log('queryAllPrintJobs failed, because : ' + JSON.stringify(err)); } else { console.log('queryAllPrintJobs success, data : ' + JSON.stringify(data)); } }) ``` ## queryAllPrintJobs<sup>(deprecated)</sup> > 从API version 10开始支æŒï¼Œä»ŽAPI version 11开始废弃。 > 建议使用[queryPrintJobList](#queryprintjoblist11-1)替代。 queryAllPrintJobs(): Promise<void> 查询所有打å°ä»»åŠ¡ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | 查询所有打å°ä»»åŠ¡å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; print.queryAllPrintJobs().then((data : void) => { console.log('queryAllPrintJobs success, data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('queryAllPrintJobs failed, error : ' + JSON.stringify(error)); }) ``` ## queryPrintJobList<sup>11+</sup> queryPrintJobList(callback: AsyncCallback<Array<PrintJob>>): void 查询所有打å°ä»»åŠ¡ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | callback | AsyncCallback<Array<PrintJob>> | 是 | 异æ¥æŸ¥è¯¢æ‰€æœ‰æ‰“å°ä»»åŠ¡ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; print.queryPrintJobList((err: BusinessError, printJobs : print.PrintJob[]) => { if (err) { console.log('queryPrintJobList failed, because : ' + JSON.stringify(err)); } else { console.log('queryPrintJobList success, data : ' + JSON.stringify(printJobs)); } }) ``` ## queryPrintJobList<sup>11+</sup> queryPrintJobList(): Promise<Array<PrintJob>> 查询所有打å°ä»»åŠ¡ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<Array<PrintJob>> | 查询所有打å°ä»»åŠ¡å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; print.queryPrintJobList().then((printJobs : print.PrintJob[]) => { console.log('queryPrintJobList success, data : ' + JSON.stringify(printJobs)); }).catch((error: BusinessError) => { console.log('queryPrintJobList failed, error : ' + JSON.stringify(error)); }) ``` ## queryPrintJobById<sup>11+</sup> queryPrintJobById(jobId: string, callback: AsyncCallback<PrintJob>): void 按打å°ä»»åŠ¡ID查询打å°ä»»åŠ¡ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobId | string | 是 | 表示打å°ä»»åŠ¡ID | | callback | AsyncCallback<PrintJob> | 是 | 异æ¥æŒ‰æ‰“å°ä»»åŠ¡ID查询打å°ä»»åŠ¡ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobId : string = '1'; print.queryPrintJobById(jobId, (err: BusinessError, printJob : print.PrintJob) => { if (err) { console.log('queryPrintJobById failed, because : ' + JSON.stringify(err)); } else { console.log('queryPrintJobById success, data : ' + JSON.stringify(printJob)); } }) ``` ## queryPrintJobById<sup>11+</sup> queryPrintJobById(jobId: string): Promise<PrintJob> 按打å°ä»»åŠ¡ID查询打å°ä»»åŠ¡ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobId | string | 是 | 表示打å°ä»»åŠ¡ID | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<PrintJob> | 按打å°ä»»åŠ¡ID查询打å°ä»»åŠ¡å®Œæˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobId : string = '1'; print.queryPrintJobById(jobId).then((printJob : print.PrintJob) => { console.log('queryPrintJobById data : ' + JSON.stringify(printJob)); }).catch((error: BusinessError) => { console.log('queryPrintJobById error : ' + JSON.stringify(error)); }) ``` ## startGettingPrintFile<sup>11+</sup> startGettingPrintFile(jobId: string, printAttributes: PrintAttributes, fd: number, onFileStateChanged: Callback<PrintFileCreationState>): void 开始获å–打å°æ–‡ä»¶ï¼Œä½¿ç”¨Callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobId | string | 是 | 表示打å°ä»»åŠ¡ID | | printAttributes | PrintAttributes | 是 | 表示打å°å‚æ•° | | fd | number | 是 | 表示打å°æ–‡ä»¶æ述符 | | onFileStateChanged | Callback<PrintFileCreationState> | 是 | 表示更新文件状æ€çš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobId : string= '1'; class MyPrintAttributes implements print.PrintAttributes { copyNumber?: number; pageRange?: print.PrintPageRange; pageSize?: print.PrintPageSize | print.PrintPageType; directionMode?: print.PrintDirectionMode; colorMode?: print.PrintColorMode; duplexMode?: print.PrintDuplexMode; } class MyPrintPageRange implements print.PrintPageRange { startPage?: number; endPage?: number; pages?: Array<number>; } class MyPrintPageSize implements print.PrintPageSize { id: string = '0'; name: string = '0'; width: number = 210; height: number = 297; } let printAttributes = new MyPrintAttributes(); printAttributes.copyNumber = 2; printAttributes.pageRange = new MyPrintPageRange(); printAttributes.pageRange.startPage = 0; printAttributes.pageRange.endPage = 5; printAttributes.pageRange.pages = [1, 3]; printAttributes.pageSize = print.PrintPageType.PAGE_ISO_A3; printAttributes.directionMode = print.PrintDirectionMode.DIRECTION_MODE_AUTO; printAttributes.colorMode = print.PrintColorMode.COLOR_MODE_MONOCHROME; printAttributes.duplexMode = print.PrintDuplexMode.DUPLEX_MODE_NONE; let fd : number = 1; print.startGettingPrintFile(jobId, printAttributes, fd, (state: print.PrintFileCreationState) => { console.log('onFileStateChanged success, data : ' + JSON.stringify(state)); }) ``` ## notifyPrintService<sup>11+</sup> notifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started', callback: AsyncCallback<void>): void å°†spoolerå…³é—ä¿¡æ¯é€šçŸ¥æ‰“å°æœåŠ¡ï¼Œä½¿ç”¨callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobId | string | 是 | 表示打å°ä»»åŠ¡ID | | type | 'spooler_closed_for_cancelled' \| 'spooler_closed_for_started' | 是 | 表示spoolerå…³é—ä¿¡æ¯ | | callback | AsyncCallback<void> | 是 | 异æ¥å°†spoolerå…³é—ä¿¡æ¯é€šçŸ¥æ‰“å°æœåŠ¡ä¹‹åŽçš„回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobId : string = '1'; print.notifyPrintService(jobId, 'spooler_closed_for_started', (err: BusinessError, data : void) => { if (err) { console.log('notifyPrintService failed, because : ' + JSON.stringify(err)); } else { console.log('notifyPrintService success, data : ' + JSON.stringify(data)); } }) ``` ## notifyPrintService<sup>11+</sup> notifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started'): Promise<void> å°†spoolerå…³é—ä¿¡æ¯é€šçŸ¥æ‰“å°æœåŠ¡ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | jobId | string | 是 | 表示打å°ä»»åŠ¡ID | | type | 'spooler_closed_for_cancelled' \| 'spooler_closed_for_started' | 是 | 表示spoolerå…³é—ä¿¡æ¯ | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | å°†spoolerå…³é—ä¿¡æ¯é€šçŸ¥æ‰“å°æœåŠ¡åŽçš„完æˆç»“æžœ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let jobId : string = '1'; print.notifyPrintService(jobId, 'spooler_closed_for_started').then((data : void) => { console.log('notifyPrintService data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('notifyPrintService error : ' + JSON.stringify(error)); }) ``` ## getAddedPrinters<sup>12+</sup> getAddedPrinters(): Promise<Array<string>> 获å–cupså·²æ·»åŠ æ‰“å°æœºåˆ—表,使用Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<Array<string>> | 获å–cupså·²æ·»åŠ æ‰“å°æœºåˆ—表的完æˆç»“果回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; print.getAddedPrinters().then((printers: string[]) => { console.log('getAddedPrinters success ' + JSON.stringify(printers)); // ... }).catch((error: BusinessError) => { console.log('failed to getAddedPrinters bacause ' + JSON.stringify(error)); }) ``` ## getPrinterInfoById<sup>12+</sup> getPrinterInfoById(printerId: string): Promise<PrinterInfo> æ ¹æ®æ‰“å°æœºid获å–打å°æœºä¿¡æ¯ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | printerId | string | 是 | 表示打å°æœºID | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<PrinterInfo> | æ ¹æ®æ‰“å°æœºid获å–打å°æœºä¿¡æ¯åŽçš„完æˆç»“果回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let printerId : string = '1'; print.getPrinterInfoById(printerId).then((printerInfo : print.PrinterInfo) => { console.log('getPrinterInfoById data : ' + JSON.stringify(printerInfo)); }).catch((error: BusinessError) => { console.log('getPrinterInfoById error : ' + JSON.stringify(error)); }) ``` ## notifyPrintServiceEvent<sup>12+</sup> notifyPrintServiceEvent(event: ApplicationEvent): Promise<void> 将打å°åº”用相关事件通知打å°æœåŠ¡ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.MANAGE_PRINT_JOB **系统接å£ï¼š** æ¤æŽ¥å£ä¸ºç³»ç»ŸæŽ¥å£ã€‚ **系统能力:** SystemCapability.Print.PrintFramework **å‚数:** | **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | | -------- | -------- | -------- | -------- | | event | ApplicationEvent | 是 | 表示打å°åº”用事件 | **返回值:** | **类型** | **说明** | | -------- | -------- | | Promise<void> | 将打å°åº”用相关事件通知打å°æœåŠ¡åŽçš„完æˆç»“果回调 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[打å°æœåŠ¡é”™è¯¯ç ](./errorcode-print.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | -------- | ------------------------------------------- | | 201 | the application does not have permission to call this function. | | 202 | not system application | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | **示例:** ```ts import { print } from '@kit.BasicServicesKit'; import { BusinessError } from '@ohos.base'; let event : print.ApplicationEvent = print.ApplicationEvent.APPLICATION_CREATED; print.notifyPrintServiceEvent(event).then((data : void) => { console.log('notifyPrintServiceEvent data : ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.log('notifyPrintServiceEvent error : ' + JSON.stringify(error)); }) ```