1# OH_Print
2
3
4## Overview
5
6Provides the C APIs definition of the print module.
7
8**System capability**: SystemCapability.Print.PrintFramework
9
10**Since**: 12
11
12
13## Summary
14
15
16### Files
17
18| Name| Description|
19| -------- | -------- |
20| [ohprint.h](ohprint_8h.md) | Declares APIs for discovering and connecting to printers, printing files, and querying the list of added printers and printer information. |
21
22
23### Structs
24
25| Name| Description|
26| -------- | -------- |
27| struct  [Print_Margin](_print___margin.md) | Defines the page margin. |
28| struct  [Print_PageSize](_print___page_size.md) | Defines the page size. |
29| struct  [Print_Range](_print___range.md) | Defines the page range. |
30| struct  [Print_PrintAttributes](_print___print_attributes.md) | Defines the print attributes. |
31| struct  [Print_PrintDocCallback](_print___print_doc_callback.md) | Defines the print job callback. |
32
33
34### Types
35
36| Name| Description|
37| -------- | -------- |
38| typedef void(\* [Print_WriteResultCallback](#print_writeresultcallback)) (const char \*jobId, uint32_t code) | Defines a callback used to return the file write-back result. |
39| typedef void(\* [Print_OnStartLayoutWrite](#print_onstartlayoutwrite)) (const char \*jobId, uint32_t fd, const [Print_PrintAttributes](_print___print_attributes.md) \*oldAttrs, const [Print_PrintAttributes](_print___print_attributes.md) \*newAttrs, [Print_WriteResultCallback](#print_writeresultcallback) writeCallback) | Defines a callback to be invoked when the file write-back starts. |
40| typedef void(\* [Print_OnJobStateChanged](#print_onjobstatechanged)) (const char \*jobId, uint32_t state) | Defines a callback used to return the print job state. |
41
42
43### Enums
44
45| Name| Description|
46| -------- | -------- |
47| [Print_ErrorCode](#print_errorcode) {<br>PRINT_ERROR_NONE = 0, PRINT_ERROR_NO_PERMISSION = 201, PRINT_ERROR_INVALID_PARAMETER = 401, PRINT_ERROR_GENERIC_FAILURE = 24300001,<br>PRINT_ERROR_RPC_FAILURE = 24300002, PRINT_ERROR_SERVER_FAILURE = 24300003, PRINT_ERROR_INVALID_EXTENSION = 24300004, PRINT_ERROR_INVALID_PRINTER = 24300005,<br>PRINT_ERROR_INVALID_PRINT_JOB = 24300006, PRINT_ERROR_FILE_IO = 24300007, PRINT_ERROR_UNKNOWN = 24300255<br>} | Enumerates the error codes. |
48| [Print_JobDocAdapterState](#print_jobdocadapterstate) {<br>PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY = 0, PRINT_DOC_ADAPTER_PRINT_TASK_SUCCEED = 1, PRINT_DOC_ADAPTER_PRINT_TASK_FAIL = 2, PRINT_DOC_ADAPTER_PRINT_TASK_CANCEL = 3,<br>PRINT_DOC_ADAPTER_PRINT_TASK_BLOCK = 4, PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY_FOR_CANCELED = 5, PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY_FOR_STARTED = 6<br>} | Enumerates the print job states. |
49
50
51### Functions
52
53| Name| Description|
54| -------- | -------- |
55| [Print_ErrorCode](#print_errorcode)[OH_Print_StartPrintByNative](#oh_print_startprintbynative) (const char \*printJobName, [Print_PrintDocCallback](_print___print_doc_callback.md) printDocCallback, void \*context) | Calls the API for opening the print preview page. |
56
57
58## Type Description
59
60
61### Print_OnJobStateChanged
62
63```
64typedef void(* Print_OnJobStateChanged) (const char *jobId, uint32_t state)
65```
66**Description**
67Defines a callback used to return the print job state.
68
69**Since**: 13
70
71**Parameters**
72
73| Name| Description|
74| -------- | -------- |
75| jobId | Print job ID. |
76| state | Current job state. |
77
78
79### Print_OnStartLayoutWrite
80
81```
82typedef void(* Print_OnStartLayoutWrite) (const char *jobId, uint32_t fd, const Print_PrintAttributes *oldAttrs, const Print_PrintAttributes *newAttrs, Print_WriteResultCallback writeCallback)
83```
84**Description**
85Defines a callback to be invoked when the file write-back starts.
86
87**Since**: 13
88
89**Parameters**
90
91| Name| Description|
92| -------- | -------- |
93| jobId | Print job ID. |
94| fd | File handle for write-back. |
95| oldAttrs | Print parameter before change. |
96| newAttrs | Print parameter after change. |
97| writeCallback | Callback to be invoked when the file write-back finishes. |
98
99
100### Print_WriteResultCallback
101
102```
103typedef void(* Print_WriteResultCallback) (const char *jobId, uint32_t code)
104```
105**Description**
106Defines a callback used to return the file write-back result.
107
108**Since**: 13
109
110**Parameters**
111
112| Name| Description|
113| -------- | -------- |
114| jobId | Print job ID. |
115| code | File writeback result. |
116
117
118## Enum Description
119
120
121### Print_ErrorCode
122
123```
124enum Print_ErrorCode
125```
126**Description**
127Enumerates the error codes.
128
129**Since**: 12
130
131| Value| Description|
132| -------- | -------- |
133| PRINT_ERROR_NONE  | Success.  |
134| PRINT_ERROR_NO_PERMISSION  | Permission denied.  |
135| PRINT_ERROR_INVALID_PARAMETER  | Invalid parameter.  |
136| PRINT_ERROR_GENERIC_FAILURE  | Internal error.  |
137| PRINT_ERROR_RPC_FAILURE  | RPC transmission failed.  |
138| PRINT_ERROR_SERVER_FAILURE  | Print service failed.  |
139| PRINT_ERROR_INVALID_EXTENSION  | Invalid print extension.  |
140| PRINT_ERROR_INVALID_PRINTER  | Invalid printer.  |
141| PRINT_ERROR_INVALID_PRINT_JOB  | Invalid print job.  |
142| PRINT_ERROR_FILE_IO  | File I/O error.  |
143| PRINT_ERROR_UNKNOWN  | Unknown error.  |
144
145
146### Print_JobDocAdapterState
147
148```
149enum Print_JobDocAdapterState
150```
151**Description**
152Enumerates the print job states.
153
154**Since**: 13
155
156| Value| Description|
157| -------- | -------- |
158| PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY  | Print preview page destroyed.  |
159| PRINT_DOC_ADAPTER_PRINT_TASK_SUCCEED  | Print job succeeded.  |
160| PRINT_DOC_ADAPTER_PRINT_TASK_FAIL  | Print job failed.  |
161| PRINT_DOC_ADAPTER_PRINT_TASK_CANCEL  | Print job canceled. |
162| PRINT_DOC_ADAPTER_PRINT_TASK_BLOCK  | Print job blocked.  |
163| PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY_FOR_CANCELED  | Print preview page destroyed by clicking the cancel button.  |
164| PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY_FOR_STARTED  | Print preview page destroyed by clicking the print button.  |
165
166
167## Function Description
168
169
170### OH_Print_StartPrintByNative()
171
172```
173Print_ErrorCode OH_Print_StartPrintByNative (const char * printJobName, Print_PrintDocCallback printDocCallback, void * context )
174```
175**Description**
176Calls the API for opening the print preview page.
177
178**System capability**: SystemCapability.Print.PrintFramework
179
180**Since**: 13
181
182**Parameters**
183
184| Name| Description|
185| -------- | -------- |
186| printJobName | Print job name. |
187| printDocCallback | Print job callback struct. |
188| context | Context of the ability that calls the API. |
189
190**Required Permissions**
191
192ohos.permission.PRINT
193
194**Returns**
195
196**Print_ErrorCode#PRINT_ERROR_NONE**: The operation is successful.
197
198**PRINT_ERROR_NO_PERMISSION**: The **ohos.permission.PRINT** permission must be declared.
199
200**PRINT_ERROR_RPC_FAILURE**: Failed to connect to the print service.
201