diff --git a/zh-cn/application-dev/reference/apis/Readme-CN.md b/zh-cn/application-dev/reference/apis/Readme-CN.md index 5a86f59cdb110ea405b452bc4e86016a265d5472..aa32d56b3a634a11391f17451996dce8970d54b7 100644 --- a/zh-cn/application-dev/reference/apis/Readme-CN.md +++ b/zh-cn/application-dev/reference/apis/Readme-CN.md @@ -380,6 +380,7 @@ - [@ohos.InputMethodSubtype (输入法å类型)](js-apis-inputmethod-subtype.md) - [@ohos.logLibrary (维测日志获å–)](js-apis-loglibrary.md) - [@ohos.pasteboard (剪贴æ¿)](js-apis-pasteboard.md) + - [@ohos.print (打å°)](js-apis-print.md) - [@ohos.screenLock (é”å±ç®¡ç†)](js-apis-screen-lock.md) - [@ohos.systemDateTime (系统时间ã€æ—¶åŒº)](js-apis-system-date-time.md) - [@ohos.systemTimer (系统定时器)](js-apis-system-timer.md) diff --git a/zh-cn/application-dev/reference/apis/js-apis-print.md b/zh-cn/application-dev/reference/apis/js-apis-print.md new file mode 100644 index 0000000000000000000000000000000000000000..7677855f8bd9a694a3ade36d7c8198294050e63e --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-print.md @@ -0,0 +1,189 @@ +# @ohos.print (打å°) + +该模å—为基本打å°çš„æ“作API,æ供调用基础打å°åŠŸèƒ½çš„接å£ã€‚ + +> **说明:** +> 本模å—首批接å£ä»ŽAPI version 10开始支æŒã€‚åŽç»ç‰ˆæœ¬çš„新增接å£ï¼Œé‡‡ç”¨ä¸Šè§’æ ‡å•ç‹¬æ ‡è®°æŽ¥å£çš„起始版本。 + +## å¯¼å…¥æ¨¡å— + +```js +import print from '@ohos.print'; +``` + +## PrintTask + +打å°ä»»åŠ¡å®ŒæˆåŽçš„事件监å¬å›žè°ƒæŽ¥å£ç±» + +### on + +on(type: 'block' | 'succeed' | 'fail' | 'cancel', callback: Callback<void>): void + +注册打å°å®ŒæˆåŽçš„监å¬ï¼Œä½¿ç”¨callback回调。 + +**需è¦æƒé™ï¼š** ohos.permission.PRINT + +**系统能力:** SystemCapability.Print.PrintFramework + +**å‚数:** +| **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | +| -------- | -------- | -------- | -------- | +| type | string | 是 | 注册监å¬ï¼Œ<br/>å¯é€‰ç›‘å¬å—段:block/succeed/fail/cancel <br/>ä¾æ¬¡è¡¨ç¤ºæ‰“å°ï¼šé˜»å¡ž/æˆåŠŸ/失败/å–消 | +| callback| Callback<void> | 是 | 打å°å®ŒæˆåŽå¤„于相应状æ€çš„回调 | + +**返回值:** + + | **类型** | **说明** | + | -------- | -------- | + | Promise<PrintTask> | 打å°å®Œæˆç»“æžœ | + +**示例:** + +```js +import print from '@ohos.print'; +let file = ['file://data/print/a.png', 'file://data/print/b.png']; +print.print(file).then((printTask) => { + printTask.on('succeed', () => { + console.log('print state is succeed') + }) + printTask.on('block', () => { + console.log('print state is block') + }) + printTask.on('succeed', () => { + console.log('print state is succeed') + }) + printTask.on('fail', () => { + console.log('print state is fail') + }) + printTask.on('cancel', () => { + console.log('print state is cancel') + }) + // ... +}).catch((error) => { + console.log('print err') +}) +``` + +### off + +off(type: 'block' | 'succeed' | 'fail' | 'cancel', callback?: Callback<void>): void + +å–消打å°å®ŒæˆåŽçš„监å¬ï¼Œä½¿ç”¨callback回调。 + +**需è¦æƒé™ï¼š** ohos.permission.PRINT + +**系统能力:** SystemCapability.Print.PrintFramework + +**å‚数:** +| **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | +| -------- | -------- | -------- | -------- | +| type | string | 是 | å–消监å¬ï¼Œ<br/>å¯é€‰ç›‘å¬å—段:block/succeed/fail/cancel <br/>ä¾æ¬¡è¡¨ç¤ºæ‰“å°ï¼šé˜»å¡ž/æˆåŠŸ/失败/å–消 | +| callback| Callback<void> | å¦ | å–消相应状æ€ç›‘å¬æˆåŠŸåŽçš„回调 | + +**返回值:** + + | **类型** | **说明** | + | -------- | -------- | + | Promise<PrintTask> | 打å°å®Œæˆç»“æžœ | + +**示例:** + +```js +import print from '@ohos.print'; +let file = ['file://data/print/a.png', 'file://data/print/b.png']; +print.print(file).then((printTask) => { + printTask.off('succeed', () => { + console.log('unregister state succeed') + }) + printTask.off('block', () => { + console.log('unregister state block') + }) + printTask.off('succeed', () => { + console.log('unregister state succeed') + }) + printTask.off('fail', () => { + console.log('unregister state fail') + }) + printTask.off('cancel', () => { + console.log('unregister state cancel') + }) + // ... +}).catch((error) => { + console.log('print err') +}) +``` + +## print + +print(files: Array<string>, callback: AsyncCallback<PrintTask>): void + +打å°æŽ¥å£ï¼Œä¼ 入文件进行打å°ï¼Œä½¿ç”¨callbak异æ¥å›žè°ƒã€‚ + +**需è¦æƒé™ï¼š** ohos.permission.PRINT + +**系统能力:** SystemCapability.Print.PrintFramework + +**å‚数:** +| **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | +| -------- | -------- | -------- | -------- | +| file | Array<string> | 是 | 待打å°æ–‡ä»¶åˆ—表,仅支æŒå›¾ç‰‡å’Œpdf | +| callback| AsyncCallback<PrintTask> | 是 | 异æ¥èŽ·å–打å°å®Œæˆä¹‹åŽçš„回调 | + +**示例:** + +```js +import print from '@ohos.print'; +//ä¼ å…¥æ–‡ä»¶çš„uri +let file = ['file://data/print/a.png', 'file://data/print/b.png']; +// æˆ–è€…ä¼ å…¥fd +// let file = ['fd://1', 'fd://2']; +print.print(file, (err, printTask: print.PrintTask) => { + if (err) { + console.log('print err') + } else { + printTask.on('succeed', () => { + console.log('print state is succeed') + }) + // ... + } +}) +``` + +## print + +print(files: Array<string>): Promise<PrintTask> + +打å°æŽ¥å£ï¼Œä¼ 入文件进行打å°ï¼Œä½¿ç”¨Promise异æ¥å›žè°ƒã€‚ + +**需è¦æƒé™ï¼š** ohos.permission.PRINT + +**系统能力:** SystemCapability.Print.PrintFramework + +**å‚数:** +| **å‚æ•°å** | **类型** | **å¿…å¡«** | **说明** | +| -------- | -------- | -------- | -------- | +| file | Array<string> | 是 | 待打å°æ–‡ä»¶åˆ—表,仅支æŒå›¾ç‰‡å’Œpdf | + +**返回值:** + + | **类型** | **说明** | + | -------- | -------- | + | Promise<PrintTask> | 打å°å®Œæˆç»“æžœ | + +**示例:** + +```js +import print from '@ohos.print'; +//ä¼ å…¥æ–‡ä»¶çš„uri +let file = ['file://data/print/a.png', 'file://data/print/b.png']; +// æˆ–è€…ä¼ å…¥fd +// let file = ['fd://1', 'fd://2']; +print.print(file).then((printTask) => { + printTask.on('succeed', () => { + console.log('print state is succeed') + }) + // ... +}).catch((error) => { + console.log('print err') +}) +``` \ No newline at end of file