• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.print (打印)
2
3该模块为基本打印的操作API,提供调用基础打印功能的接口。
4
5> **说明:**
6> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
7
8## 导入模块
9
10```ts
11import { print } from '@kit.BasicServicesKit';
12```
13
14## PrintTask
15
16打印任务完成后的事件监听回调接口类。
17
18### PrintTask.on
19
20on(type: 'block', callback: Callback<void>): void
21
22注册打印完成后的监听,使用callback回调。
23
24**需要权限:** ohos.permission.PRINT
25
26**系统能力:** SystemCapability.Print.PrintFramework
27
28**参数:**
29| **参数名** | **类型** | **必填** | **说明** |
30| -------- | -------- | -------- | -------- |
31| type | string | 是 | 注册监听,<br/>监听字段:block,<br/>表示打印阻塞。 |
32| callback | Callback&lt;void&gt; | 是 | 打印完成后处于响应状态的回调。 |
33
34**错误码:**
35
36以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
37
38| 错误码ID | 错误信息                                    |
39| -------- | ------------------------------------------- |
40| 201 | the application does not have permission to call this function. |
41| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
42
43**示例:**
44
45```ts
46import { print } from '@kit.BasicServicesKit';
47import { BusinessError } from '@ohos.base';
48import { fileUri } from '@kit.CoreFileKit';
49
50let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
51print.print([fileUri.getUriFromPath(filePath)]).then((printTask: print.PrintTask) => {
52    printTask.on('block', () => {
53        console.log('print state is block');
54    })
55    // ...
56}).catch((error: BusinessError) => {
57    console.log('print err ' + JSON.stringify(error));
58})
59```
60
61### PrintTask.on
62
63on(type: 'succeed', callback: Callback&lt;void&gt;): void
64
65注册打印完成后的监听,使用callback回调。
66
67**需要权限:** ohos.permission.PRINT
68
69**系统能力:** SystemCapability.Print.PrintFramework
70
71**参数:**
72| **参数名** | **类型** | **必填** | **说明** |
73| -------- | -------- | -------- | -------- |
74| type | string | 是 | 注册监听,<br/>监听字段:succeed,<br/>表示打印成功。 |
75| callback | Callback&lt;void&gt; | 是 | 打印完成后处于响应状态的回调。 |
76
77**错误码:**
78
79以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
80
81| 错误码ID | 错误信息                                    |
82| -------- | ------------------------------------------- |
83| 201 | the application does not have permission to call this function. |
84| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
85
86**示例:**
87
88```ts
89import { print } from '@kit.BasicServicesKit';
90import { BusinessError } from '@ohos.base';
91import { fileUri } from '@kit.CoreFileKit';
92
93let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
94print.print([fileUri.getUriFromPath(filePath)]).then((printTask: print.PrintTask) => {
95    printTask.on('succeed', () => {
96        console.log('print state is succeed');
97    })
98    // ...
99}).catch((error: BusinessError) => {
100    console.log('print err ' + JSON.stringify(error));
101})
102```
103
104### PrintTask.on
105
106on(type: 'fail', callback: Callback&lt;void&gt;): void
107
108注册打印完成后的监听,使用callback回调。
109
110**需要权限:** ohos.permission.PRINT
111
112**系统能力:** SystemCapability.Print.PrintFramework
113
114**参数:**
115| **参数名** | **类型** | **必填** | **说明** |
116| -------- | -------- | -------- | -------- |
117| type | string | 是 | 注册监听,<br/>监听字段:fail,<br/>表示打印失败。 |
118| callback | Callback&lt;void&gt; | 是 | 打印完成后处于响应状态的回调。 |
119
120**错误码:**
121
122以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
123
124| 错误码ID | 错误信息                                    |
125| -------- | ------------------------------------------- |
126| 201 | the application does not have permission to call this function. |
127| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
128
129**示例:**
130
131```ts
132import { print } from '@kit.BasicServicesKit';
133import { BusinessError } from '@ohos.base';
134import { fileUri } from '@kit.CoreFileKit';
135
136let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
137print.print([fileUri.getUriFromPath(filePath)]).then((printTask: print.PrintTask) => {
138    printTask.on('fail', () => {
139        console.log('print state is fail');
140    })
141    // ...
142}).catch((error: BusinessError) => {
143    console.log('print err ' + JSON.stringify(error));
144})
145```
146
147### PrintTask.on
148
149on(type: 'cancel', callback: Callback&lt;void&gt;): void
150
151注册打印完成后的监听,使用callback回调。
152
153**需要权限:** ohos.permission.PRINT
154
155**系统能力:** SystemCapability.Print.PrintFramework
156
157**参数:**
158| **参数名** | **类型** | **必填** | **说明** |
159| -------- | -------- | -------- | -------- |
160| type | string | 是 | 注册监听,<br/>监听字段:cancel,<br/>表示打印取消。 |
161| callback | Callback&lt;void&gt; | 是 | 打印完成后处于响应状态的回调。 |
162
163**错误码:**
164
165以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
166
167| 错误码ID | 错误信息                                    |
168| -------- | ------------------------------------------- |
169| 201 | the application does not have permission to call this function. |
170| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
171
172**示例:**
173
174```ts
175import { print } from '@kit.BasicServicesKit';
176import { BusinessError } from '@ohos.base';
177import { fileUri } from '@kit.CoreFileKit';
178
179let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
180print.print([fileUri.getUriFromPath(filePath)]).then((printTask: print.PrintTask) => {
181    printTask.on('cancel', () => {
182        console.log('print state is cancel');
183    })
184    // ...
185}).catch((error: BusinessError) => {
186    console.log('print err ' + JSON.stringify(error));
187})
188```
189
190### PrintTask.off
191
192off(type: 'block', callback?: Callback&lt;void&gt;): void
193
194取消打印完成后的监听,使用callback回调。
195
196**需要权限:** ohos.permission.PRINT
197
198**系统能力:** SystemCapability.Print.PrintFramework
199
200**参数:**
201| **参数名** | **类型** | **必填** | **说明** |
202| -------- | -------- | -------- | -------- |
203| type | string | 是 | 取消监听,<br/>监听字段:block,<br/>表示打印阻塞。 |
204| callback | Callback&lt;void&gt; | 否 | 取消相应状态监听成功后的回调。 |
205
206**错误码:**
207
208以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
209
210| 错误码ID | 错误信息                                    |
211| -------- | ------------------------------------------- |
212| 201 | the application does not have permission to call this function. |
213| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
214
215**示例:**
216
217```ts
218import { print } from '@kit.BasicServicesKit';
219import { BusinessError } from '@ohos.base';
220import { fileUri } from '@kit.CoreFileKit';
221
222let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
223print.print([fileUri.getUriFromPath(filePath)]).then((printTask: print.PrintTask) => {
224    printTask.off('block', () => {
225        console.log('unregister state block');
226    })
227    // ...
228}).catch((error: BusinessError) => {
229    console.log('print err ' + JSON.stringify(error));
230})
231```
232
233### PrintTask.off
234
235off(type: 'succeed', callback?: Callback&lt;void&gt;): void
236
237取消打印完成后的监听,使用callback回调。
238
239**需要权限:** ohos.permission.PRINT
240
241**系统能力:** SystemCapability.Print.PrintFramework
242
243**参数:**
244| **参数名** | **类型** | **必填** | **说明** |
245| -------- | -------- | -------- | -------- |
246| type | string | 是 | 取消监听,<br/>监听字段:succeed,<br/>表示打印成功。 |
247| callback | Callback&lt;void&gt; | 否 | 取消相应状态监听成功后的回调。 |
248
249**错误码:**
250
251以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
252
253| 错误码ID | 错误信息                                    |
254| -------- | ------------------------------------------- |
255| 201 | the application does not have permission to call this function. |
256| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
257
258**示例:**
259
260```ts
261import { print } from '@kit.BasicServicesKit';
262import { BusinessError } from '@ohos.base';
263import { fileUri } from '@kit.CoreFileKit';
264
265let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
266print.print([fileUri.getUriFromPath(filePath)]).then((printTask: print.PrintTask) => {
267    printTask.off('succeed', () => {
268        console.log('unregister state succeed');
269    })
270    // ...
271}).catch((error: BusinessError) => {
272    console.log('print err ' + JSON.stringify(error));
273})
274```
275
276### PrintTask.off
277
278off(type: 'fail', callback?: Callback&lt;void&gt;): void
279
280取消打印完成后的监听,使用callback回调。
281
282**需要权限:** ohos.permission.PRINT
283
284**系统能力:** SystemCapability.Print.PrintFramework
285
286**参数:**
287| **参数名** | **类型** | **必填** | **说明** |
288| -------- | -------- | -------- | -------- |
289| type | string | 是 | 取消监听,<br/>监听字段:fail,<br/>表示打印失败。 |
290| callback | Callback&lt;void&gt; | 否 | 取消相应状态监听成功后的回调。 |
291
292**错误码:**
293
294以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
295
296| 错误码ID | 错误信息                                    |
297| -------- | ------------------------------------------- |
298| 201 | the application does not have permission to call this function. |
299| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
300
301**示例:**
302
303```ts
304import { print } from '@kit.BasicServicesKit';
305import { BusinessError } from '@ohos.base';
306import { fileUri } from '@kit.CoreFileKit';
307
308let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
309print.print([fileUri.getUriFromPath(filePath)]).then((printTask: print.PrintTask) => {
310    printTask.off('fail', () => {
311        console.log('unregister state fail');
312    })
313    // ...
314}).catch((error: BusinessError) => {
315    console.log('print err ' + JSON.stringify(error));
316})
317```
318
319### PrintTask.off
320
321off(type: 'cancel', callback?: Callback&lt;void&gt;): void
322
323取消打印完成后的监听,使用callback回调。
324
325**需要权限:** ohos.permission.PRINT
326
327**系统能力:** SystemCapability.Print.PrintFramework
328
329**参数:**
330| **参数名** | **类型** | **必填** | **说明** |
331| -------- | -------- | -------- | -------- |
332| type | string | 是 | 取消监听,<br/>监听字段:cancel,<br/>表示打印取消。 |
333| callback | Callback&lt;void&gt; | 否 | 取消相应状态监听成功后的回调。 |
334
335**错误码:**
336
337以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
338
339| 错误码ID | 错误信息                                    |
340| -------- | ------------------------------------------- |
341| 201 | the application does not have permission to call this function. |
342| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
343
344**示例:**
345
346```ts
347import { print } from '@kit.BasicServicesKit';
348import { BusinessError } from '@ohos.base';
349import { fileUri } from '@kit.CoreFileKit';
350
351let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
352print.print([fileUri.getUriFromPath(filePath)]).then((printTask: print.PrintTask) => {
353    printTask.off('cancel', () => {
354        console.log('unregister state cancel');
355    })
356    // ...
357}).catch((error: BusinessError) => {
358    console.log('print err ' + JSON.stringify(error));
359})
360```
361
362## PrintDocumentAdapter<sup>11+</sup>
363
364第三方应用程序实现此接口来渲染要打印的文件。
365
366### onStartLayoutWrite
367
368onStartLayoutWrite(jobId: string, oldAttrs: PrintAttributes, newAttrs: PrintAttributes, fd: number, writeResultCallback: (jobId: string, writeResult: PrintFileCreationState) => void): void
369
370打印服务会通过本接口将一个空的pdf文件的文件描述符传给三方应用,由三方应用使用新的打印参数更新待打印文件,更新文件完成后通过本接口的回调方法writeResultCallback通知打印服务。
371
372**需要权限:** ohos.permission.PRINT
373
374**系统能力:** SystemCapability.Print.PrintFramework
375
376**参数:**
377| **参数名** | **类型** | **必填** | **说明** |
378| -------- | -------- | -------- | -------- |
379| jobId | string | 是 | 表示打印任务ID。 |
380| oldAttrs | [PrintAttributes](#printattributes11) | 是 | 表示旧打印参数。 |
381| newAttrs | [PrintAttributes](#printattributes11) | 是 | 表示新打印参数。 |
382| fd | number | 是 | 表示打印文件传给接口调用方的pdf文件的文件描述符。 |
383| writeResultCallback | (jobId: string, writeResult: [PrintFileCreationState](#printfilecreationstate11)) | 是 | 表示三方应用使用新的打印参数更新待打印文件完成后的回调。 |
384
385**错误码:**
386
387以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
388
389| 错误码ID | 错误信息                                    |
390| -------- | ------------------------------------------- |
391| 201 | the application does not have permission to call this function. |
392| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
393
394**示例:**
395
396```ts
397import { print } from '@kit.BasicServicesKit';
398import { BusinessError } from '@ohos.base';
399
400class MyPrintDocumentAdapter implements print.PrintDocumentAdapter {
401    onStartLayoutWrite(jobId: string, oldAttrs: print.PrintAttributes, newAttrs: print.PrintAttributes, fd: number,
402        writeResultCallback: (jobId: string, writeResult: print.PrintFileCreationState) => void) {
403        writeResultCallback(jobId, print.PrintFileCreationState.PRINT_FILE_CREATED);
404    };
405    onJobStateChanged(jobId: string, state: print.PrintDocumentAdapterState) {
406        if (state == print.PrintDocumentAdapterState.PREVIEW_DESTROY) {
407            console.log('PREVIEW_DESTROY');
408        } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_SUCCEED) {
409            console.log('PRINT_TASK_SUCCEED');
410        } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_FAIL) {
411            console.log('PRINT_TASK_FAIL');
412        } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_CANCEL) {
413            console.log('PRINT_TASK_CANCEL');
414        } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_BLOCK) {
415            console.log('PRINT_TASK_BLOCK');
416        }
417    }
418}
419```
420
421### onJobStateChanged
422
423onJobStateChanged(jobId: string, state: PrintDocumentAdapterState): void
424
425实现这个接口来监听打印任务状态的改变。
426
427**需要权限:** ohos.permission.PRINT
428
429**系统能力:** SystemCapability.Print.PrintFramework
430
431**参数:**
432| **参数名** | **类型** | **必填** | **说明** |
433| -------- | -------- | -------- | -------- |
434| jobId | string | 是 | 表示打印任务ID。 |
435| state | [PrintDocumentAdapterState](#printdocumentadapterstate11) | 是 | 表示打印任务更改为该状态。 |
436
437**错误码:**
438
439以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
440
441| 错误码ID | 错误信息                                    |
442| -------- | ------------------------------------------- |
443| 201 | the application does not have permission to call this function. |
444| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
445
446**示例:**
447
448```ts
449import { print } from '@kit.BasicServicesKit';
450import { BusinessError } from '@ohos.base';
451
452class MyPrintDocumentAdapter implements print.PrintDocumentAdapter {
453    onStartLayoutWrite(jobId: string, oldAttrs: print.PrintAttributes, newAttrs: print.PrintAttributes, fd: number,
454        writeResultCallback: (jobId: string, writeResult: print.PrintFileCreationState) => void) {
455        writeResultCallback(jobId, print.PrintFileCreationState.PRINT_FILE_CREATED);
456    };
457    onJobStateChanged(jobId: string, state: print.PrintDocumentAdapterState) {
458        if (state == print.PrintDocumentAdapterState.PREVIEW_DESTROY) {
459            console.log('PREVIEW_DESTROY');
460        } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_SUCCEED) {
461            console.log('PRINT_TASK_SUCCEED');
462        } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_FAIL) {
463            console.log('PRINT_TASK_FAIL');
464        } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_CANCEL) {
465            console.log('PRINT_TASK_CANCEL');
466        } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_BLOCK) {
467            console.log('PRINT_TASK_BLOCK');
468        }
469    }
470}
471```
472
473## print.print
474
475print(files: Array&lt;string&gt;, callback: AsyncCallback&lt;PrintTask&gt;): void
476
477打印接口,传入文件进行打印,使用callback异步回调。
478
479**需要权限:** ohos.permission.PRINT
480
481**系统能力:** SystemCapability.Print.PrintFramework
482
483**参数:**
484| **参数名** | **类型** | **必填** | **说明** |
485| -------- | -------- | -------- | -------- |
486| files | Array&lt;string&gt; | 是 | 待打印文件列表,支持图片(.jpg .png .gif .bmp .webp)和pdf。文件需先保存到应用沙箱,通过fileUri.getUriFromPath获取到沙箱uri,再作为参数传入到本接口。 |
487| callback | AsyncCallback&lt;[PrintTask](#printtask)&gt; | 是 | 异步获取打印完成之后的回调。 |
488
489**错误码:**
490
491以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
492
493| 错误码ID | 错误信息                                    |
494| -------- | ------------------------------------------- |
495| 201 | the application does not have permission to call this function. |
496| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
497
498**示例:**
499
500```ts
501import { print } from '@kit.BasicServicesKit';
502import { BusinessError } from '@ohos.base';
503import { fileUri } from '@kit.CoreFileKit';
504
505//传入文件的uri
506let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
507print.print([fileUri.getUriFromPath(filePath)], (err: BusinessError, printTask: print.PrintTask) => {
508    if (err) {
509        console.log('print err ' + JSON.stringify(err));
510    } else {
511        printTask.on('succeed', () => {
512            console.log('print state is succeed');
513        })
514        // ...
515    }
516})
517```
518
519## print.print
520
521print(files: Array&lt;string&gt;): Promise&lt;PrintTask&gt;
522
523打印接口,传入文件进行打印,使用Promise异步回调。
524
525**需要权限:** ohos.permission.PRINT
526
527**系统能力:** SystemCapability.Print.PrintFramework
528
529**参数:**
530| **参数名** | **类型** | **必填** | **说明** |
531| -------- | -------- | -------- | -------- |
532| files | Array&lt;string&gt; | 是 | 待打印文件列表,支持图片(.jpg .png .gif .bmp .webp)和pdf。文件需先保存到应用沙箱,通过fileUri.getUriFromPath获取到沙箱uri,再作为参数传入到本接口。 |
533
534**返回值:**
535| **类型** | **说明** |
536| -------- | -------- |
537| Promise&lt;[PrintTask](#printtask)&gt; | 打印完成结果。 |
538
539**错误码:**
540
541以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
542
543| 错误码ID | 错误信息                                    |
544| -------- | ------------------------------------------- |
545| 201 | the application does not have permission to call this function. |
546| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
547
548**示例:**
549
550```ts
551import { print } from '@kit.BasicServicesKit';
552import { BusinessError } from '@ohos.base';
553import { fileUri } from '@kit.CoreFileKit';
554
555//传入文件的uri
556let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
557print.print([fileUri.getUriFromPath(filePath)]).then((printTask: print.PrintTask) => {
558    printTask.on('succeed', () => {
559        console.log('print state is succeed');
560    })
561    // ...
562}).catch((error: BusinessError) => {
563    console.log('print err ' + JSON.stringify(error));
564})
565```
566
567## print.print<sup>11+</sup>
568
569print(files: Array&lt;string&gt;, context: Context, callback: AsyncCallback&lt;PrintTask&gt;): void
570
571打印接口,传入文件进行打印,使用callback异步回调。
572
573**需要权限:** ohos.permission.PRINT
574
575**系统能力:** SystemCapability.Print.PrintFramework
576
577**参数:**
578| **参数名** | **类型** | **必填** | **说明** |
579| -------- | -------- | -------- | -------- |
580| files | Array&lt;string&gt; | 是 | 待打印文件列表,支持图片(.jpg .png .gif .bmp .webp)和pdf。文件需先保存到应用沙箱,通过fileUri.getUriFromPath获取到沙箱uri,再作为参数传入到本接口。 |
581| context | Context | 是 | 用于拉起系统打印界面的UIAbilityContext。 |
582| callback | AsyncCallback&lt;[PrintTask](#printtask)&gt; | 是 | 异步获取打印完成之后的回调。 |
583
584**错误码:**
585
586以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
587
588| 错误码ID | 错误信息                                    |
589| -------- | ------------------------------------------- |
590| 201 | the application does not have permission to call this function. |
591| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
592
593**示例:**
594
595```ts
596import { print } from '@kit.BasicServicesKit';
597import { BusinessError } from '@ohos.base';
598import { fileUri } from '@kit.CoreFileKit';
599
600//传入文件的uri
601let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
602let context = this.getUIContext().getHostContext();
603print.print([fileUri.getUriFromPath(filePath)], context, (err: BusinessError, printTask: print.PrintTask) => {
604    if (err) {
605        console.log('print err ' + JSON.stringify(err));
606    } else {
607        printTask.on('succeed', () => {
608            console.log('print state is succeed');
609        })
610        // ...
611    }
612})
613```
614
615## print.print<sup>11+</sup>
616
617print(files: Array&lt;string&gt;, context: Context): Promise&lt;PrintTask&gt;
618
619打印接口,传入文件进行打印,使用Promise异步回调。
620
621**需要权限:** ohos.permission.PRINT
622
623**系统能力:** SystemCapability.Print.PrintFramework
624
625**参数:**
626| **参数名** | **类型** | **必填** | **说明** |
627| -------- | -------- | -------- | -------- |
628| files | Array&lt;string&gt; | 是 | 待打印文件列表,支持图片(.jpg .png .gif .bmp .webp)和pdf。文件需先保存到应用沙箱,通过fileUri.getUriFromPath获取到沙箱uri,再作为参数传入到本接口。 |
629| context | Context | 是 | 用于拉起系统打印界面的UIAbilityContext。 |
630
631**返回值:**
632| **类型** | **说明** |
633| -------- | -------- |
634| Promise&lt;[PrintTask](#printtask)&gt; | 打印完成结果。 |
635
636**错误码:**
637
638以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
639
640| 错误码ID | 错误信息                                    |
641| -------- | ------------------------------------------- |
642| 201 | the application does not have permission to call this function. |
643| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
644
645**示例:**
646
647```ts
648import { print } from '@kit.BasicServicesKit';
649import { BusinessError } from '@ohos.base';
650import { fileUri } from '@kit.CoreFileKit';
651
652//传入文件的uri
653let filePath = '/data/storage/el2/base/haps/entry/files/test.pdf';
654let context = this.getUIContext().getHostContext();
655print.print([fileUri.getUriFromPath(filePath)], context).then((printTask: print.PrintTask) => {
656    printTask.on('succeed', () => {
657        console.log('print state is succeed');
658    })
659    // ...
660}).catch((error: BusinessError) => {
661    console.log('print err ' + JSON.stringify(error));
662})
663```
664
665## print.print<sup>11+</sup>
666
667print(jobName: string, printAdapter: PrintDocumentAdapter, printAttributes: PrintAttributes, context: Context): Promise&lt;PrintTask&gt;
668
669打印接口,传入文件进行打印,三方应用需要更新打印文件,使用Promise异步回调。
670
671**需要权限:** ohos.permission.PRINT
672
673**系统能力:** SystemCapability.Print.PrintFramework
674
675**参数:**
676| **参数名** | **类型** | **必填** | **说明** |
677| -------- | -------- | -------- | -------- |
678| jobName | string | 是 | 表示待打印文件名称,例如:test.pdf。打印侧会通过[onStartLayoutWrite](#onstartlayoutwrite)接口将空的pdf文件的fd传给接口调用方,由调用方使用新的打印参数更新待打印文件。 |
679| printAdapter | [PrintDocumentAdapter](#printdocumentadapter11) | 是 | 表示三方应用实现的[PrintDocumentAdapter](#printdocumentadapter11)接口实例。 |
680| printAttributes | [PrintAttributes](#printattributes11) | 是 | 表示打印参数。 |
681| context | Context | 是 | 用于拉起系统打印界面的UIAbilityContext。 |
682
683**返回值:**
684| **类型** | **说明** |
685| -------- | -------- |
686| Promise&lt;[PrintTask](#printtask)&gt; | 打印完成结果。 |
687
688**错误码:**
689
690以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
691
692| 错误码ID | 错误信息                                    |
693| -------- | ------------------------------------------- |
694| 201 | the application does not have permission to call this function. |
695| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
696
697**示例:**
698
699```ts
700import { print } from '@kit.BasicServicesKit';
701import { BusinessError } from '@ohos.base';
702
703let jobName : string = "jobName";
704let printAdapter : print.PrintDocumentAdapter | null = null;
705let printAttributes : print.PrintAttributes = {
706    copyNumber: 1,
707    pageRange: {
708        startPage: 0,
709        endPage: 5,
710        pages: []
711    },
712    pageSize: print.PrintPageType.PAGE_ISO_A3,
713    directionMode: print.PrintDirectionMode.DIRECTION_MODE_AUTO,
714    colorMode: print.PrintColorMode.COLOR_MODE_MONOCHROME,
715    duplexMode: print.PrintDuplexMode.DUPLEX_MODE_NONE
716}
717let context = this.getUIContext().getHostContext();
718
719print.print(jobName, printAdapter, printAttributes, context).then((printTask: print.PrintTask) => {
720    printTask.on('succeed', () => {
721        console.log('print state is succeed');
722    })
723    // ...
724}).catch((error: BusinessError) => {
725    console.log('print err ' + JSON.stringify(error));
726})
727```
728
729## PrintAttributes<sup>11+</sup>
730
731定义打印参数的接口。
732
733**系统能力:** SystemCapability.Print.PrintFramework
734
735**属性:**
736| **名称** | **类型** | **必填** | **说明** |
737| -------- | -------- | -------- | -------- |
738| copyNumber | number | 否 | 表示文件打印份数。 |
739| pageRange | [PrintPageRange](#printpagerange11) | 否 | 表示待打印文件的页面范围。 |
740| pageSize | [PrintPageSize](#printpagesize11) \| [PrintPageType](#printpagetype11) | 否 | 表示代打印文件的纸张类型。 |
741| directionMode | [PrintDirectionMode](#printdirectionmode11) | 否 | 表示待打印文件的方向。 |
742| colorMode | [PrintColorMode](#printcolormode11) | 否 | 表示待打印文件的色彩模式。 |
743| duplexMode | [PrintDuplexMode](#printduplexmode11) | 否 | 表示待打印文件的单双面模式。 |
744
745## PrintPageRange<sup>11+</sup>
746
747定义打印范围的接口。
748
749**系统能力:** SystemCapability.Print.PrintFramework
750
751**属性:**
752| **名称** | **类型** | **必填** | **说明** |
753| -------- | -------- | -------- | -------- |
754| startPage | number | 否 | 表示起始页。 |
755| endPage | number | 否 | 表示结束页。 |
756| pages | Array&lt;number&gt; | 否 | 表示待打印的页面范围的集合。|
757
758
759## PrintPageSize<sup>11+</sup>
760
761定义打印页面尺寸的接口。
762
763**系统能力:** SystemCapability.Print.PrintFramework
764
765**属性:**
766| **名称** | **类型** | **必填** | **说明** |
767| -------- | -------- | -------- | -------- |
768| id | string | 是 | 表示纸张类型ID。 |
769| name | string | 是 | 表示纸张类型名称。 |
770| width | number | 是 | 表示页面宽度,单位:毫米。 |
771| height | number | 是 | 表示页面高度,单位:毫米。 |
772
773
774
775## PrintDirectionMode<sup>11+</sup>
776
777打印纸张方向的枚举。
778
779**系统能力:** SystemCapability.Print.PrintFramework
780
781| **名称** | **值** | **说明** |
782| -------- | -------- | -------- |
783| DIRECTION_MODE_AUTO | 0 | 表示自动选择纸张方向。 |
784| DIRECTION_MODE_PORTRAIT | 1 | 表示纵向打印。 |
785| DIRECTION_MODE_LANDSCAPE | 2 | 表示横向打印。 |
786
787## PrintColorMode<sup>11+</sup>
788
789打印色彩模式的枚举。
790
791**系统能力:** SystemCapability.Print.PrintFramework
792
793| **名称** | **值** | **说明** |
794| -------- | -------- | -------- |
795| COLOR_MODE_MONOCHROME | 0 | 表示黑白打印。 |
796| COLOR_MODE_COLOR | 1 | 表示彩色打印。 |
797
798## PrintDuplexMode<sup>11+</sup>
799
800打印单双面模式的枚举。
801
802**系统能力:** SystemCapability.Print.PrintFramework
803
804| **名称** | **值** | **说明** |
805| -------- | -------- | -------- |
806| DUPLEX_MODE_NONE | 0 | 表示单面打印。 |
807| DUPLEX_MODE_LONG_EDGE | 1 | 表示双面打印沿长边翻转。 |
808| DUPLEX_MODE_SHORT_EDGE | 2 | 表示双面打印沿短边翻转。 |
809
810## PrintPageType<sup>11+</sup>
811
812打印纸张类型的枚举。
813
814**系统能力:** SystemCapability.Print.PrintFramework
815
816| **名称** | **值** | **说明** |
817| -------- | -------- | -------- |
818| PAGE_ISO_A3 | 0 | 表示A3。 |
819| PAGE_ISO_A4 | 1 | 表示A4。 |
820| PAGE_ISO_A5 | 2 | 表示A5。 |
821| PAGE_JIS_B5 | 3 | 表示B5。 |
822| PAGE_ISO_C5 | 4 | 表示C5。 |
823| PAGE_ISO_DL | 5 | 表示DL。 |
824| PAGE_LETTER | 6 | 表示Letter。 |
825| PAGE_LEGAL | 7 | 表示Legal。 |
826| PAGE_PHOTO_4X6 | 8 | 表示4x6相纸。 |
827| PAGE_PHOTO_5X7 | 9 | 表示5x7相纸。 |
828| PAGE_INT_DL_ENVELOPE | 10 | 表示INT DL ENVELOPE。 |
829| PAGE_B_TABLOID | 11 | 表示B Tabloid。 |
830
831## PrintDocumentAdapterState<sup>11+</sup>
832
833打印任务状态的枚举。
834
835**系统能力:** SystemCapability.Print.PrintFramework
836
837| **名称** | **值** | **说明** |
838| -------- | -------- | -------- |
839| PREVIEW_DESTROY | 0 | 表示预览失败。 |
840| PRINT_TASK_SUCCEED | 1 | 表示打印任务成功。 |
841| PRINT_TASK_FAIL | 2 | 表示打印任务失败。 |
842| PRINT_TASK_CANCEL | 3 | 表示打印任务取消。 |
843| PRINT_TASK_BLOCK | 4 | 表示打印任务阻塞。 |
844
845## PrintFileCreationState<sup>11+</sup>
846
847打印文件创建状态的枚举。
848
849**系统能力:** SystemCapability.Print.PrintFramework
850
851| **名称** | **值** | **说明** |
852| -------- | -------- | -------- |
853| PRINT_FILE_CREATED | 0 | 表示打印文件创建成功。 |
854| PRINT_FILE_CREATION_FAILED | 1 | 表示打印文件创建失败。|
855| PRINT_FILE_CREATED_UNRENDERED | 2 | 表示打印文件创建成功但未渲染。 |
856
857## PrinterState<sup>14+</sup>
858
859打印机状态的枚举。
860
861**系统能力:** SystemCapability.Print.PrintFramework
862
863| **名称** | **值** | **说明** |
864| -------- | -------- | -------- |
865| PRINTER_ADDED | 0 | 表示新打印机到达。 |
866| PRINTER_REMOVED | 1 | 表示打印机丢失。 |
867| PRINTER_CAPABILITY_UPDATED | 2 | 表示打印机更新。 |
868| PRINTER_CONNECTED | 3 | 表示打印机已连接。 |
869| PRINTER_DISCONNECTED | 4 | 表示打印机已断开连接。 |
870| PRINTER_RUNNING | 5 | 表示打印机正在运行。 |
871
872## PrintJobState<sup>14+</sup>
873
874打印任务状态的枚举。
875
876**系统能力:** SystemCapability.Print.PrintFramework
877
878| **名称** | **值** | **说明** |
879| -------- | -------- | -------- |
880| PRINT_JOB_PREPARE | 0 | 表示打印任务的初始状态。 |
881| PRINT_JOB_QUEUED | 1 | 表示打印任务传送到打印机。 |
882| PRINT_JOB_RUNNING | 2 | 表示执行打印任务。|
883| PRINT_JOB_BLOCKED | 3 | 表示打印任务已被阻止。 |
884| PRINT_JOB_COMPLETED | 4 | 表示打印任务完成。 |
885
886## PrintJobSubState<sup>14+</sup>
887
888打印任务子状态的枚举。
889
890**系统能力:** SystemCapability.Print.PrintFramework
891
892| **名称** | **值** | **说明** |
893| -------- | -------- | -------- |
894| PRINT_JOB_COMPLETED_SUCCESS | 0 | 表示打印任务成功。 |
895| PRINT_JOB_COMPLETED_FAILED | 1 | 表示打印任务失败。 |
896| PRINT_JOB_COMPLETED_CANCELLED | 2 | 表示打印任务已取消。|
897| PRINT_JOB_COMPLETED_FILE_CORRUPTED | 3 | 表示打印任务已损坏。 |
898| PRINT_JOB_BLOCK_OFFLINE | 4 | 表示打印处于离线状态。 |
899| PRINT_JOB_BLOCK_BUSY | 5 | 表示打印被其他进程占用。 |
900| PRINT_JOB_BLOCK_CANCELLED | 6 | 表示打印任务已取消。 |
901| PRINT_JOB_BLOCK_OUT_OF_PAPER | 7 | 表示打印纸张用完。 |
902| PRINT_JOB_BLOCK_OUT_OF_INK | 8 | 表示打印墨水用完。 |
903| PRINT_JOB_BLOCK_OUT_OF_TONER | 9 | 表示打印墨粉用完。 |
904| PRINT_JOB_BLOCK_JAMMED | 10 | 表示打印卡纸。 |
905| PRINT_JOB_BLOCK_DOOR_OPEN | 11 | 表示打印盖开启。 |
906| PRINT_JOB_BLOCK_SERVICE_REQUEST | 12 | 表示打印服务请求。 |
907| PRINT_JOB_BLOCK_LOW_ON_INK | 13 | 表示打印墨水不足。 |
908| PRINT_JOB_BLOCK_LOW_ON_TONER | 14 | 表示打印墨粉不足。 |
909| PRINT_JOB_BLOCK_REALLY_LOW_ON_INK | 15 | 表示打印墨水量非常低。 |
910| PRINT_JOB_BLOCK_BAD_CERTIFICATE | 16 | 表示打印证书有误。 |
911| PRINT_JOB_BLOCK_ACCOUNT_ERROR | 18 | 表示打印账户时出错。 |
912| PRINT_JOB_BLOCK_PRINT_PERMISSION_ERROR | 19 | 表示打印许可异常。 |
913| PRINT_JOB_BLOCK_PRINT_COLOR_PERMISSION_ERROR | 20 | 表示彩色打印权限异常。 |
914| PRINT_JOB_BLOCK_NETWORK_ERROR | 21 | 表示设备未连接到网络。 |
915| PRINT_JOB_BLOCK_SERVER_CONNECTION_ERROR | 22 | 表示无法连接服务器。 |
916| PRINT_JOB_BLOCK_LARGE_FILE_ERROR | 23 | 表示打印大文件异常。 |
917| PRINT_JOB_BLOCK_FILE_PARSING_ERROR | 24 | 表示文件分析异常。 |
918| PRINT_JOB_BLOCK_SLOW_FILE_CONVERSION | 25 | 表示文件转换太慢。 |
919| PRINT_JOB_RUNNING_UPLOADING_FILES | 26 | 表示正在上传文件。 |
920| PRINT_JOB_RUNNING_CONVERTING_FILES | 27 | 表示正在转换文件。 |
921| PRINT_JOB_BLOCK_UNKNOWN | 99 | 表示打印未知问题。 |
922
923## PrintErrorCode<sup>14+</sup>
924
925打印错误代码的枚举。
926
927**系统能力:** SystemCapability.Print.PrintFramework
928
929| **名称** | **值** | **说明** |
930| -------- | -------- | -------- |
931| E_PRINT_NONE | 0 | 表示没有错误。 |
932| E_PRINT_NO_PERMISSION | 201 | 表示没有许可。 |
933| E_PRINT_INVALID_PARAMETER | 401 | 表示无效的参数。 |
934| E_PRINT_GENERIC_FAILURE | 13100001 | 表示一般打印失败。 |
935| E_PRINT_RPC_FAILURE | 13100002 | 表示RPC失败。 |
936| E_PRINT_SERVER_FAILURE | 13100003 | 表示打印服务失败。 |
937| E_PRINT_INVALID_EXTENSION | 13100004 | 表示打印扩展无效。 |
938| E_PRINT_INVALID_PRINTER | 13100005 | 表示打印机无效。 |
939| E_PRINT_INVALID_PRINT_JOB | 13100006 | 表示打印任务无效。 |
940| E_PRINT_FILE_IO | 13100007 | 表示文件输入/输出错误。 |
941
942## ApplicationEvent<sup>14+</sup>
943
944打印应用事件的枚举。
945
946**系统能力:** SystemCapability.Print.PrintFramework
947
948| **名称** | **值** | **说明** |
949| -------- | -------- | -------- |
950| APPLICATION_CREATED | 0 | 表示打印应用被拉起的事件。 |
951| APPLICATION_CLOSED_FOR_STARTED | 1 | 表示由于点击打印而关闭打印应用的事件。 |
952| APPLICATION_CLOSED_FOR_CANCELED | 2 | 表示由于点击取消而关闭打印应用的事件。 |
953
954## print.addPrinterToDiscovery<sup>14+</sup>
955
956addPrinterToDiscovery(printerInformation: PrinterInformation): Promise&lt;void&gt;
957
958添加打印机到系统打印机发现列表,使用Promise异步回调。
959
960**需要权限:** ohos.permission.PRINT
961
962**系统能力:** SystemCapability.Print.PrintFramework
963
964**参数:**
965| **参数名** | **类型** | **必填** | **说明** |
966| -------- | -------- | -------- | -------- |
967| printerInformation | [PrinterInformation](#printerinformation14) | 是 | 表示新发现的打印机。 |
968
969**返回值:**
970| **类型** | **说明** |
971| -------- | -------- |
972| Promise&lt;void&gt; | 添加打印机到系统打印机发现列表完成结果。 |
973
974**错误码:**
975
976以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
977
978| 错误码ID | 错误信息                                    |
979| -------- | ------------------------------------------- |
980| 201 | the application does not have permission to call this function. |
981| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
982
983**示例:**
984
985```ts
986import { print } from '@kit.BasicServicesKit';
987import { BusinessError } from '@ohos.base';
988
989let printerInformation : print.PrinterInformation = {
990    printerId : 'testPrinterId',
991    printerName : 'testPrinterName',
992    printerStatus : 0,
993    description : 'testDesc',
994    uri : 'testUri',
995    printerMake : 'testPrinterMake',
996    options : 'testOps'
997};
998print.addPrinterToDiscovery(printerInformation).then((data : void) => {
999    console.log('addPrinterToDiscovery data : ' + JSON.stringify(data));
1000}).catch((error: BusinessError) => {
1001    console.log('addPrinterToDiscovery error : ' + JSON.stringify(error));
1002})
1003```
1004
1005## print.updatePrinterInDiscovery<sup>14+</sup>
1006
1007updatePrinterInDiscovery(printerInformation: PrinterInformation): Promise&lt;void&gt;
1008
1009更新打印机能力到系统打印机发现列表,使用Promise异步回调。
1010
1011**需要权限:** ohos.permission.PRINT
1012
1013**系统能力:** SystemCapability.Print.PrintFramework
1014
1015**参数:**
1016| **参数名** | **类型** | **必填** | **说明** |
1017| -------- | -------- | -------- | -------- |
1018| printerInformation | [PrinterInformation](#printerinformation14) | 是 | 表示待更新能力的打印机。 |
1019
1020**返回值:**
1021| **类型** | **说明** |
1022| -------- | -------- |
1023| Promise&lt;void&gt; | 更新打印机能力到系统打印机发现列表完成结果。 |
1024
1025**错误码:**
1026
1027以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
1028
1029| 错误码ID | 错误信息                                    |
1030| -------- | ------------------------------------------- |
1031| 201 | the application does not have permission to call this function. |
1032| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1033
1034**示例:**
1035
1036```ts
1037import { print } from '@kit.BasicServicesKit';
1038import { BusinessError } from '@ohos.base';
1039
1040let testPageSize : print.PrintPageSize = {
1041    id : 'ISO_A4',
1042    name : 'iso_a4_210x297mm',
1043    width : 8268,
1044    height : 11692
1045};
1046
1047let testCapability : print.PrinterCapabilities = {
1048    supportedPageSizes : [testPageSize],
1049    supportedColorModes : [print.PrintColorMode.COLOR_MODE_MONOCHROME],
1050    supportedDuplexModes : [print.PrintDuplexMode.DUPLEX_MODE_NONE],
1051    supportedMediaTypes : ['stationery'],
1052    supportedQualities : [print.PrintQuality.QUALITY_NORMAL],
1053    supportedOrientations : [print.PrintOrientationMode.ORIENTATION_MODE_PORTRAIT],
1054    options : 'testOptions'
1055};
1056
1057let printerInformation : print.PrinterInformation = {
1058    printerId : 'testPrinterId',
1059    printerName : 'testPrinterName',
1060    printerStatus : 0,
1061    description : 'testDesc',
1062    capability : testCapability,
1063    uri : 'testUri',
1064    printerMake : 'testPrinterMake',
1065    options : 'testOptions'
1066};
1067print.updatePrinterInDiscovery(printerInformation).then((data : void) => {
1068    console.log('updatePrinterInDiscovery data : ' + JSON.stringify(data));
1069}).catch((error: BusinessError) => {
1070    console.log('updatePrinterInDiscovery error : ' + JSON.stringify(error));
1071})
1072```
1073
1074## print.removePrinterFromDiscovery<sup>14+</sup>
1075
1076removePrinterFromDiscovery(printerId: string): Promise&lt;void&gt;
1077
1078从系统打印机发现列表里移除打印机,使用Promise异步回调。
1079
1080**需要权限:** ohos.permission.PRINT
1081
1082**系统能力:** SystemCapability.Print.PrintFramework
1083
1084**参数:**
1085| **参数名** | **类型** | **必填** | **说明** |
1086| -------- | -------- | -------- | -------- |
1087| printerId | string | 是 | 表示待移除的打印机。 |
1088
1089**返回值:**
1090| **类型** | **说明** |
1091| -------- | -------- |
1092| Promise&lt;void&gt; | 从系统打印机发现列表里移除打印机完成结果。 |
1093
1094**错误码:**
1095
1096以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
1097
1098| 错误码ID | 错误信息                                    |
1099| -------- | ------------------------------------------- |
1100| 201 | the application does not have permission to call this function. |
1101| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1102
1103**示例:**
1104
1105```ts
1106import { print } from '@kit.BasicServicesKit';
1107import { BusinessError } from '@ohos.base';
1108
1109let printerId : string = 'testPrinterId';
1110print.removePrinterFromDiscovery(printerId).then((data : void) => {
1111    console.log('removePrinterFromDiscovery data : ' + JSON.stringify(data));
1112}).catch((error: BusinessError) => {
1113    console.log('removePrinterFromDiscovery error : ' + JSON.stringify(error));
1114})
1115```
1116
1117## print.getPrinterInformationById<sup>14+</sup>
1118
1119getPrinterInformationById(printerId: string): Promise&lt;PrinterInformation&gt;
1120
1121根据打印机id获取打印机信息,使用Promise异步回调。
1122
1123**需要权限:** ohos.permission.PRINT
1124
1125**系统能力:** SystemCapability.Print.PrintFramework
1126
1127**参数:**
1128| **参数名** | **类型** | **必填** | **说明** |
1129| -------- | -------- | -------- | -------- |
1130| printerId | string | 是 | 表示待获取信息的打印机id。 |
1131
1132**返回值:**
1133| **类型** | **说明** |
1134| -------- | -------- |
1135| Promise&lt;[PrinterInformation](#printerinformation14)&gt; | 根据打印机id获取的对应打印机信息。 |
1136
1137**错误码:**
1138
1139以下错误码的详细介绍请参见[打印服务错误码](./errorcode-print.md)。
1140
1141| 错误码ID | 错误信息                                    |
1142| -------- | ------------------------------------------- |
1143| 201 | the application does not have permission to call this function. |
1144| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1145
1146**示例:**
1147
1148```ts
1149import { print } from '@kit.BasicServicesKit';
1150import { BusinessError } from '@ohos.base';
1151
1152let printerId : string = 'testPrinterId';
1153print.getPrinterInformationById(printerId).then((printerInformation : print.PrinterInformation) => {
1154    console.log('getPrinterInformationById data : ' + JSON.stringify(printerInformation));
1155}).catch((error: BusinessError) => {
1156    console.log('getPrinterInformationById error : ' + JSON.stringify(error));
1157})
1158```
1159
1160## PrinterInformation<sup>14+</sup>
1161
1162定义打印机信息的接口。
1163
1164**系统能力:** SystemCapability.Print.PrintFramework
1165
1166**属性:**
1167| **名称** | **类型** | **必填** | **说明** |
1168| -------- | -------- | -------- | -------- |
1169| printerId | string | 是 | 表示打印机ID。 |
1170| printerName | string | 是 | 表示打印机名称。 |
1171| printerStatus | [PrinterStatus](#printerstatus14) | 是 | 表示当前打印机状态。 |
1172| description | string | 否 | 表示打印机说明。 |
1173| capability | [PrinterCapabilities](#printercapabilities14) | 否 | 表示打印机能力。 |
1174| uri | string | 否 | 表示打印机uri。 |
1175| printerMake | string | 否 | 表示打印机型号。 |
1176| options | string | 否 | 表示打印机详细信息。 |
1177
1178## PrinterCapabilities<sup>14+</sup>
1179
1180定义打印机能力的接口。
1181
1182**系统能力:** SystemCapability.Print.PrintFramework
1183
1184**属性:**
1185| **名称** | **类型** | **必填** | **说明** |
1186| -------- | -------- | -------- | -------- |
1187| supportedPageSizes | Array&lt;[PrintPageSize](#printpagesize11)&gt; | 是 | 表示打印机支持的纸张尺寸列表。 |
1188| supportedColorModes | Array&lt;[PrintColorMode](#printcolormode11)&gt; | 是 | 表示打印机支持的色彩模式列表。 |
1189| supportedDuplexModes | Array&lt;[PrintDuplexMode](#printduplexmode11)&gt; | 是 | 表示打印机支持的单双面模式列表。 |
1190| supportedMediaTypes | Array&lt;string&gt; | 否 | 表示打印机支持的纸张类型列表。 |
1191| supportedQualities | Array&lt;[PrintQuality](#printquality14)&gt; | 否 | 表示打印机支持的打印质量列表。 |
1192| supportedOrientations | Array&lt;[PrintOrientationMode](#printorientationmode14)&gt; | 否 | 表示打印机支持的打印方向列表。 |
1193| options | string | 否 | 表示打印机能力详细信息。 |
1194
1195## PrintQuality<sup>14+</sup>
1196
1197打印质量的枚举。
1198
1199**系统能力:** SystemCapability.Print.PrintFramework
1200
1201| **名称** | **值** | **说明** |
1202| -------- | -------- | -------- |
1203| QUALITY_DRAFT | 3 | 表示经济的打印质量。 |
1204| QUALITY_NORMAL | 4 | 表示标准的打印质量。 |
1205| QUALITY_HIGH | 5 | 表示最佳的打印质量。 |
1206
1207## PrintOrientationMode<sup>14+</sup>
1208
1209打印方向的枚举。
1210
1211**系统能力:** SystemCapability.Print.PrintFramework
1212
1213| **名称** | **值** | **说明** |
1214| -------- | -------- | -------- |
1215| ORIENTATION_MODE_PORTRAIT | 0 | 表示纵向打印。 |
1216| ORIENTATION_MODE_LANDSCAPE | 1 | 表示横向打印。 |
1217| ORIENTATION_MODE_REVERSE_LANDSCAPE | 2 | 表示横向翻转打印。 |
1218| ORIENTATION_MODE_REVERSE_PORTRAIT | 3 | 表示纵向翻转打印。 |
1219| ORIENTATION_MODE_NONE | 4 | 表示自适应方向打印。 |
1220
1221## PrinterStatus<sup>14+</sup>
1222
1223打印机状态的枚举。
1224
1225**系统能力:** SystemCapability.Print.PrintFramework
1226
1227| **名称** | **值** | **说明** |
1228| -------- | -------- | -------- |
1229| PRINTER_IDLE | 0 | 表示打印机空闲状态。 |
1230| PRINTER_BUSY | 1 | 表示打印机忙碌状态。 |
1231| PRINTER_UNAVAILABLE | 2 | 表示打印机脱机状态。 |
1232