• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# OH_Print
2
3## Overview
4
5Provides applications with the ability to access the print system using CAPI.
6
7**Since**: 12
8
9## Summary
10
11### Files
12
13| Name| Description|
14| -------- | -------- |
15| [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.|
16
17### Types
18
19| Name| Description|
20| -------- | -------- |
21| [Print_StringList](#print_stringlist) | Defines a printer list.|
22| [Print_Property](#print_property) | Defines a property for the printer.|
23| [Print_PropertyList](#print_propertylist) | Defines a property list for the printer.|
24| [Print_Resolution](#print_resolution) | Defines the resolution unit for printing.|
25| [Print_Margin](#print_margin) | Defines the page margin.|
26| [Print_PageSize](#print_pagesize) | Defines the page size for printing.|
27| [Print_PrinterCapability](#print_printercapability) | Defines the printer capabilities.|
28| [Print_DefaultValue](#print_defaultvalue) | Defines the default printing information.|
29| [Print_PrinterInfo](#print_printerinfo) | Defines the printer information.|
30| [Print_PrintJob](#print_printjob) | Defines a print job.|
31| [Print_Range](#print_range) | Defines the page range.|
32| [Print_PrintAttributes](#print_printattributes) | Defines the print attributes.|
33| [Print_WriteResultCallback](#print_writeresultcallback) | Defines a callback used to return the write result.|
34| [Print_OnStartLayoutWrite](#print_onstartlayoutwrite) | Defines a callback to be invoked when the layout processing starts.|
35| [Print_OnJobStateChanged](#print_onjobstatechanged) | Defines a callback to be invoked when the print job state changes.|
36| [Print_PrintDocCallback](#print_printdoccallback) | Defines a callback used to return the file state.|
37| [Print_PrinterDiscoveryCallback](#print_printerdiscoverycallback) | Defines a callback used to return the discovered printers.|
38| [Print_PrinterChangeCallback](#print_printerchangecallback) | Defines a callback to be invoked when the printer state changes.|
39
40### Enums
41
42| Name| Description|
43| -------- | -------- |
44| [Print_ErrorCode](#print_errorcode) | Enumerates the error codes.|
45| [Print_PrinterState](#print_printerstate) | Enumerates the printer state codes.|
46| [Print_DiscoveryEvent](#print_discoveryevent) | Enumerates the printer discovery events.|
47| [Print_PrinterEvent](#print_printerevent) | Enumerates the printer state change events.|
48| [Print_DuplexMode](#print_duplexmode) | Enumerates the duplex modes for printing.|
49| [Print_ColorMode](#print_colormode) | Enumerates the color modes for printing.|
50| [Print_OrientationMode](#print_orientationmode) | Enumerates the orientation modes for printing.|
51| [Print_Quality](#print_quality) | Enumerates the print qualities.|
52| [Print_DocumentFormat](#print_documentformat) | Enumerates the document formats.|
53| [Print_JobDocAdapterState](#print_jobdocadapterstate) | Enumerates the print job adapter states.|
54
55### Functions
56
57| Name| Description|
58| -------- | -------- |
59| [OH_Print_Init](#oh_print_init) | Initiates the print service, initializes the print client, and establishes a connection to the print service.|
60| [OH_Print_Release](#oh_print_release) | Closes the connection to the print service, unregisters the callback, and releases the print client resources.|
61| [OH_Print_StartPrinterDiscovery](#oh_print_startprinterdiscovery) | Starts printer discovery.|
62| [OH_Print_StopPrinterDiscovery](#oh_print_stopprinterdiscovery) | Stops printer discovery.|
63| [OH_Print_ConnectPrinter](#oh_print_connectprinter) | Connects to a printer by printer ID.|
64| [OH_Print_StartPrintJob](#oh_print_startprintjob) | Starts a print job.|
65| [OH_Print_RegisterPrinterChangeListener](#oh_print_registerprinterchangelistener) | Registers a listener to listen for the printer state changes.|
66| [OH_Print_UnregisterPrinterChangeListener](#oh_print_unregisterprinterchangelistener) | Unregisters the listener used to listen for the printer state changes.|
67| [OH_Print_QueryPrinterList](#oh_print_queryprinterlist) | Queries the printer list.|
68| [OH_Print_ReleasePrinterList](#oh_print_releaseprinterlist) | Releases the memory allocated for querying the printer list.|
69| [OH_Print_QueryPrinterInfo](#oh_print_queryprinterinfo) | Queries the printer information.|
70| [OH_Print_ReleasePrinterInfo](#oh_print_releaseprinterinfo) | Releases the memory allocated for querying the printer information.|
71| [OH_Print_LaunchPrinterManager](#oh_print_launchprintermanager) | Launches the printer manager.|
72| [OH_Print_QueryPrinterProperties](#oh_print_queryprinterproperties) | Queries the printer properties.|
73| [OH_Print_ReleasePrinterProperties](#oh_print_releaseprinterproperties) | Releases the memory allocated for querying the printer properties.|
74| [OH_Print_UpdatePrinterProperties](#oh_print_updateprinterproperties) | Updates the printer properties.|
75| [OH_Print_RestorePrinterProperties](#oh_print_restoreprinterproperties) | Restores printer properties to the default settings based on the property key list.|
76| [OH_Print_StartPrintByNative](#oh_print_startprintbynative) | Starts printing.|
77
78## Type Description
79
80### Print_StringList
81
82**Description**
83
84Defines a printer list.
85
86**Since**: 12
87
88| Member        | Description    |
89| ------------ | -------- |
90| count    | Number of strings.|
91| list | String pointer array.  |
92
93### Print_Property
94
95**Description**
96
97Defines a property for the printer.
98
99**Since**: 12
100
101| Member    | Description                   |
102| -------- | ----------------------- |
103| key | Property key.|
104| value       | Property value.           |
105
106### Print_PropertyList
107
108**Description**
109
110Defines a property list for the printer.
111
112**Since**: 12
113
114| Member        | Description        |
115| ------------ | ------------ |
116| count       | Number of properties.    |
117| list | Property pointer array.|
118
119### Print_Resolution
120
121**Description**
122
123Defines the resolution unit for printing.
124
125**Since**: 12
126
127| Parameter       | Description      |
128| ----------- | ---------- |
129| horizontalDpi     | Horizontal resolution (dpi).|
130| verticalDpi | Vertical resolution (dpi).  |
131
132### Print_Margin
133
134**Description**
135
136Defines the page margin.
137
138**Since**: 12
139
140| Parameter       | Description      |
141| ----------- | ---------- |
142| leftMargin     | Left margin (µm).|
143| topMargin | Top margin (µm).  |
144| rightMargin | Right margin (µm).  |
145| bottomMargin | Bottom margin (µm).  |
146
147### Print_PageSize
148
149**Description**
150
151Defines the page size for printing.
152
153**Since**: 12
154
155| Parameter       | Description      |
156| ----------- | ---------- |
157| id     | Page ID.|
158| name | Page name.  |
159| width | Paper width (µm).  |
160| height | Paper height (µm).  |
161
162### Print_PrinterCapability
163
164**Description**
165
166Defines the printer capabilities.
167
168**Since**: 12
169
170| Parameter       | Description      |
171| ----------- | ---------- |
172| supportedColorModes     | Supported color modes.|
173| supportedColorModesCount | Number of supported color modes.  |
174| supportedDuplexModes | Supported duplex modes.  |
175| supportedDuplexModesCount | Number of supported duplex modes.  |
176| supportedPageSizes | Supported page sizes.  |
177| supportedPageSizesCount | Number of supported paper sizes.  |
178| supportedMediaTypes | Supported media types (JSON string array format).  |
179| supportedQualities | Supported print qualities.  |
180| supportedQualitiesCount | Number of supported print qualities.  |
181| supportedPaperSources | Supported paper sources (JSON string array format).  |
182| supportedCopies | Maximum number of copies that can be printed.  |
183| supportedResolutions | Supported resolutions.  |
184| supportedResolutionsCount | Number of supported resolutions.  |
185| supportedOrientations | Supported printing orientations.  |
186| supportedOrientationsCount | Number of supported printing orientations.  |
187| advancedCapability | Advanced capabilities (JSON format).  |
188
189### Print_DefaultValue
190
191**Description**
192
193Defines the default printing information.
194
195**Since**: 12
196
197| Parameter       | Description      |
198| ----------- | ---------- |
199| defaultColorMode     | Default color mode.|
200| defaultDuplexMode | Default duplex mode.  |
201| defaultMediaType | Default media type.  |
202| defaultPageSizeId | Default page size ID.  |
203| defaultMargin | Default margin.  |
204| defaultPaperSource | Default paper source.  |
205| defaultPrintQuality | Default print quality.  |
206| defaultCopies | Default number of copies.  |
207| defaultResolution | Default resolution.  |
208| defaultOrientation | Default printing orientation.  |
209| otherDefaultValues | Other default values (JSON format).  |
210
211### Print_PrinterInfo
212
213**Description**
214
215Defines the printer information.
216
217**Since**: 12
218
219| Parameter       | Description      |
220| ----------- | ---------- |
221| printerState     | Printer state.|
222| capability | Printer capability.  |
223| defaultValue | Default printer property.  |
224| isDefaultPrinter | Whether the printer is the default one.  |
225| printerId | Printer ID.  |
226| printerName | Printer name.  |
227| description | Printer description.  |
228| location | Printer location.  |
229| makeAndModel | Printer manufacturer and model information.  |
230| printerUri | Printer URI.  |
231| detailInfo | Detailed information (JSON format).  |
232
233### Print_PrintJob
234
235**Description**
236
237Defines a print job.
238
239**Since**: 12
240
241| Parameter       | Description      |
242| ----------- | ---------- |
243| jobName     | Print job name.|
244| fdList | List of file descriptors of the print job.  |
245| fdListCount | Number of file descriptors of the print job.  |
246| printerId | Printer ID.  |
247| copyNumber | Number of copies to print.  |
248| paperSource | Paper source.  |
249| mediaType | Media type.  |
250| pageSizeId | Page size ID.  |
251| colorMode | Color mode.  |
252| duplexMode | Duplex mode.  |
253| resolution | Resolution.  |
254| printMargin | Page margin.  |
255| borderless | Whether to print without margins.  |
256| orientationMode | Orientation mode.  |
257| printQuality | Print quality.  |
258| documentFormat | Document format.  |
259| advancedOptions | Advanced options (JSON format).  |
260
261### Print_Range
262
263**Description**
264
265Defines the page range.
266
267**Since**: 13
268
269| Parameter       | Description      |
270| ----------- | ---------- |
271| startPage     | Start page number.|
272| endPage | End page number.  |
273| pagesArrayLen | Length of the page array.  |
274| pagesArray | Page array.  |
275
276### Print_PrintAttributes
277
278**Description**
279
280Defines the print attributes.
281
282**Since**: 13
283
284| Parameter       | Description      |
285| ----------- | ---------- |
286| pageRange     | Defines the page range.|
287| pageSize | Paper size.  |
288| pageMargin | Page margin.  |
289| copyNumber | Number of copies to print.  |
290| duplexMode | Duplex mode.  |
291| colorMode | Color mode.  |
292| isSequential | Whether to print in sequence.  |
293| isLandscape | Whether to print in landscape mode.  |
294| hasOption | Whether print options are provided.  |
295| options | Print options (in 256 bytes).  |
296
297### Print_WriteResultCallback
298
299**Description**
300
301Defines a callback used to return the write result.
302
303**Since**: 13
304
305**Parameters**
306
307| Name     | Description      |
308| --------- | ---------- |
309| jobId     | Print job ID.|
310| code | State code of the write result.  |
311
312### Print_OnStartLayoutWrite
313
314**Description**
315
316Defines a callback to be invoked when the layout processing starts.
317
318**Since**: 13
319
320**Parameters**
321
322| Name     | Description      |
323| --------- | ---------- |
324| jobId     | Print job ID.|
325| fd | File descriptor.  |
326| oldAttrs | Previous print attributes.  |
327| newAttrs | New print attributes.  |
328| writeCallback | Callback used to return the write result.  |
329
330### Print_OnJobStateChanged
331
332**Description**
333
334Defines a callback to be invoked when the print job state changes.
335
336**Since**: 13
337
338**Parameters**
339
340| Name     | Description      |
341| --------- | ---------- |
342| jobId     | Print job ID.|
343| state | Print job state.  |
344
345### Print_PrintDocCallback
346
347**Description**
348
349Defines a callback used to return the file state.
350
351**Since**: 13
352
353| Parameter       | Description      |
354| ----------- | ---------- |
355| startLayoutWriteCb     | Callback to be invoked when the layout processing starts.|
356| jobStateChangedCb | Callback to be invoked when the print job state changes.  |
357
358### Print_PrinterDiscoveryCallback
359
360**Description**
361
362Defines a callback used to return the discovered printers.
363
364**Since**: 12
365
366**Parameters**
367
368| Name     | Description      |
369| --------- | ---------- |
370| event     | Discovery event.|
371| printerInfo | Printer information.  |
372
373### Print_PrinterChangeCallback
374
375**Description**
376
377Defines a callback to be invoked when the printer state changes.
378
379**Since**: 12
380
381**Parameters**
382
383| Name     | Description      |
384| --------- | ---------- |
385| event     | Change event.|
386| printerInfo | Printer information.  |
387
388## Enum Description
389
390### Print_ErrorCode
391
392**Description**
393
394Enumerates the error codes.
395
396**Since**: 12
397
398| Name| Description| Value|
399| -------- | -------- | -------- |
400| PRINT_ERROR_NONE | Operation successful.| 0 |
401| PRINT_ERROR_NO_PERMISSION | Permission verification failed.| 201 |
402| PRINT_ERROR_INVALID_PARAMETER | Invalid parameter.| 401 |
403| PRINT_ERROR_GENERIC_FAILURE | Internal error.| 24300001 |
404| PRINT_ERROR_RPC_FAILURE | RPC communication error.| 24300002 |
405| PRINT_ERROR_SERVER_FAILURE | Server error.| 24300003 |
406| PRINT_ERROR_INVALID_EXTENSION | Invalid extension.| 24300004 |
407| PRINT_ERROR_INVALID_PRINTER | Invalid printer.| 24300005 |
408| PRINT_ERROR_INVALID_PRINT_JOB | Invalid print job.| 24300006 |
409| PRINT_ERROR_FILE_IO | File I/O operation failed.| 24300007 |
410| PRINT_ERROR_UNKNOWN | Unknown error.| 24300255 |
411
412### Print_PrinterState
413
414**Description**
415
416Enumerates the printer state codes.
417
418**Since**: 12
419
420| Name| Description|
421| -------- | -------- |
422| PRINTER_IDLE | The printer is idle.|
423| PRINTER_BUSY | The printer is busy.|
424| PRINTER_UNAVAILABLE | The printer is unavailable.|
425
426### Print_DiscoveryEvent
427
428**Description**
429
430Enumerates the printer discovery events.
431
432**Since**: 12
433
434| Name| Description|
435| -------- | -------- |
436| PRINTER_DISCOVERED | Printer discovered.|
437| PRINTER_LOST | Printer lost.|
438| PRINTER_CONNECTING | Printer connecting.|
439| PRINTER_CONNECTED | Printer connected.|
440
441### Print_PrinterEvent
442
443**Description**
444
445Enumerates the printer state change events.
446
447**Since**: 12
448
449| Name| Description|
450| -------- | -------- |
451| PRINTER_ADDED | A printer is added.|
452| PRINTER_DELETED | A printer is deleted.|
453| PRINTER_STATE_CHANGED | The printer state has changed.|
454| PRINTER_INFO_CHANGED | The printer information has changed.|
455| PRINTER_PREFERENCE_CHANGED | The printer preferences have changed.|
456
457### Print_DuplexMode
458
459**Description**
460
461Enumerates the duplex modes for printing.
462
463**Since**: 12
464
465| Name| Description|
466| -------- | -------- |
467| DUPLEX_MODE_ONE_SIDED | Single-sided printing.|
468| DUPLEX_MODE_TWO_SIDED_LONG_EDGE | Long-edge duplex printing.|
469| DUPLEX_MODE_TWO_SIDED_SHORT_EDGE | Short-edge duplex printing.|
470
471### Print_ColorMode
472
473**Description**
474
475Enumerates the color modes for printing.
476
477**Since**: 12
478
479| Name| Description|
480| -------- | -------- |
481| COLOR_MODE_MONOCHROME | Monochrome mode.|
482| COLOR_MODE_COLOR | Color mode.|
483| COLOR_MODE_AUTO | Auto mode.|
484
485### Print_OrientationMode
486
487**Description**
488
489Enumerates the orientation modes for printing.
490
491**Since**: 12
492
493| Name| Description|
494| -------- | -------- |
495| ORIENTATION_MODE_PORTRAIT | Portrait.|
496| ORIENTATION_MODE_LANDSCAPE | Landscape.|
497| ORIENTATION_MODE_REVERSE_LANDSCAPE | Reverse landscape.|
498| ORIENTATION_MODE_REVERSE_PORTRAIT | Reverse portrait.|
499| ORIENTATION_MODE_NONE | Not specified.|
500
501### Print_Quality
502
503**Description**
504
505Enumerates the print qualities.
506
507**Since**: 12
508
509| Name| Description|
510| -------- | -------- |
511| PRINT_QUALITY_DRAFT | Draft quality.|
512| PRINT_QUALITY_NORMAL | Normal quality.|
513| PRINT_QUALITY_HIGH | High quality.|
514
515### Print_DocumentFormat
516
517**Description**
518
519Enumerates the document formats.
520
521**Since**: 12
522
523| Name| Description| MIME Type|
524| -------- | -------- | -------- |
525| DOCUMENT_FORMAT_AUTO | Auto-detected format.| application/octet-stream. |
526| DOCUMENT_FORMAT_JPEG | JPEG image.| image/jpeg. |
527| DOCUMENT_FORMAT_PDF | PDF document.| application/pdf. |
528| DOCUMENT_FORMAT_POSTSCRIPT | PostScript document.| application/postscript. |
529| DOCUMENT_FORMAT_TEXT | Plain text.| text/plain. |
530
531### Print_JobDocAdapterState
532
533**Description**
534
535Enumerates the print job adapter states.
536
537**Since**: 13
538
539| Name| Description|
540| -------- | -------- |
541| PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY | Preview destroyed.|
542| PRINT_DOC_ADAPTER_PRINT_TASK_SUCCEED | Successful print job.|
543| PRINT_DOC_ADAPTER_PRINT_TASK_FAIL | Print job failed.|
544| PRINT_DOC_ADAPTER_PRINT_TASK_CANCEL | Print job canceled.|
545| PRINT_DOC_ADAPTER_PRINT_TASK_BLOCK | Print job blocked.|
546| PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY_FOR_CANCELED | Preview destroyed due to print job cancellation.|
547| PRINT_DOC_ADAPTER_PREVIEW_ABILITY_DESTROY_FOR_STARTED | Preview destroyed due to print job start.|
548
549## Function Description
550
551### OH_Print_Init()
552
553```cpp
554Print_ErrorCode OH_Print_Init();
555```
556
557**Description**
558
559Initiates the print service, initializes the print client, and establishes a connection to the print service.
560
561**Required permissions**: ohos.permission.PRINT
562
563**System capability**: SystemCapability.Print.PrintFramework
564
565**Since**: 12
566
567**Returns**
568
569| Error Code| Description|
570| -------- | -------- |
571| PRINT_ERROR_NONE | Operation successful.|
572| PRINT_ERROR_NO_PERMISSION | Permission denied.|
573| PRINT_ERROR_RPC_FAILURE | Failed to connect to the print service.|
574| PRINT_ERROR_SERVER_FAILURE | Failed to start the CUPS service.|
575
576### OH_Print_Release()
577
578```cpp
579Print_ErrorCode OH_Print_Release();
580```
581
582**Description**
583
584Closes the connection to the print service, unregisters the callback, and releases the print client resources.
585
586**System capability**: SystemCapability.Print.PrintFramework
587
588**Since**: 12
589
590**Returns**
591
592| Error Code| Description|
593| -------- | -------- |
594| PRINT_ERROR_NONE | Operation successful.|
595
596### OH_Print_StartPrinterDiscovery()
597
598```cpp
599Print_ErrorCode OH_Print_StartPrinterDiscovery(Print_PrinterDiscoveryCallback callback);
600```
601
602**Description**
603
604Starts printer discovery.
605
606**Required permissions**: ohos.permission.PRINT
607
608**System capability**: SystemCapability.Print.PrintFramework
609
610**Since**: 12
611
612**Parameters**
613
614| Name| Description|
615| -------- | -------- |
616| callback | callback used to return the discovered printers.|
617
618**Returns**
619
620| Error Code| Description|
621| -------- | -------- |
622| PRINT_ERROR_NONE | Operation successful.|
623| PRINT_ERROR_NO_PERMISSION | Permission denied.|
624| PRINT_ERROR_RPC_FAILURE | Failed to connect to the print service.|
625| PRINT_ERROR_SERVER_FAILURE | Failed to query the extended printing list from the BMS.|
626| PRINT_ERROR_INVALID_EXTENSION | Invalid print extension.|
627
628### OH_Print_StopPrinterDiscovery()
629
630```cpp
631Print_ErrorCode OH_Print_StopPrinterDiscovery();
632```
633
634**Description**
635
636Stops printer discovery.
637
638**Required permissions**: ohos.permission.PRINT
639
640**System capability**: SystemCapability.Print.PrintFramework
641
642**Since**: 12
643
644**Returns**
645
646| Error Code| Description|
647| -------- | -------- |
648| PRINT_ERROR_NONE | Operation successful.|
649| PRINT_ERROR_NO_PERMISSION | Permission denied.|
650| PRINT_ERROR_RPC_FAILURE | Failed to connect to the print service.|
651
652### OH_Print_ConnectPrinter()
653
654```cpp
655Print_ErrorCode OH_Print_ConnectPrinter(const char *printerId);
656```
657
658**Description**
659
660Connects to a printer by printer ID.
661
662**Required permissions**: ohos.permission.PRINT
663
664**System capability**: SystemCapability.Print.PrintFramework
665
666**Since**: 12
667
668**Parameters**
669
670| Name| Description|
671| -------- | -------- |
672| printerId | ID of the printer to be connected.|
673
674**Returns**
675
676| Error Code| Description|
677| -------- | -------- |
678| PRINT_ERROR_NONE | Operation successful.|
679| PRINT_ERROR_NO_PERMISSION | Permission denied.|
680| PRINT_ERROR_RPC_FAILURE | Failed to connect to the print service.|
681| PRINT_ERROR_INVALID_PRINTER | Failed to find the printer in the discovery list.|
682| PRINT_ERROR_SERVER_FAILURE | Failed to find the printer extension.|
683
684### OH_Print_StartPrintJob()
685
686```cpp
687Print_ErrorCode OH_Print_StartPrintJob(const Print_PrintJob *printJob);
688```
689
690**Description**
691
692Starts a print job.
693
694**Required permissions**: ohos.permission.PRINT
695
696**System capability**: SystemCapability.Print.PrintFramework
697
698**Since**: 12
699
700**Parameters**
701
702| Name| Description|
703| -------- | -------- |
704| printJob | Pointer to the **Print_PrintJob** struct that contains the print job information.|
705
706**Returns**
707
708| Error Code| Description|
709| -------- | -------- |
710| PRINT_ERROR_NONE | Operation successful.|
711| PRINT_ERROR_NO_PERMISSION | Permission denied.|
712| PRINT_ERROR_RPC_FAILURE | Failed to connect to the print service.|
713| PRINT_ERROR_INVALID_PRINTER | Failed to find the printer in the connection list.|
714| PRINT_ERROR_SERVER_FAILURE | Failed to create a print job in the print service.|
715| PRINT_ERROR_INVALID_PRINT_JOB | Invalid print job.|
716
717### OH_Print_RegisterPrinterChangeListener()
718
719```cpp
720Print_ErrorCode OH_Print_RegisterPrinterChangeListener(Print_PrinterChangeCallback callback);
721```
722
723**Description**
724
725Registers a listener to listen for the printer state changes.
726
727**Required permissions**: ohos.permission.PRINT
728
729**System capability**: SystemCapability.Print.PrintFramework
730
731**Since**: 12
732
733**Parameters**
734
735| Name| Description|
736| -------- | -------- |
737| callback | Callback to be invoked when the printer state changes.|
738
739**Returns**
740
741| Error Code| Description|
742| -------- | -------- |
743| PRINT_ERROR_NONE | Operation successful.|
744| PRINT_ERROR_NO_PERMISSION | Permission denied.|
745| PRINT_ERROR_RPC_FAILURE | Failed to connect to the print service.|
746
747### OH_Print_UnregisterPrinterChangeListener()
748
749```cpp
750void OH_Print_UnregisterPrinterChangeListener();
751```
752
753**Description**
754
755Unregisters the listener used to listen for the printer state changes.
756
757**Required permissions**: ohos.permission.PRINT
758
759**System capability**: SystemCapability.Print.PrintFramework
760
761**Since**: 12
762
763### OH_Print_QueryPrinterList()
764
765```cpp
766Print_ErrorCode OH_Print_QueryPrinterList(Print_StringList *printerIdList);
767```
768
769**Description**
770
771Queries the printer list.
772
773**Required permissions**: ohos.permission.PRINT
774
775**System capability**: SystemCapability.Print.PrintFramework
776
777**Since**: 12
778
779**Parameters**
780
781| Name| Description|
782| -------- | -------- |
783| printerIdList | Pointer to **Print_StringList** that stores the query result.|
784
785**Returns**
786
787| Error Code| Description|
788| -------- | -------- |
789| PRINT_ERROR_NONE | Operation successful.|
790| PRINT_ERROR_NO_PERMISSION | Permission denied.|
791| PRINT_ERROR_INVALID_PARAMETER | **printerIdList** is null.|
792| PRINT_ERROR_INVALID_PRINTER | Failed to query any connected printers.|
793| PRINT_ERROR_GENERIC_FAILURE | Failed to copy the printer ID list.|
794
795### OH_Print_ReleasePrinterList()
796
797```cpp
798void OH_Print_ReleasePrinterList(Print_StringList *printerIdList);
799```
800
801**Description**
802
803Releases the memory allocated for querying the printer list.
804
805**System capability**: SystemCapability.Print.PrintFramework
806
807**Since**: 12
808
809**Parameters**
810
811| Name| Description|
812| -------- | -------- |
813| printerIdList | Printer ID list queried.|
814
815### OH_Print_QueryPrinterInfo()
816
817```cpp
818Print_ErrorCode OH_Print_QueryPrinterInfo(const char *printerId, Print_PrinterInfo **printerInfo);
819```
820
821**Description**
822
823Queries printer information based on the printer ID.
824
825**Required permissions**: ohos.permission.PRINT
826
827**System capability**: SystemCapability.Print.PrintFramework
828
829**Since**: 12
830
831**Parameters**
832
833| Name| Description|
834| -------- | -------- |
835| printerId | Printer ID to be queried.|
836| printerInfo | Pointer to **Print_PrinterInfo** that stores the query result.|
837
838**Returns**
839
840| Error Code| Description|
841| -------- | -------- |
842| PRINT_ERROR_NONE | Operation successful.|
843| PRINT_ERROR_NO_PERMISSION | Permission denied.|
844| PRINT_ERROR_RPC_FAILURE | Failed to connect to the print service.|
845| PRINT_ERROR_INVALID_PARAMETER | **printerId** or **printerInfo** is null.|
846| PRINT_ERROR_INVALID_PRINTER | Failed to find the printer in the connection list.|
847
848### OH_Print_ReleasePrinterInfo()
849
850```cpp
851void OH_Print_ReleasePrinterInfo(Print_PrinterInfo *printerInfo);
852```
853
854**Description**
855
856Releases the memory allocated for querying the printer information.
857
858**System capability**: SystemCapability.Print.PrintFramework
859
860**Since**: 12
861
862**Parameters**
863
864| Name| Description|
865| -------- | -------- |
866| printerInfo | Pointer to the printer information.|
867
868### OH_Print_LaunchPrinterManager()
869
870```cpp
871Print_ErrorCode OH_Print_LaunchPrinterManager();
872```
873
874**Description**
875
876Launches the system printer manager.
877
878**System capability**: SystemCapability.Print.PrintFramework
879
880**Since**: 12
881
882**Returns**
883
884| Error Code| Description|
885| -------- | -------- |
886| PRINT_ERROR_NONE | Operation successful.|
887| PRINT_ERROR_GENERIC_FAILURE | Failed to launch the printer manager.|
888
889### OH_Print_QueryPrinterProperties()
890
891```cpp
892Print_ErrorCode OH_Print_QueryPrinterProperties(const char *printerId,
893                                              const Print_StringList *propertyKeyList,
894                                              Print_PropertyList *propertyList);
895```
896
897**Description**
898
899Queries printer properties based on the property key list.
900
901**Required permissions**: ohos.permission.PRINT
902
903**System capability**: SystemCapability.Print.PrintFramework
904
905**Since**: 12
906
907**Parameters**
908
909| Name| Description|
910| -------- | -------- |
911| printerId | Printer ID to be queried.|
912| propertyKeyList | List of property keys.|
913| propertyList | Property list used to store the query result.|
914
915**Returns**
916
917| Error Code| Description|
918| -------- | -------- |
919| PRINT_ERROR_NONE | Operation successful.|
920| PRINT_ERROR_NO_PERMISSION | Permission denied.|
921| PRINT_ERROR_INVALID_PARAMETER | The parameter is null or the key list is empty.|
922| PRINT_ERROR_INVALID_PRINTER | Failed to find printer properties.|
923| PRINT_ERROR_GENERIC_FAILURE | Failed to copy the printer properties.|
924
925### OH_Print_ReleasePrinterProperties()
926
927```cpp
928void OH_Print_ReleasePrinterProperties(Print_PropertyList *propertyList);
929```
930
931**Description**
932
933Releases the memory allocated for querying the printer properties.
934
935**System capability**: SystemCapability.Print.PrintFramework
936
937**Since**: 12
938
939**Parameters**
940
941| Name| Description|
942| -------- | -------- |
943| propertyList | Pointer to the property list.|
944
945### OH_Print_UpdatePrinterProperties()
946
947```cpp
948Print_ErrorCode OH_Print_UpdatePrinterProperties(const char *printerId,
949                                               const Print_PropertyList *propertyList);
950```
951
952**Description**
953
954Updates the printer properties based on the KV pairs.
955
956**Required permissions**: ohos.permission.PRINT
957
958**System capability**: SystemCapability.Print.PrintFramework
959
960**Since**: 12
961
962**Parameters**
963
964| Name| Description|
965| -------- | -------- |
966| printerId | Printer ID to be set.|
967| propertyList | Property list to be set.|
968
969**Returns**
970
971| Error Code| Description|
972| -------- | -------- |
973| PRINT_ERROR_NONE | Operation successful.|
974| PRINT_ERROR_NO_PERMISSION | Permission denied.|
975| PRINT_ERROR_RPC_FAILURE | Failed to connect to the print service.|
976
977### OH_Print_RestorePrinterProperties()
978
979```cpp
980Print_ErrorCode OH_Print_RestorePrinterProperties(const char *printerId,
981                                                const Print_StringList *propertyKeyList);
982```
983
984**Description**
985
986Restores printer properties to the default settings based on the property key list.
987
988**Required permissions**: ohos.permission.PRINT
989
990**System capability**: SystemCapability.Print.PrintFramework
991
992**Since**: 12
993
994**Parameters**
995
996| Name| Description|
997| -------- | -------- |
998| printerId | Printer ID to be restored.|
999| propertyKeyList | Property list to be restored.|
1000
1001**Returns**
1002
1003| Error Code| Description|
1004| -------- | -------- |
1005| PRINT_ERROR_NONE | Operation successful.|
1006| PRINT_ERROR_NO_PERMISSION | Permission denied.|
1007| PRINT_ERROR_RPC_FAILURE | Failed to connect to the print service.|
1008
1009### OH_Print_StartPrintByNative()
1010
1011```cpp
1012Print_ErrorCode OH_Print_StartPrintByNative(const char *printJobName,
1013                                          Print_PrintDocCallback printDocCallback,
1014                                          void *context);
1015```
1016
1017**Description**
1018
1019Starts printing.
1020
1021**Required permissions**: ohos.permission.PRINT
1022
1023**System capability**: SystemCapability.Print.PrintFramework
1024
1025**Since**: 13
1026
1027**Parameters**
1028
1029| Name| Description|
1030| -------- | -------- |
1031| printJobName | Print job name.|
1032| printDocCallback | Callback used to return the file state.|
1033| context | Context of the caller.|
1034
1035**Returns**
1036
1037| Error Code| Description|
1038| -------- | -------- |
1039| PRINT_ERROR_NONE | Operation successful.|
1040| PRINT_ERROR_NO_PERMISSION | Permission denied.|
1041| PRINT_ERROR_RPC_FAILURE | Failed to connect to the print service.|
1042