harmony 鸿蒙@ohos.print (Print)

  • 2023-10-30
  • 浏览 (330)

@ohos.print (Print)

The print module provides APIs for basic print operations.

NOTE

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.

Modules to Import

import print from '@ohos.print';

PrintTask

Implements event listener APIs for print tasks.

on

on(type: ‘block’, callback: Callback<void>): void

Registers a listener for the print task blocking event. This API uses a callback to return the result.

Required permissions: ohos.permission.PRINT

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|string|Yes|Listening type.
The value is fixed at ‘block’, indicating blocking of the print task.| |callback|Callback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let file = ['file://data/print/a.png', 'file://data/print/b.png'];
print.print(file).then((printTask: print.PrintTask) => {
    printTask.on('block', () => {
        console.log('print state is block');
    })
    // ...
}).catch((error: BusinessError) => {
    console.log('print err ' + JSON.stringify(error));
})

on

on(type: ‘succeed’, callback: Callback<void>): void

Registers a listener for the print task success event. This API uses a callback to return the result.

Required permissions: ohos.permission.PRINT

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|string|Yes|Listening type.
The value is fixed at ‘succeed’, indicating success of the print task.| |callback|Callback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let file = ['file://data/print/a.png', 'file://data/print/b.png'];
print.print(file).then((printTask: print.PrintTask) => {
    printTask.on('succeed', () => {
        console.log('print state is succeed');
    })
    // ...
}).catch((error: BusinessError) => {
    console.log('print err ' + JSON.stringify(error));
})

on

on(type: ‘fail’, callback: Callback<void>): void

Registers a listener for the print task failure event. This API uses a callback to return the result.

Required permissions: ohos.permission.PRINT

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|string|Yes|Listening type.
The value is fixed at ‘fail’, indicating failure of the print task.| |callback|Callback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let file = ['file://data/print/a.png', 'file://data/print/b.png'];
print.print(file).then((printTask: print.PrintTask) => {
    printTask.on('fail', () => {
        console.log('print state is fail');
    })
    // ...
}).catch((error: BusinessError) => {
    console.log('print err ' + JSON.stringify(error));
})

on

on(type: ‘cancel’, callback: Callback<void>): void

Registers a listener for the print task cancel event. This API uses a callback to return the result.

Required permissions: ohos.permission.PRINT

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|string|Yes|Listening type.
The value is fixed at ‘cancel’, indicating canceling of the print task.| |callback|Callback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let file = ['file://data/print/a.png', 'file://data/print/b.png'];
print.print(file).then((printTask: print.PrintTask) => {
    printTask.on('cancel', () => {
        console.log('print state is cancel');
    })
    // ...
}).catch((error: BusinessError) => {
    console.log('print err ' + JSON.stringify(error));
})

off

off(type: ‘block’, callback?: Callback<void>): void

Unregisters the listener for the print task blocking event. This API uses a callback to return the result.

Required permissions: ohos.permission.PRINT

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|string|Yes|Listening type.
The value is fixed at ‘block’, indicating blocking of the print task.| |callback|Callback<void>|No|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let file = ['file://data/print/a.png', 'file://data/print/b.png'];
print.print(file).then((printTask: print.PrintTask) => {
    printTask.off('block', () => {
        console.log('unregister state block');
    })
    // ...
}).catch((error: BusinessError) => {
    console.log('print err ' + JSON.stringify(error));
})

off

off(type: ‘succeed’, callback?: Callback<void>): void

Unregisters the listener for the print task success event. This API uses a callback to return the result.

Required permissions: ohos.permission.PRINT

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|string|Yes|Listening type.
The value is fixed at ‘succeed’, indicating success of the print task.| |callback|Callback<void>|No|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let file = ['file://data/print/a.png', 'file://data/print/b.png'];
print.print(file).then((printTask: print.PrintTask) => {
    printTask.off('succeed', () => {
        console.log('unregister state succeed');
    })
    // ...
}).catch((error: BusinessError) => {
    console.log('print err ' + JSON.stringify(error));
})

off

off(type: ‘fail’, callback?: Callback<void>): void

Unregisters the listener for the print task failure event. This API uses a callback to return the result.

Required permissions: ohos.permission.PRINT

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|string|Yes|Listening type.
The value is fixed at ‘fail’, indicating failure of the print task.| |callback|Callback<void>|No|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let file = ['file://data/print/a.png', 'file://data/print/b.png'];
print.print(file).then((printTask: print.PrintTask) => {
    printTask.off('fail', () => {
        console.log('unregister state fail');
    })
    // ...
}).catch((error: BusinessError) => {
    console.log('print err ' + JSON.stringify(error));
})

off

off(type: ‘cancel’, callback?: Callback<void>): void

Unregisters the listener for the print task cancel event. This API uses a callback to return the result.

Required permissions: ohos.permission.PRINT

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|string|Yes|Listening type.
The value is fixed at ‘cancel’, indicating canceling of the print task.| |callback|Callback<void>|No|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let file = ['file://data/print/a.png', 'file://data/print/b.png'];
print.print(file).then((printTask: print.PrintTask) => {
    printTask.off('cancel', () => {
        console.log('unregister state cancel');
    })
    // ...
}).catch((error: BusinessError) => {
    console.log('print err ' + JSON.stringify(error));
})

print

print(files: Array<string>, callback: AsyncCallback<PrintTask>): void

Prints files. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.PRINT

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |file|Array<string>|Yes|List of files to print. Images in .jpg, .png, .gif, .bmp, or .webp format are supported.| |callback|AsyncCallback<PrintTask>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

// Pass in the URIs of the files.
let file = ['file://data/print/a.png', 'file://data/print/b.png'];
// Alternatively, pass in the file IDs.
//let file = ['fd://1', 'fd://2'];
print.print(file, (err: BusinessError, printTask: print.PrintTask) => {
    if (err) {
        console.log('print err ' + JSON.stringify(err));
    } else {
        printTask.on('succeed', () => {
            console.log('print state is succeed');
        })
        // ...
    }
})

print

print(files: Array<string>): Promise<PrintTask>

Prints files. This API uses a promise to return the result.

Required permissions: ohos.permission.PRINT

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |file|Array<string>|Yes|List of files to print. Images in .jpg, .png, .gif, .bmp, or .webp format are supported.|

Return value |Type|Description| |——–|——–| |Promise<PrintTask>|Print result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

// Pass in the URIs of the files.
let file = ['file://data/print/a.png', 'file://data/print/b.png'];
// Alternatively, pass in the file IDs.
//let file = ['fd://1', 'fd://2'];
print.print(file).then((printTask: print.PrintTask) => {
    printTask.on('succeed', () => {
        console.log('print state is succeed');
    })
    // ...
}).catch((error: BusinessError) => {
    console.log('print err ' + JSON.stringify(error));
})

PrintMargin

Defines the page margins for printing.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Attributes |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |top|number|No|Top margin of the page.| |bottom|number|No|Bottom margin of the page.| |left|number|No|Left margin of the page.| |right|number|No|Right margin of the page.|

PrinterRange

Defines the print range.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Attributes |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |startPage|number|No|Start page.| |endPage|number|No|End page.| |pages|Array<number>|No|Discrete pages.|

PreviewAttribute

Defines the print preview attributes.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Attributes |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |previewRange|PrinterRange|Yes|Preview page range.| |result|number|No|Print preview result.|

PrintResolution

Defines the resolution for printing.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Attributes |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |id|string|Yes|Resolution ID.| |horizontalDpi|number|Yes|Horizontal DPI.| |verticalDpi|number|Yes|Vertical DPI.|

PrintPageSize

Defines the size of the printed page.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Attributes |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |id|string|Yes|Page size ID.| |name|string|Yes|Page size name.| |width|number|Yes|Page width, in millimeters.| |height|number|Yes|Page height, in millimeters.|

PrinterCapability

Defines the printer capabilities.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Attributes |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |colorMode|number|Yes|Color mode.| |duplexMode|number|Yes|Single-sided or double-sided printing mode.| |pageSize|Array<PrintPageSize>|Yes|List of page sizes supported by the printer.| |resolution|Array<PrintResolution>|No|List of resolutions supported by the printer.| |minMargin|PrintMargin|No|Minimum margin of the printer.|

PrinterInfo

Provides the printer information.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Attributes |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerId|string|Yes|Printer ID.| |printerName|string|Yes|Printer name.| |printerState|PrinterState|Yes|Printer state.| |printerIcon|number|No|Resource ID of the printer icon.| |description|string|No|Printer description.| |capability|PrinterCapability|No|Printer capability.| |options|Object|No|Printer options. The value is a JSON object string.|

PrintJob

Defines a print job.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Attributes |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |fdList|Array<number>|Yes|FD list of files to print.| |jobId|string|Yes|ID of the print job.| |printerId|string|Yes|ID of the printer used for printing.| |jobState|PrintJobState|Yes|State of the print job.| |copyNumber|number|Yes|Copy of the file list.| |pageRange|PrinterRange|Yes|Print range.| |isSequential|boolean|Yes|Whether to enable sequential printing.| |pageSize|PrintPageSize|Yes|Selected page size.| |isLandscape|boolean|Yes|Whether to print in landscape mode.| |colorMode|number|Yes|Color mode.| |duplexMode|number|Yes|Single-sided or double-sided printing mode.| |margin|PrintMargin|No|Current page margin.| |preview|PreviewAttribute|No|Preview settings.| |options|Object|No|Printer options. The value is a JSON object string.|

PrinterState

Enumerates the printer states.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Name Value Description
PRINTER_ADDED 0 A new printer is added.
PRINTER_REMOVED 1 The printer is removed.
PRINTER_CAPABILITY_UPDATED 2 The printer is updated.
PRINTER_CONNECTED 3 The printer is connected.
PRINTER_DISCONNECTED 4 The printer is disconnected.
PRINTER_RUNNING 5 The printer is running.

PrintJobState

Enumerates the print job states.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Name Value Description
PRINT_JOB_PREPARE 0 The printer is prepared for the print job.
PRINT_JOB_QUEUED 1 The print job is on the print queue of the printer.
PRINT_JOB_RUNNING 2 The print job is being executed.
PRINT_JOB_BLOCKED 3 The print job is blocked.
PRINT_JOB_COMPLETED 4 The print job is complete.

PrintJobSubState

Enumerates the print job substates.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Name Value Description
PRINT_JOB_COMPLETED_SUCCESS 0 The print job is successful.
PRINT_JOB_COMPLETED_FAILED 1 The print job failed.
PRINT_JOB_COMPLETED_CANCELLED 2 The print job is canceled.
PRINT_JOB_COMPLETED_FILE_CORRUPTED 3 The print job is corrupted.
PRINT_JOB_BLOCK_OFFLINE 4 The printer is offline.
PRINT_JOB_BLOCK_BUSY 5 The printer is occupied by another process.
PRINT_JOB_BLOCK_CANCELLED 6 The print job is canceled.
PRINT_JOB_BLOCK_OUT_OF_PAPER 7 The printer is out of paper.
PRINT_JOB_BLOCK_OUT_OF_INK 8 The printer is out of ink.
PRINT_JOB_BLOCK_OUT_OF_TONER 9 The printer is out of toner.
PRINT_JOB_BLOCK_JAMMED 10 The printer is in a paper jam.
PRINT_JOB_BLOCK_DOOR_OPEN 11 The printer door is open.
PRINT_JOB_BLOCK_SERVICE_REQUEST 12 Print service request.
PRINT_JOB_BLOCK_LOW_ON_INK 13 The printer is low on ink.
PRINT_JOB_BLOCK_LOW_ON_TONER 14 The printer is low on toner.
PRINT_JOB_BLOCK_REALLY_LOW_ON_INK 15 The printer is extremely low on ink.
PRINT_JOB_BLOCK_BAD_CERTIFICATE 16 The print certificate is incorrect.
PRINT_JOB_BLOCK_UNKNOWN 99 An unknown print error occurs.

PrintErrorCode

Enumerates the print error codes.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Name Value Description
E_PRINT_NONE 0 No error.
E_PRINT_NO_PERMISSION 201 No permission.
E_PRINT_INVALID_PARAMETER 401 Invalid parameter.
E_PRINT_GENERIC_FAILURE 13100001 Printing failure.
E_PRINT_RPC_FAILURE 13100002 RPC failure.
E_PRINT_SERVER_FAILURE 13100003 Print service failure.
E_PRINT_INVALID_EXTENSION 13100004 Invalid printer extension.
E_PRINT_INVALID_PRINTER 13100005 Invalid printer.
E_PRINT_INVALID_PRINT_JOB 13100006 Invalid print job.
E_PRINT_FILE_IO 13100007 Incorrect file input/output.

PrinterExtensionInfo

Provides the printer extension information.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Attributes |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |extensionId|string|Yes|ID of the printer extension.| |vendorId|string|Yes|Vendor ID of the printer extension.| |vendorName|string|Yes|Vendor name of the printer extension.| |vendorIcon|number|Yes|Vendor icon of the printer extension.| |version|string|Yes|Version of the printer extension.|

queryAllPrinterExtensionInfos

queryAllPrinterExtensionInfos(callback: AsyncCallback<Array<PrinterExtensionInfo>>): void

Obtains the information of all installed printer extensions. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |callback|AsyncCallback<Array<PrinterExtensionInfo>>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

print.queryAllPrinterExtensionInfos((err: BusinessError, extensionInfos: print.PrinterExtensionInfo[]) => {
    if (err) {
        console.log('queryAllPrinterExtensionInfos err ' + JSON.stringify(err));
    } else {
        console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos));
    }
})

queryAllPrinterExtensionInfos

queryAllPrinterExtensionInfos(): Promise<Array<PrinterExtensionInfo>>

Obtains the information of all installed printer extensions. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Return value |Type|Description| |——–|——–| |Promise<Array<PrinterExtensionInfo>>|Promise used to return the result.used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

print.queryAllPrinterExtensionInfos().then((extensionInfos: print.PrinterExtensionInfo[]) => {
    console.log('queryAllPrinterExtensionInfos success ' + JSON.stringify(extensionInfos));
    // ...
}).catch((error: BusinessError) => {
    console.log('failed to get AllPrinterExtension bacause ' + JSON.stringify(error));
})

startDiscoverPrinter

startDiscoverPrinter(extensionList: Array<string>, callback: AsyncCallback<void>): void

Starts discovering printers with the specified printer extensions. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |extensionList|Array<string>|Yes|List of printer extensions to load.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let extensionList: string[] = [];
// If there is no information in extensionList, all extensions are used for printer discovery.
print.startDiscoverPrinter(extensionList, (err: BusinessError, data : void) => {
    if (err) {
        console.log('failed to start Discover Printer because : ' + JSON.stringify(err));
    } else {
        console.log('start Discover Printer success data : ' + JSON.stringify(data));
    }
})

startDiscoverPrinter

startDiscoverPrinter(extensionList: Array<string>): Promise<void>

Starts discovering printers with the specified printer extensions. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let extensionList: string[] = [];
// If there is no information in extensionList, all extensions are used for printer discovery.
print.startDiscoverPrinter(extensionList).then((data : void) => {
    console.log('start Discovery success data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('failed to start Discovery because : ' + JSON.stringify(error));
})

stopDiscoverPrinter

stopDiscoverPrinter(callback: AsyncCallback<void>): void

Stops discovering printers with the specified printer extensions. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

print.stopDiscoverPrinter((err: BusinessError, data : void) => {
    if (err) {
        console.log('failed to stop Discover Printer because : ' + JSON.stringify(err));
    } else {
        console.log('stop Discover Printer success data : ' + JSON.stringify(data));
    }
})

stopDiscoverPrinter

stopDiscoverPrinter(): Promise<void>

Stops discovering printers with the specified printer extensions. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

print.stopDiscoverPrinter().then((data : void) => {
    console.log('stop Discovery success data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('failed to stop Discovery because : ' + JSON.stringify(error));
})

connectPrinter

connectPrinter(printerId: string, callback: AsyncCallback<void>): void

Connects to the specified printer. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerId|string|Yes|Printer ID.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerId: string = 'printerId_32';
print.connectPrinter(printerId, (err: BusinessError, data : void) => {
    if (err) {
        console.log('failed to connect Printer because : ' + JSON.stringify(err));
    } else {
        console.log('start connect Printer success data : ' + JSON.stringify(data));
    }
})

connectPrinter

connectPrinter(printerId: string): Promise<void>

Connects to the specified printer. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerId|string|Yes|Printer ID.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerId: string = 'printerId_32';
print.connectPrinter(printerId).then((data : void) => {
    console.log('start connect Printer success data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('failed to connect Printer because : ' + JSON.stringify(error));
})

disconnectPrinter

disconnectPrinter(printerId: string, callback: AsyncCallback<void>): void

Disconnects from the specified printer. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerId|string|Yes|Printer ID.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerId: string = 'printerId_32';
print.disconnectPrinter(printerId, (err: BusinessError, data : void) => {
    if (err) {
        console.log('failed to disconnect Printer because : ' + JSON.stringify(err));
    } else {
        console.log('start disconnect Printer success data : ' + JSON.stringify(data));
    }
})

disconnectPrinter

disconnectPrinter(printerId: string): Promise<void>

Disconnects from the specified printer. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerId|string|Yes|Printer ID.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerId: string = 'printerId_32';
print.disconnectPrinter(printerId).then((data : void) => {
    console.log('start disconnect Printer success data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('failed to disconnect Printer because : ' + JSON.stringify(error));
})

queryPrinterCapability

queryPrinterCapability(printerId: string, callback: AsyncCallback<void>): void

Queries the printer capability. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerId|string|Yes|Printer ID.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerId: string = 'printerId_32';
print.queryPrinterCapability(printerId, (err: BusinessError, data : void) => {
    if (err) {
        console.log('failed to query Printer Capability because : ' + JSON.stringify(err));
    } else {
        console.log('start query Printer Capability success data : ' + JSON.stringify(data));
    }
})

queryPrinterCapability

queryPrinterCapability(printerId: string): Promise<void>

Queries the printer capability. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerId|string|Yes|Printer ID.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerId: string = 'printerId_32';
print.queryPrinterCapability(printerId).then((data : void) => {
    console.log('start query Printer success data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('failed to query Printer Capability because : ' + JSON.stringify(error));
})

startPrintJob

startPrintJob(jobInfo: PrintJob, callback: AsyncCallback<void>): void

Starts the specified print job. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |jobInfo|PrintJob|Yes|Information about the print job.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let jobInfo : print.PrintJob = {
    fdList : [0,1],
    jobId : 'jobId_12',
    printerId : 'printerId_32',
    jobState : 3,
    copyNumber : 1,
    pageRange : {},
    isSequential : false,
    pageSize : {id : '', name : '', width : 10, height : 20},
    isLandscape : false,
    colorMode : 6,
    duplexMode : 6,
    margin : undefined,
    preview : undefined,
    options : undefined
};
print.startPrintJob(jobInfo, (err: BusinessError, data : void) => {
    if (err) {
        console.log('failed to start Print Job because : ' + JSON.stringify(err));
    } else {
        console.log('start Print Job success data : ' + JSON.stringify(data));
    }
})

startPrintJob

startPrintJob(jobInfo: PrintJob): Promise<void>

Starts the specified print job. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |jobInfo|PrintJob|Yes|Information about the print job.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let jobInfo : print.PrintJob = {
    fdList : [0,1],
    jobId : 'jobId_12',
    printerId : 'printerId_32',
    jobState : 3,
    copyNumber : 1,
    pageRange : {},
    isSequential : false,
    pageSize : {id : '', name : '', width : 10, height : 20},
    isLandscape : false,
    colorMode : 6,
    duplexMode : 6,
    margin : undefined,
    preview : undefined,
    options : undefined
};
print.startPrintJob(jobInfo).then((data : void) => {
    console.log('start Print success data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('failed to start Print because : ' + JSON.stringify(error));
})

cancelPrintJob

cancelPrintJob(jobId: string, callback: AsyncCallback<void>): void

Cancels the specified print job, which is on the print queue of the printer. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |jobId|string|Yes|Print job ID.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let jobId : string = '121212';
print.cancelPrintJob(jobId, (err: BusinessError, data : void) => {
    if (err) {
        console.log('cancelPrintJob failed, because : ' + JSON.stringify(err));
    } else {
        console.log('cancelPrintJob success, data: ' + JSON.stringify(data));
    }
})

cancelPrintJob

cancelPrintJob(jobId: string): Promise<void>

Cancels the specified print job, which is on the print queue of the printer. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |jobId|string|Yes|Print job ID.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let jobId : string = '121212';
print.cancelPrintJob(jobId).then((data : void) => {
    console.log('cancelPrintJob success, data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('cancelPrintJob failed, because : ' + JSON.stringify(error));
})

requestPrintPreview

requestPrintPreview(jobInfo: PrintJob, callback: Callback<number>): void

Requests print preview data. This API uses a callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |jobInfo|PrintJob|Yes|Information about the print job.| |callback|Callback<number>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';

let jobInfo : print.PrintJob = {
    fdList : [0,1],
    jobId : 'jobId_12',
    printerId : 'printerId_32',
    jobState : 3,
    copyNumber : 1,
    pageRange : {},
    isSequential : false,
    pageSize : {id : '', name : '', width : 10, height : 20},
    isLandscape : false,
    colorMode : 6,
    duplexMode : 6,
    margin : undefined,
    preview : undefined,
    options : undefined
};
print.requestPrintPreview(jobInfo, (num : number) => {
    console.log('requestPrintPreview success, num : ' + JSON.stringify(num));

})

requestPrintPreview

requestPrintPreview(jobInfo: PrintJob): Promise<number>

Requests print preview data. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |jobInfo|PrintJob|Yes|Information about the print job.|

Return value |Type|Description| |——–|——–| |Promise<number>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let jobInfo : print.PrintJob = {
    fdList : [0,1],
    jobId : 'jobId_12',
    printerId : 'printerId_32',
    jobState : 3,
    copyNumber : 1,
    pageRange : {},
    isSequential : false,
    pageSize : {id : '', name : '', width : 10, height : 20},
    isLandscape : false,
    colorMode : 6,
    duplexMode : 6,
    margin : undefined,
    preview : undefined,
    options : undefined
};
print.requestPrintPreview(jobInfo).then((num: number) => {
    console.log('requestPrintPreview success, num : ' + JSON.stringify(num));
}).catch((error: BusinessError) => {
    console.log('requestPrintPreview failed, because : ' + JSON.stringify(error));
})

on

on(type: ‘printerStateChange’, callback: (state: PrinterState, info: PrinterInfo) => void): void

Registers a listener for printer state change events. This API uses a callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|‘printerStateChange’|Yes|Listening type. The value is fixed at ‘printerStateChange’.| |callback|(state: PrinterState, info: PrinterInfo) => void|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';

print.on('printerStateChange', (state: print.PrinterState, info: print.PrinterInfo) => {
    if (state === null||info === null) {
        console.log('printer state changed state is null or info is null');
        return;
    } else {
        console.log('on printer state changed, state : ' + JSON.stringify(state));
        console.log('on printer state changed, info : ' + JSON.stringify(info));
    }
})

off

off(type: ‘printerStateChange’, callback?: Callback<boolean>): void

Unregisters the listener for printer state change events. This API uses a callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|‘printerStateChange’|Yes|Listening type. The value is fixed at ‘printerStateChange’.| |callback|Callback<boolean>|No|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

print.off('printerStateChange', (err: BusinessError, data: boolean) => {
    if (err) {
        console.log('off printerStateChange failed, because : ' + JSON.stringify(err));
    } else {
        console.log('off printerStateChange data : ' + JSON.stringify(data));
    }
})

on

on(type: ‘jobStateChange’, callback: (state: PrintJobState, job: PrintJob) => void): void

Registers a listener for print job state change events. This API uses a callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|‘jobStateChange’|Yes|Listening type. The value is fixed at ‘jobStateChange’.| |callback|(state: PrintJobState, job: PrintJob) => void|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';

print.on('jobStateChange', (state: print.PrintJobState, job: print.PrintJob) => {
    console.log('onJobStateChange, state : ' + JSON.stringify(state) + ', job : ' + JSON.stringify(job));
})

off

off(type: ‘jobStateChange’, callback?: Callback<boolean>): void

Unregisters the listener for print job state change events. This API uses a callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|‘jobStateChange’|Yes|Listening type. The value is fixed at ‘jobStateChange’.| |callback|Callback<boolean>|No|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

print.off('jobStateChange', (err: BusinessError, data: boolean) => {
    if (err) {
        console.log('offJobStateChanged failed, because : ' + JSON.stringify(err));
    } else {
        console.log('offJobStateChanged data : ' + JSON.stringify(data));
    }
})

on

on(type: ‘extInfoChange’, callback: (extensionId: string, info: string) => void): void

Registers a listener for printer extension information change events. This API uses a callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|‘extInfoChange’|Yes|Listening type. The value is fixed at ‘extInfoChange’.| |callback|(extensionId: string, info: string) => void|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';

print.on('extInfoChange', (extensionId: string, info: string) => {
    console.log('onExtInfoChange, entensionId : ' + JSON.stringify(extensionId) + ', info : ' + JSON.stringify(info));
})

off

off(type: ‘extInfoChange’, callback?: Callback<boolean>): void

Unregisters the listener for printer extension information change events. This API uses a callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |type|‘extInfoChange’|Yes|Listening type. The value is fixed at ‘extInfoChange’.| |callback|Callback<boolean>|No|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

print.off('extInfoChange', (err: BusinessError, data: boolean) => {
    if (err) {
        console.log('offExtInfoChange failed, because : ' + JSON.stringify(err));
    } else {
        console.log('offExtInfoChange data : ' + JSON.stringify(data));
    }
})

addPrinters

addPrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void

Adds printers. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printers|Array<PrinterInfo>|Yes|List of printers to add.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerInfo : print.PrinterInfo = {
    printerId : '3232',
    printerName : 'hhhhh',
    printerState : 0,
    printerIcon : 12,
    description : 'str',
    capability : undefined,
    options : 'opt'
};
print.addPrinters([printerInfo], (err: BusinessError, data : void) => {
    if (err) {
        console.log('addPrinters failed, because : ' + JSON.stringify(err));
    } else {
        console.log('addPrinters success, data : ' + JSON.stringify(data));
    }
})

addPrinters

addPrinters(printers: Array<PrinterInfo>): Promise<void>

Adds printers. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printers|Array<PrinterInfo>|Yes|List of printers to add.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerInfo : print.PrinterInfo = {
    printerId : '3232',
    printerName : 'hhhhh',
    printerState : 0,
    printerIcon : 12,
    description : 'str',
    capability : undefined,
    options : 'opt'
};
print.addPrinters([printerInfo]).then((data : void) => {
    console.log('add printers data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('add printers error : ' + JSON.stringify(error));
})

removePrinters

removePrinters(printerIds: Array<string>, callback: AsyncCallback<void>): void

Removes printers. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerIds|Array<string>|Yes|List of printers to remove.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerId : string = '1212';
print.removePrinters([printerId], (err: BusinessError, data : void) => {
    if (err) {
        console.log('removePrinters failed, because : ' + JSON.stringify(err));
    } else {
        console.log('removePrinters success, data : ' + JSON.stringify(data));
    }
})

removePrinters

removePrinters(printerIds: Array<string>): Promise<void>

Removes printers. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerIds|Array<string>|Yes|List of printers to remove.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerId : string = '1212';
print.removePrinters([printerId]).then((data : void) => {
    console.log('remove printers data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('remove printers error : ' + JSON.stringify(error));
})

updatePrinters

updatePrinters(printers: Array<PrinterInfo>, callback: AsyncCallback<void>): void

Updates information about the specified printers. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printers|Array<PrinterInfo>|Yes|List of printers whose information is to be updated.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerInfo : print.PrinterInfo = {
    printerId : '3232',
    printerName : 'hhhhh',
    printerState : 0,
    printerIcon : 12,
    description : 'str',
    capability : undefined,
    options : 'opt'
};
print.updatePrinters([printerInfo], (err: BusinessError, data : void) => {
    if (err) {
        console.log('updataPrinters failed, because : ' + JSON.stringify(err));
    } else {
        console.log('updataPrinters success, data : ' + JSON.stringify(data));
    }
})

updatePrinters

updatePrinters(printers: Array<PrinterInfo>): Promise<void>

Updates information about the specified printers. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printers|Array<PrinterInfo>|Yes|List of printers whose information is to be updated.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerInfo : print.PrinterInfo = {
    printerId : '3232',
    printerName : 'hhhhh',
    printerState : 0,
    printerIcon : 12,
    description : 'str',
    capability : undefined,
    options : 'opt'
};
print.updatePrinters([printerInfo]).then((data : void) => {
    console.log('update printers data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('update printers error : ' + JSON.stringify(error));
})

updatePrinterState

updatePrinterState(printerId: string, state: PrinterState, callback: AsyncCallback<void>): void

Updates the printer state. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerId|string|Yes|Printer ID.| |state|PrinterState|Yes|Printer state.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerId : string = '1212';
let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED;
print.updatePrinterState(printerId, state, (err: BusinessError, data : void) => {
    if (err) {
        console.log('updataPrinterState failed, because : ' + JSON.stringify(err));
    } else {
        console.log('updataPrinterState success, data : ' + JSON.stringify(data));
    }
})

updatePrinterState

updatePrinterState(printerId: string, state: PrinterState): Promise<void>

Updates the printer state. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |printerId|string|Yes|Printer ID.| |state|PrinterState|Yes|Printer state.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let printerId : string = '1212';
let state : print.PrinterState = print.PrinterState.PRINTER_CONNECTED;
print.updatePrinterState(printerId, state).then((data : void) => {
    console.log('update printer state data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('update printer state error : ' + JSON.stringify(error));
})

updatePrintJobState

updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState, callback: AsyncCallback<void>): void

Updates the print job state. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |jobId|string|Yes|ID of the print job.| |state|PrintJobState|Yes|State of the print job.| |subState|PrintJobSubState|Yes|Substate of the print job.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let jobId : string = '3434';
let state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE;
let subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS;
print.updatePrintJobState(jobId, state, subState, (err: BusinessError, data : void) => {
    if (err) {
        console.log('updataPrintJobState failed, because : ' + JSON.stringify(err));
    } else {
        console.log('updatePrintJobState success, data : ' + JSON.stringify(data));
    }
})

updatePrintJobState

updatePrintJobState(jobId: string, state: PrintJobState, subState: PrintJobSubState): Promise<void>

Updates the print job state. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |jobId|string|Yes|ID of the print job.| |state|PrintJobState|Yes|State of the print job.| |subState|PrintJobSubState|Yes|Substate of the print job.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let jobId : string = '3434';
let state : print.PrintJobState = print.PrintJobState.PRINT_JOB_PREPARE;
let subState : print.PrintJobSubState = print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS;
print.updatePrintJobState(jobId, state, subState).then((data : void) => {
    console.log('update print job state data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('update print job state error : ' + JSON.stringify(error));
})

updateExtensionInfo

updateExtensionInfo(info: string, callback: AsyncCallback<void>): void

Updates the printer extension information. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |info|string|Yes|New printer extension information.| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let info : string = 'WIFI_INACTIVE';
print.updateExtensionInfo(info, (err: BusinessError, data : void) => {
    if (err) {
        console.log('updateExtensionInfo failed, because : ' + JSON.stringify(err));
    } else {
        console.log('updateExtensionInfo success, data : ' + JSON.stringify(data));
    }
})

updateExtensionInfo

updateExtensionInfo(info: string): Promise<void>

Updates the printer extension information. This API uses a promise to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |info|string|Yes|New printer extension information.|

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

let info : string = 'WIFI_INACTIVE';
print.updateExtensionInfo(info).then((data : void) => {
    console.log('update print job state data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('update print job state error : ' + JSON.stringify(error));
})

queryAllPrintJobs

queryAllPrintJobs(callback: AsyncCallback<void>): void

Queries all print jobs. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Parameters |Name|Type|Mandatory|Description| |——–|——–|——–|——–| |callback|AsyncCallback<void>|Yes|Callback used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

print.queryAllPrintJobs((err: BusinessError, data : void) => {
    if (err) {
        console.log('queryAllPrintJobs failed, because : ' + JSON.stringify(err));
    } else {
        console.log('queryAllPrintJobs success, data : ' + JSON.stringify(data));
    }
})

queryAllPrintJobs

queryAllPrintJobs(): Promise<void>

Queries all print jobs. This API uses a promise used to return the result.

Required permissions: ohos.permission.MANAGE_PRINT_JOB

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Return value |Type|Description| |——–|——–| |Promise<void>|Promise used to return the result.|

Example

import print from '@ohos.print';
import { BusinessError } from '@ohos.base';

print.queryAllPrintJobs().then((data : void) => {
    console.log('update print job state data : ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
    console.log('update print job state error : ' + JSON.stringify(error));
})

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞