ohprint.h
Overview
Declares APIs for discovering and connecting to printers, printing files, and querying the list of added printers and printer information.
File to include: <BasicServicesKit/ohprint.h>
Library: libohprint.so
System capability: SystemCapability.Print.PrintFramework
Since: 12
Related module: OH_Print
Summary
Structs
| Name | typedef Keyword | Description |
|---|---|---|
| Print_StringList | Print_StringList | Defines a struct for the string list. |
| Print_Property | Print_Property | Defines a struct for the printer property. |
| Print_PropertyList | Print_PropertyList | Defines a struct for the printer property list. |
| Print_Resolution | Print_Resolution | Defines a struct for the printing resolution in dpi. |
| Print_Margin | Print_Margin | Defines a struct for the page margin to print. |
| Print_PageSize | Print_PageSize | Defines a struct for the page size. |
| Print_PrinterCapability | Print_PrinterCapability | Defines a struct for the printer capabilities. |
| Print_DefaultValue | Print_DefaultValue | Defines a struct for the default property value. |
| Print_PrinterInfo | Print_PrinterInfo | Defines a struct for the printer information. |
| Print_PrintJob | Print_PrintJob | Defines a struct for the print job. |
| Print_Range | Print_Range | Defines a struct for the page range to print. |
| Print_PrintAttributes | Print_PrintAttributes | Defines a struct for the print attributes. |
| Print_PrintDocCallback | Print_PrintDocCallback | Defines a struct for the print job status callback. |
Enums
| Name | typedef Keyword | Description |
|---|---|---|
| Print_ErrorCode | Print_ErrorCode | Enumerates the error codes. |
| Print_PrinterState | Print_PrinterState | Enumerates the printer states. |
| Print_DiscoveryEvent | Print_DiscoveryEvent | Enumerates the printer discovery events. |
| Print_PrinterEvent | Print_PrinterEvent | Enumerates the printer change events. |
| Print_DuplexMode | Print_DuplexMode | Enumerates the duplex modes. |
| Print_ColorMode | Print_ColorMode | Enumerates the color modes. |
| Print_OrientationMode | Print_OrientationMode | Enumerates the orientation modes. |
| Print_Quality | Print_Quality | Enumerates the print qualities. |
| Print_DocumentFormat | Print_DocumentFormat | Enumerates the MIME types. |
| Print_JobDocAdapterState | Print_JobDocAdapterState | Enumerates the print job adapter states. |
| OH_Print_JobState | OH_Print_JobState | Enumerates the print job states. |
Functions
Enum Description
Print_ErrorCode
enum Print_ErrorCode
Description
Enumerates the error codes.
Since: 12
| Enum Item | Description |
|---|---|
| PRINT_ERROR_NONE = 0 | Operation successful. |
| PRINT_ERROR_NO_PERMISSION = 201 | Permission verification failed. |
| PRINT_ERROR_INVALID_PARAMETER = 401 | Invalid parameter. |
| PRINT_ERROR_GENERIC_FAILURE = 24300001 | Internal error. |
| PRINT_ERROR_RPC_FAILURE = 24300002 | RPC communication error. |
| PRINT_ERROR_SERVER_FAILURE = 24300003 | Server error. |
| PRINT_ERROR_INVALID_EXTENSION = 24300004 | Invalid extension. |
| PRINT_ERROR_INVALID_PRINTER = 24300005 | Invalid printer. |
| PRINT_ERROR_INVALID_PRINT_JOB = 24300006 | Invalid print job. |
| PRINT_ERROR_FILE_IO = 24300007 | File I/O error. |
| PRINT_ERROR_UNKNOWN = 24300255 | Unknown error. |
Print_PrinterState
enum Print_PrinterState
Description
Enumerates the printer states.
Since: 12
| Enum Item | Description |
|---|---|
| PRINTER_IDLE | The printer is idle. |
| PRINTER_BUSY | The printer is busy. |
| PRINTER_UNAVAILABLE | The printer is unavailable. |
Print_DiscoveryEvent
enum Print_DiscoveryEvent
Description
Enumerates the printer discovery events.
Since: 12
| Enum Item | Description |
|---|---|
| PRINTER_DISCOVERED = 0 | Printer discovered. |
| PRINTER_LOST = 1 | Printer lost. |
| PRINTER_CONNECTING = 2 | Printer connecting. |
| PRINTER_CONNECTED = 3 | Printer connected. |
Print_PrinterEvent
enum Print_PrinterEvent
Description
Enumerates the printer change events.
Since: 12
| Enum Item | Description |
|---|---|
| PRINTER_ADDED = 0 | Printer added. |
| PRINTER_DELETED = 1 | Printer deleted. |
| PRINTER_STATE_CHANGED = 2 | Printer changed. |
| PRINTER_INFO_CHANGED = 3 | Printer information changed. |
Print_DuplexMode
enum Print_DuplexMode
Description
Enumerates the duplex modes.
Since: 12
| Enum Item | Description |
|---|---|
| DUPLEX_MODE_ONE_SIDED = 0 | Single-sided mode. |
| DUPLEX_MODE_TWO_SIDED_LONG_EDGE = 1 | Duplex mode with flipping on long edge. |
| DUPLEX_MODE_TWO_SIDED_SHORT_EDGE = 2 | Duplex mode with flipping on short edge. |
Print_ColorMode
enum Print_ColorMode
Description
Enumerates the color modes.
Since: 12
| Enum Item | Description |
|---|---|
| COLOR_MODE_MONOCHROME = 0 | B/W mode. |
| COLOR_MODE_COLOR = 1 | Color mode. |
| COLOR_MODE_AUTO = 2 | Auto mode. |
Print_OrientationMode
enum Print_OrientationMode
Description
Enumerates the orientation modes.
Since: 12
| Enum Item | Description |
|---|---|
| ORIENTATION_MODE_PORTRAIT = 0 | Portrait mode. |
| ORIENTATION_MODE_LANDSCAPE = 1 | Landscape mode. |
| ORIENTATION_MODE_REVERSE_LANDSCAPE = 2 | Reverse landscape mode. |
| ORIENTATION_MODE_REVERSE_PORTRAIT = 3 | Reverse portrait mode. |
| ORIENTATION_MODE_NONE = 4 | Not specified. |
Print_Quality
enum Print_Quality
Description
Enumerates the print qualities.
Since: 12
| Enum Item | Description |
|---|---|
| PRINT_QUALITY_DRAFT = 3 | Draft. |
| PRINT_QUALITY_NORMAL = 4 | Normal quality. |
| PRINT_QUALITY_HIGH = 5 | High quality. |
Print_DocumentFormat
enum Print_DocumentFormat
Description
Enumerates the MIME types.
Since: 12
| Enum Item | Description |
|---|---|
| DOCUMENT_FORMAT_AUTO | application/octet-stream. |
| DOCUMENT_FORMAT_JPEG | image/jpeg. |
| DOCUMENT_FORMAT_PDF | application/pdf. |
| DOCUMENT_FORMAT_POSTSCRIPT | application/postscript. |
| DOCUMENT_FORMAT_TEXT | text/plain. |
Print_JobDocAdapterState
enum Print_JobDocAdapterState
Description
Enumerates the print job adapter states.
Since: 13
| Enum Item | Description |
|---|---|
| PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY = 0 | Print job preview destroyed. |
| PRINT_DOC_ADAPTER_PRINT_TASK_SUCCEED = 1 | Successful print job. |
| PRINT_DOC_ADAPTER_PRINT_TASK_FAIL = 2 | Print job failed. |
| PRINT_DOC_ADAPTER_PRINT_TASK_CANCEL = 3 | Print job canceled. |
| PRINT_DOC_ADAPTER_PRINT_TASK_BLOCK = 4 | Print job blocked. |
| PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY_FOR_CANCELED = 5 | Print job preview destroyed due to cancellation. |
| PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY_FOR_STARTED = 6 | Print job preview destroyed due to startup. |
OH_Print_JobState
enum OH_Print_JobState
Description
Enumerates the print job states.
Since: 24
| Name | Value | Description |
|---|---|---|
| OH_PRINT_JOB_SUCCEED | 0 | Successful print job. |
| OH_PRINT_JOB_FAIL | 1 | Print job failed. |
| OH_PRINT_JOB_CANCEL | 2 | Print job canceled. |
| OH_PRINT_JOB_BLOCK | 3 | Print job blocked. |
Function Description
Print_WriteResultCallback()
typedef void(*Print_WriteResultCallback)(const char *jobId, uint32_t code)
Description
Defines a callback used to return the file write-back result.
Since: 13
Parameters
| Name | Description |
|---|---|
| const char *jobId | Pointer to the print job ID. |
| uint32_t code | File write-back result. |
Print_OnStartLayoutWrite()
typedef void(*Print_OnStartLayoutWrite)(const char *jobId, uint32_t fd, const Print_PrintAttributes *oldAttrs, const Print_PrintAttributes *newAttrs, Print_WriteResultCallback writeCallback)
Description
Defines a callback to be invoked when the file write-back starts.
Since: 13
Parameters
| Name | Description |
|---|---|
| const char *jobId | Pointer to the print job ID. |
| uint32_t fd | File descriptor to write. |
| const Print_PrintAttributes *oldAttrs | Pointer to the old attribute. |
| const Print_PrintAttributes *newAttrs | Pointer to the new attribute. |
| Print_WriteResultCallback writeCallback | Defines a callback used to return the file write-back result. |
Print_OnJobStateChanged()
typedef void(*Print_OnJobStateChanged)(const char *jobId, uint32_t state)
Description
Defines a callback to be invoked when the print job state changes.
Since: 13
Parameters
| Name | Description |
|---|---|
| const char *jobId | Pointer to the print job ID. |
| uint32_t state | Print job state. |
Print_PrinterDiscoveryCallback()
typedef void (*Print_PrinterDiscoveryCallback)(Print_DiscoveryEvent event, const Print_PrinterInfo *printerInfo)
Description
Defines a callback used to return the discovered printers.
Since: 12
Parameters
| Name | Description |
|---|---|
| Print_DiscoveryEvent event | Printer discovery event. |
| const Print_PrinterInfo *printerInfo | Printer information when the discovery event occurs. |
Print_PrinterChangeCallback()
typedef void (*Print_PrinterChangeCallback)(Print_PrinterEvent event, const Print_PrinterInfo *printerInfo)
Description
Defines a callback to be invoked when a printer is changed.
Since: 12
Parameters
| Name | Description |
|---|---|
| Print_PrinterEvent event | Printer change event during the running of the print service. |
| const Print_PrinterInfo *printerInfo | Printer information when the change event occurs. |
OH_Print_Init()
Print_ErrorCode OH_Print_Init()
Description
Checks and starts the print service, initializes the print client, and connects it with the print service.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_RPC_FAILURE: Failed to connect to the print service. PRINT_ERROR_SERVER_FAILURE: Failed to start the CUPS service. |
OH_Print_Release()
Print_ErrorCode OH_Print_Release()
Description
Disconnects from the print service, dismisses the previous callback, and releases the print client resources.
System capability: SystemCapability.Print.PrintFramework
Since: 12
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. Currently, no other error codes will be returned. |
OH_Print_StartPrinterDiscovery()
Print_ErrorCode OH_Print_StartPrinterDiscovery(Print_PrinterDiscoveryCallback callback)
Description
Starts printer discovery.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Parameters
| Name | Description |
|---|---|
| Print_PrinterDiscoveryCallback callback | Print_PrinterDiscoveryCallback to be invoked when a printer is discovered. |
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_RPC_FAILURE: Failed to connect to the print service. PRINT_ERROR_SERVER_FAILURE: Failed to query the print extension list from the BMS. PRINT_ERROR_INVALID_EXTENSION: No available print extension is found. |
OH_Print_StopPrinterDiscovery()
Print_ErrorCode OH_Print_StopPrinterDiscovery()
Description
Stops printer discovery.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_RPC_FAILURE: Failed to connect to the print service. |
OH_Print_ConnectPrinter()
Print_ErrorCode OH_Print_ConnectPrinter(const char *printerId)
Description
Connects to a printer by the printer ID.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Parameters
| Name | Description |
|---|---|
| const char *printerId | Pointer to the ID of the printer to be connected. |
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_RPC_FAILURE: Failed to connect to the print service. PRINT_ERROR_INVALID_PRINTER: Printer does not exist in the list of discovered printers. PRINT_ERROR_SERVER_FAILURE: Failed to find the printer extension. |
OH_Print_StartPrintJob()
Print_ErrorCode OH_Print_StartPrintJob(const Print_PrintJob *printJob)
Description
Starts a print job.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Parameters
| Name | Description |
|---|---|
| const Print_PrintJob *printJob | Pointer to the Print_PrintJob instance of the specified print job information. |
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_RPC_FAILURE: Failed to connect to the print service. PRINT_ERROR_INVALID_PRINTER: Printer does not exist in the list of connected printers. PRINT_ERROR_SERVER_FAILURE: Failed to create a print job in the print service. PRINT_ERROR_INVALID_PRINT_JOB: Failed to find the specified task in the task queue. |
OH_Print_RegisterPrinterChangeListener()
Print_ErrorCode OH_Print_RegisterPrinterChangeListener(Print_PrinterChangeCallback callback)
Description
Registers a listener for printer changes.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Parameters
| Name | Description |
|---|---|
| Print_PrinterChangeCallback callback | Print_PrinterChangeCallback to be registered. |
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_RPC_FAILURE: Failed to connect to the print service. |
OH_Print_UnregisterPrinterChangeListener()
void OH_Print_UnregisterPrinterChangeListener()
Description
Unregisters this listener for printer changes.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
OH_Print_QueryPrinterList()
Print_ErrorCode OH_Print_QueryPrinterList(Print_StringList *printerIdList)
Description
Queries the list of added printers.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Parameters
| Name | Description |
|---|---|
| Print_StringList *printerIdList | Pointer to the Print_StringList instance that stores the queried printer ID list. |
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_INVALID_PARAMETER: printerIdList is null. PRINT_ERROR_INVALID_PRINTER: Failed to query any connected printers. PRINT_ERROR_GENERIC_FAILURE: Failed to copy printer ID list. |
OH_Print_ReleasePrinterList()
void OH_Print_ReleasePrinterList(Print_StringList *printerIdList)
Description
Releases the memory used to query the printer list.
System capability: SystemCapability.Print.PrintFramework
Since: 12
Parameters
| Name | Description |
|---|---|
| Print_StringList *printerIdList | Pointer to the queried printer ID list. |
OH_Print_QueryPrinterInfo()
Print_ErrorCode OH_Print_QueryPrinterInfo(const char *printerId, Print_PrinterInfo **printerInfo)
Description
Queries printer information by printer ID.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Parameters
| Name | Description |
|---|---|
| const char *printerId | Pointer to the printer ID to be queried. |
| Print_PrinterInfo **printerInfo | Double pointer to the Print_PrinterInfo. |
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_RPC_FAILURE: Failed to connect to the print service. PRINT_ERROR_INVALID_PARAMETER: The printerId or printerInfo is null. PRINT_ERROR_INVALID_PRINTER: Failed to find the specified printer in the list of connected printers. |
OH_Print_ReleasePrinterInfo()
void OH_Print_ReleasePrinterInfo(Print_PrinterInfo *printerInfo)
Description
Releases the memory used to query the printer information.
System capability: SystemCapability.Print.PrintFramework
Since: 12
Parameters
| Name | Description |
|---|---|
| Print_PrinterInfo *printerInfo | Pointer to the queried printer information. |
OH_Print_LaunchPrinterManager()
Print_ErrorCode OH_Print_LaunchPrinterManager()
Description
Starts the printer management window of the system.
System capability: SystemCapability.Print.PrintFramework
Since: 12
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_GENERIC_FAILURE: Failed to start the printer management window. |
OH_Print_QueryPrinterProperties()
Print_ErrorCode OH_Print_QueryPrinterProperties(const char *printerId, const Print_StringList *propertyKeyList, Print_PropertyList *propertyList)
Description
Queries the printer properties based on the list of property keys.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Parameters
| Name | Description |
|---|---|
| const char *printerId | Pointer to the printer ID to be queried. |
| const Print_StringList *propertyKeyList | Pointer to the list of property keys. |
| Print_PropertyList *propertyList | Pointer to the queried printer properties. |
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_INVALID_PARAMETER: One of the parameters is null or the key list is empty. PRINT_ERROR_INVALID_PRINTER: Failed to find properties of the specified printer. PRINT_ERROR_GENERIC_FAILURE: Failed to copy printer properties. |
OH_Print_ReleasePrinterProperties()
void OH_Print_ReleasePrinterProperties(Print_PropertyList *propertyList)
Description
Releases the memory used to query the printer properties.
System capability: SystemCapability.Print.PrintFramework
Since: 12
Parameters
| Name | Description |
|---|---|
| Print_PropertyList *propertyList | Pointer to the queried printer properties. |
OH_Print_UpdatePrinterProperties()
Print_ErrorCode OH_Print_UpdatePrinterProperties(const char *printerId, const Print_PropertyList *propertyList)
Description
Updates the printer properties based on the KV pairs.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Parameters
| Name | Description |
|---|---|
| const char *printerId | Pointer to the printer ID. |
| const Print_PropertyList *propertyList | Pointer to the list of printer properties to be updated. |
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_RPC_FAILURE: Failed to connect to the print service. |
OH_Print_RestorePrinterProperties()
Print_ErrorCode OH_Print_RestorePrinterProperties(const char *printerId, const Print_StringList *propertyKeyList)
Description
Restores printer properties to the default settings based on the property key list.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 12
Parameters
| Name | Description |
|---|---|
| const char *printerId | Pointer to the printer ID. |
| const Print_StringList *propertyKeyList | Pointer to the property key list. |
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_RPC_FAILURE: Failed to connect to the print service. |
OH_Print_StartPrintByNative()
Print_ErrorCode OH_Print_StartPrintByNative(const char *printJobName, Print_PrintDocCallback printDocCallback, void *context)
Description
Starts the printing dialog box.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 13
Parameters
| Name | Description |
|---|---|
| const char *printJobName | Pointer to the name of the print job. |
| Print_PrintDocCallback printDocCallback | Callback used to return the file state. |
| void *context | Pointer to the context of the caller. |
Returns
| Type | Description |
|---|---|
| Print_ErrorCode | PRINT_ERROR_NONE: Operation is successful. PRINT_ERROR_NO_PERMISSION: The ohos.permission.PRINT permission is required. PRINT_ERROR_RPC_FAILURE: Failed to connect to the print service. |
OH_Print_OnJobStateChanged()
typedef void(*OH_Print_OnJobStateChanged)(const char *jobId, OH_Print_JobState state)
Description
Defines a callback to be invoked when the print job state changes.
Since: 24
Parameters
| Name | Description |
|---|---|
| const char *jobId | Pointer to the print job ID. |
| OH_Print_JobState state | Print job state. |
OH_Print_StartPrintWithJobStateCallback()
Print_ErrorCode OH_Print_StartPrintWithJobStateCallback(const Print_PrintJob *printJob, OH_Print_OnJobStateChanged jobStateChangedCb)
Description
Starts a print job with the callback to be invoked when the print job state changes.
System capability: SystemCapability.Print.PrintFramework
Required permissions: ohos.permission.PRINT
Since: 24
Parameters
| Name | Description |
|---|---|
| const Print_PrintJob *printJob | Pointer to the print job struct. |
| OH_Print_OnJobStateChanged jobStateChangedCb | Callback to be invoked when the print job state changes. |
Returns
| Name | Value | Description |
|---|---|---|
| PRINT_ERROR_NONE | 0 | Operation is successful. |
| PRINT_ERROR_NO_PERMISSION | 201 | The ohos.permission.PRINT permission is required. |
| PRINT_ERROR_INVALID_PARAMETER | 401 | One of the parameters is null or the key list is empty. |
| PRINT_ERROR_GENERIC_FAILURE | 24300001 | The callback function cannot be copied. |
| PRINT_ERROR_RPC_FAILURE | 24300002 | Failed to connect to the print service. |
| PRINT_ERROR_SERVER_FAILURE | 24300003 | The print job struct cannot be created in the print service. |
| PRINT_ERROR_INVALID_PRINTER | 24300005 | The properties of the specified printer cannot be found. |
| PRINT_ERROR_INVALID_PRINT_JOB | 24300006 | Print job cannot be found in the job queue. |