1e41f4b71Sopenharmony_ci# @ohos.print (Print) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **print** module provides APIs for basic print operations. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci## Modules to Import 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci```ts 11e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 12e41f4b71Sopenharmony_ci``` 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci## PrintTask 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ciImplements event listeners for print tasks. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci### on 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_cion(type: 'block', callback: Callback<void>): void 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciRegisters a listener for the print task blocking event. This API uses a callback to return the result. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**Parameters** 29e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 30e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 31e41f4b71Sopenharmony_ci| type | string | Yes| Listening type.<br>The value is fixed at **'block'**,<br>indicating blocking of the print task.| 32e41f4b71Sopenharmony_ci| callback | Callback<void> | Yes| Callback used to return the result.| 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**Error codes** 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci| ID| Error Message | 39e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 40e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 41e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**Example** 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci```ts 46e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 47e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_cilet file = ['file://data/print/a.png', 'file://data/print/b.png']; 50e41f4b71Sopenharmony_ciprint.print(file).then((printTask: print.PrintTask) => { 51e41f4b71Sopenharmony_ci printTask.on('block', () => { 52e41f4b71Sopenharmony_ci console.log('print state is block'); 53e41f4b71Sopenharmony_ci }) 54e41f4b71Sopenharmony_ci // ... 55e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 56e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 57e41f4b71Sopenharmony_ci}) 58e41f4b71Sopenharmony_ci``` 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci### on 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_cion(type: 'succeed', callback: Callback<void>): void 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ciRegisters a listener for the print task blocking event. This API uses a callback to return the result. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci**Parameters** 71e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 72e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 73e41f4b71Sopenharmony_ci| type | string | Yes| Listening type.<br>The value is fixed at **'succeed'**,<br>indicating success of the print task.| 74e41f4b71Sopenharmony_ci| callback | Callback<void> | Yes| Callback used to return the result.| 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**Error codes** 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci| ID| Error Message | 81e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 82e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 83e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**Example** 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci```ts 88e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 89e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_cilet file = ['file://data/print/a.png', 'file://data/print/b.png']; 92e41f4b71Sopenharmony_ciprint.print(file).then((printTask: print.PrintTask) => { 93e41f4b71Sopenharmony_ci printTask.on('succeed', () => { 94e41f4b71Sopenharmony_ci console.log('print state is succeed'); 95e41f4b71Sopenharmony_ci }) 96e41f4b71Sopenharmony_ci // ... 97e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 98e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 99e41f4b71Sopenharmony_ci}) 100e41f4b71Sopenharmony_ci``` 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci### on 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_cion(type: 'fail', callback: Callback<void>): void 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ciRegisters a listener for the print task blocking event. This API uses a callback to return the result. 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**Parameters** 113e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 114e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 115e41f4b71Sopenharmony_ci| type | string | Yes| Listening type.<br>The value is fixed at **'fail'**,<br>indicating failure of the print task.| 116e41f4b71Sopenharmony_ci| callback | Callback<void> | Yes| Callback used to return the result.| 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci**Error codes** 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci| ID| Error Message | 123e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 124e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 125e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**Example** 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci```ts 130e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 131e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_cilet file = ['file://data/print/a.png', 'file://data/print/b.png']; 134e41f4b71Sopenharmony_ciprint.print(file).then((printTask: print.PrintTask) => { 135e41f4b71Sopenharmony_ci printTask.on('fail', () => { 136e41f4b71Sopenharmony_ci console.log('print state is fail'); 137e41f4b71Sopenharmony_ci }) 138e41f4b71Sopenharmony_ci // ... 139e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 140e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 141e41f4b71Sopenharmony_ci}) 142e41f4b71Sopenharmony_ci``` 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci### on 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_cion(type: 'cancel', callback: Callback<void>): void 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ciRegisters a listener for the print task blocking event. This API uses a callback to return the result. 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci**Parameters** 155e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 156e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 157e41f4b71Sopenharmony_ci| type | string | Yes| Listening type.<br>The value is fixed at **'cancel'**,<br>indicating canceling of the print task.| 158e41f4b71Sopenharmony_ci| callback | Callback<void> | Yes| Callback used to return the result.| 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci**Error codes** 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci| ID| Error Message | 165e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 166e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 167e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci**Example** 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci```ts 172e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 173e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_cilet file = ['file://data/print/a.png', 'file://data/print/b.png']; 176e41f4b71Sopenharmony_ciprint.print(file).then((printTask: print.PrintTask) => { 177e41f4b71Sopenharmony_ci printTask.on('cancel', () => { 178e41f4b71Sopenharmony_ci console.log('print state is cancel'); 179e41f4b71Sopenharmony_ci }) 180e41f4b71Sopenharmony_ci // ... 181e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 182e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 183e41f4b71Sopenharmony_ci}) 184e41f4b71Sopenharmony_ci``` 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci### off 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_cioff(type: 'block', callback?: Callback<void>): void 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ciUnregisters the listener for the print task blocking event. This API uses a callback to return the result. 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**Parameters** 197e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 198e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 199e41f4b71Sopenharmony_ci| type | string | Yes| Listening type.<br>The value is fixed at **'block'**,<br>indicating blocking of the print task.| 200e41f4b71Sopenharmony_ci| callback | Callback<void> | No| Callback used to return the result.| 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci**Error codes** 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci| ID| Error Message | 207e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 208e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 209e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci**Example** 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci```ts 214e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 215e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_cilet file = ['file://data/print/a.png', 'file://data/print/b.png']; 218e41f4b71Sopenharmony_ciprint.print(file).then((printTask: print.PrintTask) => { 219e41f4b71Sopenharmony_ci printTask.off('block', () => { 220e41f4b71Sopenharmony_ci console.log('unregister state block'); 221e41f4b71Sopenharmony_ci }) 222e41f4b71Sopenharmony_ci // ... 223e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 224e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 225e41f4b71Sopenharmony_ci}) 226e41f4b71Sopenharmony_ci``` 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci### off 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_cioff(type: 'succeed', callback?: Callback<void>): void 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ciUnregisters the listener for the print task blocking event. This API uses a callback to return the result. 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci**Parameters** 239e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 240e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 241e41f4b71Sopenharmony_ci| type | string | Yes| Listening type.<br>The value is fixed at **'succeed'**,<br>indicating success of the print task.| 242e41f4b71Sopenharmony_ci| callback | Callback<void> | No| Callback used to return the result.| 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci**Error codes** 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci| ID| Error Message | 249e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 250e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 251e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci**Example** 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci```ts 256e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 257e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_cilet file = ['file://data/print/a.png', 'file://data/print/b.png']; 260e41f4b71Sopenharmony_ciprint.print(file).then((printTask: print.PrintTask) => { 261e41f4b71Sopenharmony_ci printTask.off('succeed', () => { 262e41f4b71Sopenharmony_ci console.log('unregister state succeed'); 263e41f4b71Sopenharmony_ci }) 264e41f4b71Sopenharmony_ci // ... 265e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 266e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 267e41f4b71Sopenharmony_ci}) 268e41f4b71Sopenharmony_ci``` 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci### off 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_cioff(type: 'fail', callback?: Callback<void>): void 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ciUnregisters the listener for the print task blocking event. This API uses a callback to return the result. 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci**Parameters** 281e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 282e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 283e41f4b71Sopenharmony_ci| type | string | Yes| Listening type.<br>The value is fixed at **'fail'**,<br>indicating failure of the print task.| 284e41f4b71Sopenharmony_ci| callback | Callback<void> | No| Callback used to return the result.| 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci**Error codes** 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci| ID| Error Message | 291e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 292e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 293e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci**Example** 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci```ts 298e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 299e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_cilet file = ['file://data/print/a.png', 'file://data/print/b.png']; 302e41f4b71Sopenharmony_ciprint.print(file).then((printTask: print.PrintTask) => { 303e41f4b71Sopenharmony_ci printTask.off('fail', () => { 304e41f4b71Sopenharmony_ci console.log('unregister state fail'); 305e41f4b71Sopenharmony_ci }) 306e41f4b71Sopenharmony_ci // ... 307e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 308e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 309e41f4b71Sopenharmony_ci}) 310e41f4b71Sopenharmony_ci``` 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci### off 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_cioff(type: 'cancel', callback?: Callback<void>): void 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ciUnregisters the listener for the print task blocking event. This API uses a callback to return the result. 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci**Parameters** 323e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 324e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 325e41f4b71Sopenharmony_ci| type | string | Yes| Listening type.<br>The value is fixed at **'cancel'**,<br>indicating canceling of the print task.| 326e41f4b71Sopenharmony_ci| callback | Callback<void> | No| Callback used to return the result.| 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci**Error codes** 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci| ID| Error Message | 333e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 334e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 335e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci**Example** 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci```ts 340e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 341e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_cilet file = ['file://data/print/a.png', 'file://data/print/b.png']; 344e41f4b71Sopenharmony_ciprint.print(file).then((printTask: print.PrintTask) => { 345e41f4b71Sopenharmony_ci printTask.off('cancel', () => { 346e41f4b71Sopenharmony_ci console.log('unregister state cancel'); 347e41f4b71Sopenharmony_ci }) 348e41f4b71Sopenharmony_ci // ... 349e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 350e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 351e41f4b71Sopenharmony_ci}) 352e41f4b71Sopenharmony_ci``` 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci## PrintDocumentAdapter<sup>11+</sup> 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ciProvides information about the document to print. This API must be implemented by a third-party application. 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci### onStartLayoutWrite 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_cionStartLayoutWrite(jobId: string, oldAttrs: PrintAttributes, newAttrs: PrintAttributes, fd: number, writeResultCallback: (jobId: string, writeResult: PrintFileCreationState) => void): void 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ciUpdates the file to be printed. This API uses **writeResultCallback** as the callback. 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 365e41f4b71Sopenharmony_ci 366e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci**Parameters** 369e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 370e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 371e41f4b71Sopenharmony_ci| jobId | string | Yes| ID of the print job.| 372e41f4b71Sopenharmony_ci| oldAttrs | PrintAttributes | Yes| Old print attributes.| 373e41f4b71Sopenharmony_ci| newAttrs | PrintAttributes | Yes| New print attributes.| 374e41f4b71Sopenharmony_ci| fd | number | Yes| File descriptor.| 375e41f4b71Sopenharmony_ci| writeResultCallback | (jobId: string, writeResult: PrintFileCreationState) | Yes| Callback used to return the result.| 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci**Error codes** 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci| ID| Error Message | 382e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 383e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 384e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci**Example** 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci```ts 389e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 390e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ciclass MyPrintDocumentAdapter implements print.PrintDocumentAdapter { 393e41f4b71Sopenharmony_ci onStartLayoutWrite(jobId: string, oldAttrs: print.PrintAttributes, newAttrs: print.PrintAttributes, fd: number, 394e41f4b71Sopenharmony_ci writeResultCallback: (jobId: string, writeResult: print.PrintFileCreationState) => void) { 395e41f4b71Sopenharmony_ci writeResultCallback(jobId, print.PrintFileCreationState.PRINT_FILE_CREATED); 396e41f4b71Sopenharmony_ci }; 397e41f4b71Sopenharmony_ci onJobStateChanged(jobId: string, state: print.PrintDocumentAdapterState) { 398e41f4b71Sopenharmony_ci if (state == print.PrintDocumentAdapterState.PREVIEW_DESTROY) { 399e41f4b71Sopenharmony_ci console.log('PREVIEW_DESTROY'); 400e41f4b71Sopenharmony_ci } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_SUCCEED) { 401e41f4b71Sopenharmony_ci console.log('PRINT_TASK_SUCCEED'); 402e41f4b71Sopenharmony_ci } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_FAIL) { 403e41f4b71Sopenharmony_ci console.log('PRINT_TASK_FAIL'); 404e41f4b71Sopenharmony_ci } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_CANCEL) { 405e41f4b71Sopenharmony_ci console.log('PRINT_TASK_CANCEL'); 406e41f4b71Sopenharmony_ci } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_BLOCK) { 407e41f4b71Sopenharmony_ci console.log('PRINT_TASK_BLOCK'); 408e41f4b71Sopenharmony_ci } 409e41f4b71Sopenharmony_ci } 410e41f4b71Sopenharmony_ci} 411e41f4b71Sopenharmony_ci``` 412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci### onJobStateChanged 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_cionJobStateChanged(jobId: string, state: PrintDocumentAdapterState): void 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ciRegisters a listener for print job state changes. 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 422e41f4b71Sopenharmony_ci 423e41f4b71Sopenharmony_ci**Parameters** 424e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 425e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 426e41f4b71Sopenharmony_ci| jobId | string | Yes| ID of the print job.| 427e41f4b71Sopenharmony_ci| state | PrintDocumentAdapterState | Yes| New state of the print job.| 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci**Error codes** 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci| ID| Error Message | 434e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 435e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 436e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ci**Example** 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci```ts 441e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 442e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ciclass MyPrintDocumentAdapter implements print.PrintDocumentAdapter { 445e41f4b71Sopenharmony_ci onStartLayoutWrite(jobId: string, oldAttrs: print.PrintAttributes, newAttrs: print.PrintAttributes, fd: number, 446e41f4b71Sopenharmony_ci writeResultCallback: (jobId: string, writeResult: print.PrintFileCreationState) => void) { 447e41f4b71Sopenharmony_ci writeResultCallback(jobId, print.PrintFileCreationState.PRINT_FILE_CREATED); 448e41f4b71Sopenharmony_ci }; 449e41f4b71Sopenharmony_ci onJobStateChanged(jobId: string, state: print.PrintDocumentAdapterState) { 450e41f4b71Sopenharmony_ci if (state == print.PrintDocumentAdapterState.PREVIEW_DESTROY) { 451e41f4b71Sopenharmony_ci console.log('PREVIEW_DESTROY'); 452e41f4b71Sopenharmony_ci } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_SUCCEED) { 453e41f4b71Sopenharmony_ci console.log('PRINT_TASK_SUCCEED'); 454e41f4b71Sopenharmony_ci } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_FAIL) { 455e41f4b71Sopenharmony_ci console.log('PRINT_TASK_FAIL'); 456e41f4b71Sopenharmony_ci } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_CANCEL) { 457e41f4b71Sopenharmony_ci console.log('PRINT_TASK_CANCEL'); 458e41f4b71Sopenharmony_ci } else if (state == print.PrintDocumentAdapterState.PRINT_TASK_BLOCK) { 459e41f4b71Sopenharmony_ci console.log('PRINT_TASK_BLOCK'); 460e41f4b71Sopenharmony_ci } 461e41f4b71Sopenharmony_ci } 462e41f4b71Sopenharmony_ci} 463e41f4b71Sopenharmony_ci``` 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci## print 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ciprint(files: Array<string>, callback: AsyncCallback<PrintTask>): void 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ciPrints files. This API uses an asynchronous callback to return the result. 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci**Parameters** 476e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 477e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 478e41f4b71Sopenharmony_ci| files | Array<string> | Yes| List of files to print. Images (in .jpg, .png, .gif, .bmp, or .webp format) and PDF files are supported. Before a system application passes in the URI, it needs to call the **uriPermissionManager.grantUriPermission()** API to authorize the print application. This API is a system API. [print](#print11-2) is recommended for third-party application.| 479e41f4b71Sopenharmony_ci| callback | AsyncCallback<PrintTask> | Yes| Callback used to return the result.| 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**Error codes** 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci| ID| Error Message | 486e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 487e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 488e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ci**Example** 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_ci```ts 493e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 494e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 495e41f4b71Sopenharmony_ci 496e41f4b71Sopenharmony_ci// Pass in the URIs of the files. 497e41f4b71Sopenharmony_cilet files = ['file://data/print/a.png', 'file://data/print/b.png']; 498e41f4b71Sopenharmony_ci// Alternatively, pass in the fd. 499e41f4b71Sopenharmony_ci//let files = ['fd://1', 'fd://2']; 500e41f4b71Sopenharmony_ciprint.print(files, (err: BusinessError, printTask: print.PrintTask) => { 501e41f4b71Sopenharmony_ci if (err) { 502e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(err)); 503e41f4b71Sopenharmony_ci } else { 504e41f4b71Sopenharmony_ci printTask.on('succeed', () => { 505e41f4b71Sopenharmony_ci console.log('print state is succeed'); 506e41f4b71Sopenharmony_ci }) 507e41f4b71Sopenharmony_ci // ... 508e41f4b71Sopenharmony_ci } 509e41f4b71Sopenharmony_ci}) 510e41f4b71Sopenharmony_ci``` 511e41f4b71Sopenharmony_ci 512e41f4b71Sopenharmony_ci## print 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ciprint(files: Array<string>): Promise<PrintTask> 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ciPrints files. This API uses a promise to return the result. 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ci**Parameters** 523e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 524e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 525e41f4b71Sopenharmony_ci| files | Array<string> | Yes| List of files to print. Images (in .jpg, .png, .gif, .bmp, or .webp format) and PDF files are supported. Before a system application passes in the URI, it needs to call the **uriPermissionManager.grantUriPermission()** API to authorize the print application. This API is a system API. [print](#print11-2) is recommended for third-party application.| 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ci**Return value** 528e41f4b71Sopenharmony_ci| **Type**| **Description**| 529e41f4b71Sopenharmony_ci| -------- | -------- | 530e41f4b71Sopenharmony_ci| Promise<PrintTask> | Print result.| 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci**Error codes** 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci| ID| Error Message | 537e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 538e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 539e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 540e41f4b71Sopenharmony_ci 541e41f4b71Sopenharmony_ci**Example** 542e41f4b71Sopenharmony_ci 543e41f4b71Sopenharmony_ci```ts 544e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 545e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_ci// Pass in the URIs of the files. 548e41f4b71Sopenharmony_cilet files = ['file://data/print/a.png', 'file://data/print/b.png']; 549e41f4b71Sopenharmony_ci// Alternatively, pass in the fd. 550e41f4b71Sopenharmony_ci//let files = ['fd://1', 'fd://2']; 551e41f4b71Sopenharmony_ciprint.print(files).then((printTask: print.PrintTask) => { 552e41f4b71Sopenharmony_ci printTask.on('succeed', () => { 553e41f4b71Sopenharmony_ci console.log('print state is succeed'); 554e41f4b71Sopenharmony_ci }) 555e41f4b71Sopenharmony_ci // ... 556e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 557e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 558e41f4b71Sopenharmony_ci}) 559e41f4b71Sopenharmony_ci``` 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci## print<sup>11+</sup> 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ciprint(files: Array<string>, context: Context, callback: AsyncCallback<PrintTask>): void 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ciPrints files. This API uses an asynchronous callback to return the result. 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci**Parameters** 572e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 573e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 574e41f4b71Sopenharmony_ci| files | Array<string> | Yes| List of files to print. Images (in .jpg, .png, .gif, .bmp, or .webp format) and PDF files are supported. Before a system application passes in the URI, it needs to call the **uriPermissionManager.grantUriPermission()** API to authorize the print application. This API is a system API. [print](#print11-2) is recommended for third-party application.| 575e41f4b71Sopenharmony_ci| context | Context | Yes| UIAbility context used to start printing.| 576e41f4b71Sopenharmony_ci| callback | AsyncCallback<PrintTask> | Yes| Callback used to return the result.| 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_ci**Error codes** 579e41f4b71Sopenharmony_ci 580e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_ci| ID| Error Message | 583e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 584e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 585e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ci**Example** 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ci```ts 590e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 591e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_ci// Pass in the URIs of the files. 594e41f4b71Sopenharmony_cilet files = ['file://data/print/a.png', 'file://data/print/b.png']; 595e41f4b71Sopenharmony_ci// Alternatively, pass in the fd. 596e41f4b71Sopenharmony_ci//let files = ['fd://1', 'fd://2']; 597e41f4b71Sopenharmony_cilet context = getContext(this); 598e41f4b71Sopenharmony_ciprint.print(files, context, (err: BusinessError, printTask: print.PrintTask) => { 599e41f4b71Sopenharmony_ci if (err) { 600e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(err)); 601e41f4b71Sopenharmony_ci } else { 602e41f4b71Sopenharmony_ci printTask.on('succeed', () => { 603e41f4b71Sopenharmony_ci console.log('print state is succeed'); 604e41f4b71Sopenharmony_ci }) 605e41f4b71Sopenharmony_ci // ... 606e41f4b71Sopenharmony_ci } 607e41f4b71Sopenharmony_ci}) 608e41f4b71Sopenharmony_ci``` 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci## print<sup>11+</sup> 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ciprint(files: Array<string>, context: Context): Promise<PrintTask> 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ciPrints files. This API uses a promise to return the result. 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 619e41f4b71Sopenharmony_ci 620e41f4b71Sopenharmony_ci**Parameters** 621e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 622e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 623e41f4b71Sopenharmony_ci| files | Array<string> | Yes| List of files to print. Images (in .jpg, .png, .gif, .bmp, or .webp format) and PDF files are supported. Before a system application passes in the URI, it needs to call the **uriPermissionManager.grantUriPermission()** API to authorize the print application. This API is a system API. [print](#print11-2) is recommended for third-party application.| 624e41f4b71Sopenharmony_ci| context | Context | Yes| UIAbility context used to start printing.| 625e41f4b71Sopenharmony_ci 626e41f4b71Sopenharmony_ci**Return value** 627e41f4b71Sopenharmony_ci| **Type**| **Description**| 628e41f4b71Sopenharmony_ci| -------- | -------- | 629e41f4b71Sopenharmony_ci| Promise<PrintTask> | Print result.| 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ci**Error codes** 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 634e41f4b71Sopenharmony_ci 635e41f4b71Sopenharmony_ci| ID| Error Message | 636e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 637e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 638e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ci**Example** 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci```ts 643e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 644e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ci// Pass in the URIs of the files. 647e41f4b71Sopenharmony_cilet files = ['file://data/print/a.png', 'file://data/print/b.png']; 648e41f4b71Sopenharmony_ci// Alternatively, pass in the fd. 649e41f4b71Sopenharmony_ci//let files = ['fd://1', 'fd://2']; 650e41f4b71Sopenharmony_cilet context = getContext(this); 651e41f4b71Sopenharmony_ciprint.print(files, context).then((printTask: print.PrintTask) => { 652e41f4b71Sopenharmony_ci printTask.on('succeed', () => { 653e41f4b71Sopenharmony_ci console.log('print state is succeed'); 654e41f4b71Sopenharmony_ci }) 655e41f4b71Sopenharmony_ci // ... 656e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 657e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 658e41f4b71Sopenharmony_ci}) 659e41f4b71Sopenharmony_ci``` 660e41f4b71Sopenharmony_ci 661e41f4b71Sopenharmony_ci## print<sup>11+</sup> 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ciprint(jobName: string, printAdapter: PrintDocumentAdapter, printAttributes: PrintAttributes, context: Context): Promise<PrintTask> 664e41f4b71Sopenharmony_ci 665e41f4b71Sopenharmony_ciPrints a file. This API uses a promise to return the result. 666e41f4b71Sopenharmony_ci 667e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRINT 668e41f4b71Sopenharmony_ci 669e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci**Parameters** 672e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 673e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 674e41f4b71Sopenharmony_ci| jobName | string | Yes| Name of the file to print.| 675e41f4b71Sopenharmony_ci| printAdapter | PrintDocumentAdapter | Yes| Feature implemented by a third-party application.| 676e41f4b71Sopenharmony_ci| printAttributes | PrintAttributes | Yes| Print attributes.| 677e41f4b71Sopenharmony_ci| context | Context | Yes| UIAbility context used to start printing.| 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ci**Return value** 680e41f4b71Sopenharmony_ci| **Type**| **Description**| 681e41f4b71Sopenharmony_ci| -------- | -------- | 682e41f4b71Sopenharmony_ci| Promise<PrintTask> | Print result.| 683e41f4b71Sopenharmony_ci 684e41f4b71Sopenharmony_ci**Error codes** 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ciFor details about the error codes, see [Error Codes of the Print Service](./errorcode-print.md). 687e41f4b71Sopenharmony_ci 688e41f4b71Sopenharmony_ci| ID| Error Message | 689e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | 690e41f4b71Sopenharmony_ci| 201 | the application does not have permission to call this function. | 691e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci**Example** 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci```ts 696e41f4b71Sopenharmony_ciimport { print } from '@kit.BasicServicesKit'; 697e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_cilet jobName : string = "jobName"; 700e41f4b71Sopenharmony_cilet printAdapter : print.PrintDocumentAdapter | null = null; 701e41f4b71Sopenharmony_cilet printAttributes : print.PrintAttributes = { 702e41f4b71Sopenharmony_ci copyNumber: 1, 703e41f4b71Sopenharmony_ci pageRange: { 704e41f4b71Sopenharmony_ci startPage: 0, 705e41f4b71Sopenharmony_ci endPage: 5, 706e41f4b71Sopenharmony_ci pages: [] 707e41f4b71Sopenharmony_ci }, 708e41f4b71Sopenharmony_ci pageSize: print.PrintPageType.PAGE_ISO_A3, 709e41f4b71Sopenharmony_ci directionMode: print.PrintDirectionMode.DIRECTION_MODE_AUTO, 710e41f4b71Sopenharmony_ci colorMode: print.PrintColorMode.COLOR_MODE_MONOCHROME, 711e41f4b71Sopenharmony_ci duplexMode: print.PrintDuplexMode.DUPLEX_MODE_NONE 712e41f4b71Sopenharmony_ci} 713e41f4b71Sopenharmony_cilet context = getContext(); 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ciprint.print(jobName, printAdapter, printAttributes, context).then((printTask: print.PrintTask) => { 716e41f4b71Sopenharmony_ci printTask.on('succeed', () => { 717e41f4b71Sopenharmony_ci console.log('print state is succeed'); 718e41f4b71Sopenharmony_ci }) 719e41f4b71Sopenharmony_ci // ... 720e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 721e41f4b71Sopenharmony_ci console.log('print err ' + JSON.stringify(error)); 722e41f4b71Sopenharmony_ci}) 723e41f4b71Sopenharmony_ci``` 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_ci## PrintAttributes<sup>11+</sup> 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ciDefines the print attributes. 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 730e41f4b71Sopenharmony_ci 731e41f4b71Sopenharmony_ci**Attributes** 732e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 733e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 734e41f4b71Sopenharmony_ci| copyNumber | number | No| Copy of the file list.| 735e41f4b71Sopenharmony_ci| pageRange | PrintPageRange | No| Range of pages to print.| 736e41f4b71Sopenharmony_ci| pageSize | PrintPageSize \| PrintPageType | No| Page size of the files to print.| 737e41f4b71Sopenharmony_ci| directionMode | PrintDirectionMode | No| Print direction mode.| 738e41f4b71Sopenharmony_ci| colorMode | PrintColorMode | No| Color mode of the files to print.| 739e41f4b71Sopenharmony_ci| duplexMode | PrintDuplexMode | No| Duplex mode of the files to print.| 740e41f4b71Sopenharmony_ci 741e41f4b71Sopenharmony_ci## PrintPageRange<sup>11+</sup> 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_ciDefines the print range. 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci**Attributes** 748e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 749e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 750e41f4b71Sopenharmony_ci| startPage | number | No| Start page.| 751e41f4b71Sopenharmony_ci| endPage | number | No| End page.| 752e41f4b71Sopenharmony_ci| pages | Array<number> | No| Discrete pages.| 753e41f4b71Sopenharmony_ci 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci## PrintPageSize<sup>11+</sup> 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ciDefines the size of the printed page. 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci**Attributes** 762e41f4b71Sopenharmony_ci| **Name**| **Type**| **Mandatory**| **Description**| 763e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 764e41f4b71Sopenharmony_ci| id | string | Yes| Page size ID.| 765e41f4b71Sopenharmony_ci| name | string | Yes| Page size name.| 766e41f4b71Sopenharmony_ci| width | number | Yes| Page width, in millimeters.| 767e41f4b71Sopenharmony_ci| height | number | Yes| Page height, in millimeters.| 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ci## PrintDirectionMode<sup>11+</sup> 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_ciEnumerates the print direction modes. 774e41f4b71Sopenharmony_ci 775e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 776e41f4b71Sopenharmony_ci 777e41f4b71Sopenharmony_ci| **Name**| **Value**| **Description**| 778e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 779e41f4b71Sopenharmony_ci| DIRECTION_MODE_AUTO | 0 | Automatic.| 780e41f4b71Sopenharmony_ci| DIRECTION_MODE_PORTRAIT | 1 | Portrait mode.| 781e41f4b71Sopenharmony_ci| DIRECTION_MODE_LANDSCAPE | 2 | Landscape mode.| 782e41f4b71Sopenharmony_ci 783e41f4b71Sopenharmony_ci## PrintColorMode<sup>11+</sup> 784e41f4b71Sopenharmony_ci 785e41f4b71Sopenharmony_ciEnumerates the color modes. 786e41f4b71Sopenharmony_ci 787e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 788e41f4b71Sopenharmony_ci 789e41f4b71Sopenharmony_ci| **Name**| **Value**| **Description**| 790e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 791e41f4b71Sopenharmony_ci| COLOR_MODE_MONOCHROME | 0 | Black and white.| 792e41f4b71Sopenharmony_ci| COLOR_MODE_COLOR | 1 | Color.| 793e41f4b71Sopenharmony_ci 794e41f4b71Sopenharmony_ci## PrintDuplexMode<sup>11+</sup> 795e41f4b71Sopenharmony_ci 796e41f4b71Sopenharmony_ciEnumerates the duplex modes. 797e41f4b71Sopenharmony_ci 798e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ci| **Name**| **Value**| **Description**| 801e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 802e41f4b71Sopenharmony_ci| DUPLEX_MODE_NONE | 0 | Simplex (single-sided).| 803e41f4b71Sopenharmony_ci| DUPLEX_MODE_LONG_EDGE | 1 | Duplex (double-sided) with flipping on long edge.| 804e41f4b71Sopenharmony_ci| DUPLEX_MODE_SHORT_EDGE | 2 | Duplex (double-sided) with flipping on short edge.| 805e41f4b71Sopenharmony_ci 806e41f4b71Sopenharmony_ci## PrintPageType<sup>11+</sup> 807e41f4b71Sopenharmony_ci 808e41f4b71Sopenharmony_ciEnumerates the print page types. 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 811e41f4b71Sopenharmony_ci 812e41f4b71Sopenharmony_ci| **Name**| **Value**| **Description**| 813e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 814e41f4b71Sopenharmony_ci| PAGE_ISO_A3 | 0 | A3.| 815e41f4b71Sopenharmony_ci| PAGE_ISO_A4 | 1 | A4.| 816e41f4b71Sopenharmony_ci| PAGE_ISO_A5 | 2 | A5.| 817e41f4b71Sopenharmony_ci| PAGE_JIS_B5 | 3 | B5.| 818e41f4b71Sopenharmony_ci| PAGE_ISO_C5 | 4 | C5.| 819e41f4b71Sopenharmony_ci| PAGE_ISO_DL | 5 | DL.| 820e41f4b71Sopenharmony_ci| PAGE_LETTER | 6 | Letter.| 821e41f4b71Sopenharmony_ci| PAGE_LEGAL | 7 | Legal.| 822e41f4b71Sopenharmony_ci| PAGE_PHOTO_4X6 | 8 | 4 x 6 photo paper.| 823e41f4b71Sopenharmony_ci| PAGE_PHOTO_5X7 | 9 | 5 x 7 photo paper.| 824e41f4b71Sopenharmony_ci| PAGE_INT_DL_ENVELOPE | 10 | International envelope DL.| 825e41f4b71Sopenharmony_ci| PAGE_B_TABLOID | 11 | B Tabloid.| 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_ci## PrintDocumentAdapterState<sup>11+</sup> 828e41f4b71Sopenharmony_ci 829e41f4b71Sopenharmony_ciEnumerates the print job states. 830e41f4b71Sopenharmony_ci 831e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 832e41f4b71Sopenharmony_ci 833e41f4b71Sopenharmony_ci| **Name**| **Value**| **Description**| 834e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 835e41f4b71Sopenharmony_ci| PREVIEW_DESTROY | 0 | The preview fails.| 836e41f4b71Sopenharmony_ci| PRINT_TASK_SUCCEED | 1 | The print job is successful.| 837e41f4b71Sopenharmony_ci| PRINT_TASK_FAIL | 2 | The print job failed.| 838e41f4b71Sopenharmony_ci| PRINT_TASK_CANCEL | 3 | The print job is canceled.| 839e41f4b71Sopenharmony_ci| PRINT_TASK_BLOCK | 4 | The print job is blocked.| 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ci## PrintFileCreationState<sup>11+</sup> 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ciEnumerates the print file creation status. 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Print.PrintFramework 846e41f4b71Sopenharmony_ci 847e41f4b71Sopenharmony_ci| **Name**| **Value**| **Description**| 848e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 849e41f4b71Sopenharmony_ci| PRINT_FILE_CREATED | 0 | The print file is created successfully.| 850e41f4b71Sopenharmony_ci| PRINT_FILE_CREATION_FAILED | 1 | The print file fails to be created.| 851e41f4b71Sopenharmony_ci| PRINT_FILE_CREATED_UNRENDERED | 2 | The print file is successfully created but not rendered.| 852