@ohos.print (Print) (System API)

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. This topic describes only system APIs provided by the module. For details about its public APIs, see @ohos.print (Print).

Modules to Import

import { print } from '@kit.BasicServicesKit';

PrinterExtensionInfo

Provides the printer extension information.

System API: This is a system API.

System capability: SystemCapability.Print.PrintFramework

Attributes

Name Type Read-Only Optional Description
extensionId string No No ID of the printer extension.
vendorId string No No Vendor ID of the printer extension.
vendorName string No No Vendor name of the printer extension.
vendorIcon number No No Vendor icon of the printer extension.
version string No No Version of the printer extension.

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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 information of all installed printer extensions.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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 that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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 that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let jobInfo : print.PrintJob = {
    fdList : [44,45],
    jobId : 'jobId_12',
    printerId : 'printerId_32',
    jobState : print.PrintJobState.PRINT_JOB_COMPLETED,
    jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS,
    copyNumber : 1,
    pageRange : {},
    isSequential : false,
    pageSize : {id : '', name : '', width : 10, height : 20},
    isLandscape : false,
    colorMode : print.PrintColorMode.COLOR_MODE_COLOR,
    duplexMode : print.PrintDuplexMode.DUPLEX_MODE_NONE,
    margin : undefined,
    preview : undefined,
    options : undefined
};
print.startPrintJob(jobInfo, (err: BusinessError) => {
    if (err) {
        console.error('failed to start Print Job because : ' + JSON.stringify(err));
    } else {
        console.info('start Print Job success');
    }
})

print.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 that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let jobInfo : print.PrintJob = {
    fdList : [44,45],
    jobId : 'jobId_12',
    printerId : 'printerId_32',
    jobState : print.PrintJobState.PRINT_JOB_COMPLETED,
    jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS,
    copyNumber : 1,
    pageRange : {},
    isSequential : false,
    pageSize : {id : '', name : '', width : 10, height : 20},
    isLandscape : false,
    colorMode : print.PrintColorMode.COLOR_MODE_COLOR,
    duplexMode : print.PrintDuplexMode.DUPLEX_MODE_NONE,
    margin : undefined,
    preview : undefined,
    options : undefined
};
print.startPrintJob(jobInfo).then(() => {
    console.info('start Print success');
}).catch((error: BusinessError) => {
    console.error('failed to start Print because : ' + JSON.stringify(error));
})

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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 that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.restartPrintJob20+

restartPrintJob(jobId: string): Promise<void>

Restarts a print job that has been finished before. 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 a print job that has been finished before.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';

let jobInfo : print.PrintJob = {
    fdList : [44,45],
    jobId : 'jobId_12',
    printerId : 'printerId_32',
    jobState : PRINT_JOB_COMPLETED,
    jobSubstate : print.PrintJobSubState.PRINT_JOB_COMPLETED_SUCCESS,
    copyNumber : 1,
    pageRange : {},
    isSequential : false,
    pageSize : {id : '', name : '', width : 10, height : 20},
    isLandscape : false,
    colorMode : COLOR_MODE_COLOR,
    duplexMode : DUPLEX_MODE_NONE,
    margin : undefined,
    preview : undefined,
    options : undefined
};
print.requestPrintPreview(jobInfo, (num : number) => {
    console.info('requestPrintPreview success, num : ' + JSON.stringify(num));

})

print.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 preview result.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';

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

print.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. The value true means that the operation is successful, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';

print.off('printerStateChange', (data: boolean) => {
    console.info('off printerStateChange data : ' + JSON.stringify(data));
})

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';

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

print.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. The value true means that the operation is successful, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';

print.off('jobStateChange', (data: boolean) => {
    console.info('offJobStateChanged data : ' + JSON.stringify(data));
})

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';

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

print.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. The value true means that the operation is successful, and false means the opposite.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';

print.off('extInfoChange', (data: boolean) => {
    console.info('offExtInfoChange data : ' + JSON.stringify(data));
})

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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 that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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 that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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 that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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 that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.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 that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.queryAllPrintJobs(deprecated)

This API is supported since API version 10 and deprecated since API version 11. You are advised to use queryPrintJobList instead.

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.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

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

print.queryAllPrintJobs(deprecated)

This API is supported since API version 10 and deprecated since API version 11. You are advised to use queryPrintJobList instead.

queryAllPrintJobs(): Promise<void>

Queries all print jobs. 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 that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

print.queryAllPrintJobs().then(() => {
    console.info('queryAllPrintJobs success');
}).catch((error: BusinessError) => {
    console.error('queryAllPrintJobs failed, error : ' + JSON.stringify(error));
})

print.queryAllActivePrintJobs20+

queryAllActivePrintJobs(): Promise<PrintJob[]>

Queries all active print jobs. 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<PrintJob[]> Promise used to return a list of all active print jobs.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

print.queryAllActivePrintJobs().then((printJobs : print.PrintJob[]) => {
    console.info('queryAllActivePrintJobs success, data : ' + JSON.stringify(printJobs));
}).catch((error: BusinessError) => {
    console.error('queryAllActivePrintJobs failed, error : ' + JSON.stringify(error));
})

print.queryPrintJobList11+

queryPrintJobList(callback: AsyncCallback<Array<PrintJob>>): 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<Array<PrintJob>> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

print.queryPrintJobList((err: BusinessError, printJobs : print.PrintJob[]) => {
    if (err) {
        console.error('queryPrintJobList failed, because : ' + JSON.stringify(err));
    } else {
        console.info('queryPrintJobList success, data : ' + JSON.stringify(printJobs));
    }
})

print.queryPrintJobList11+

queryPrintJobList(): Promise<Array<PrintJob>>

Queries all print jobs. 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<PrintJob>> Promise used to return a list of all print jobs.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

print.queryPrintJobList().then((printJobs : print.PrintJob[]) => {
    console.info('queryPrintJobList success, data : ' + JSON.stringify(printJobs));
}).catch((error: BusinessError) => {
    console.error('queryPrintJobList failed, error : ' + JSON.stringify(error));
})

print.queryPrintJobById11+

queryPrintJobById(jobId: string, callback: AsyncCallback<PrintJob>): void

Queries a print job by ID. 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.
callback AsyncCallback<PrintJob> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let jobId : string = '1';
print.queryPrintJobById(jobId, (err: BusinessError, printJob : print.PrintJob) => {
    if (err) {
        console.error('queryPrintJobById failed, because : ' + JSON.stringify(err));
    } else {
        console.info('queryPrintJobById success, data : ' + JSON.stringify(printJob));
    }
})

print.queryPrintJobById11+

queryPrintJobById(jobId: string): Promise<PrintJob>

Queries a print job by ID. 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.

Return value

Type Description
Promise<PrintJob> Promise used to return the queried print job.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let jobId : string = '1';
print.queryPrintJobById(jobId).then((printJob : print.PrintJob) => {
    console.info('queryPrintJobById data : ' + JSON.stringify(printJob));
}).catch((error: BusinessError) => {
    console.error('queryPrintJobById error : ' + JSON.stringify(error));
})

print.startGettingPrintFile11+

startGettingPrintFile(jobId: string, printAttributes: PrintAttributes, fd: number, onFileStateChanged: Callback<PrintFileCreationState>): void

Starts to obtain the print file. 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.
printAttributes PrintAttributes Yes Print attributes.
fd number Yes File descriptor.
onFileStateChanged Callback<PrintFileCreationState> Yes Callback for updating the file state.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';

let jobId : string= '1';
class MyPrintAttributes implements print.PrintAttributes {
    copyNumber?: number;
    pageRange?: print.PrintPageRange;
    pageSize?: print.PrintPageSize | print.PrintPageType;
    directionMode?: print.PrintDirectionMode;
    colorMode?: print.PrintColorMode;
    duplexMode?: print.PrintDuplexMode;
}

class MyPrintPageRange implements print.PrintPageRange {
    startPage?: number;
    endPage?: number;
    pages?: Array<number>;
}

class MyPrintPageSize implements print.PrintPageSize {
    id: string = '0';
    name: string = '0';
    width: number = 210;
    height: number = 297;
}

let printAttributes = new MyPrintAttributes();
printAttributes.copyNumber = 2;
printAttributes.pageRange = new MyPrintPageRange();
printAttributes.pageRange.pages = [1, 3];
printAttributes.pageSize = print.PrintPageType.PAGE_ISO_A3;
printAttributes.directionMode = print.PrintDirectionMode.DIRECTION_MODE_AUTO;
printAttributes.colorMode = print.PrintColorMode.COLOR_MODE_MONOCHROME;
printAttributes.duplexMode = print.PrintDuplexMode.DUPLEX_MODE_NONE;

let fd : number = 1;
print.startGettingPrintFile(jobId, printAttributes, fd, (state: print.PrintFileCreationState) => {
    console.info('onFileStateChanged success, data : ' + JSON.stringify(state));
})

print.notifyPrintService11+

notifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started', callback: AsyncCallback<void>): void

Notifies the print service of the spooler shutdown 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
jobId string Yes ID of the print job.
type 'spooler_closed_for_cancelled' | 'spooler_closed_for_started' Yes Spooler shutdown information.
callback AsyncCallback<void> Yes Callback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let jobId : string = '1';
print.notifyPrintService(jobId, 'spooler_closed_for_started', (err: BusinessError) => {
    if (err) {
        console.error('notifyPrintService failed, because : ' + JSON.stringify(err));
    } else {
        console.info('notifyPrintService success');
    }
})

print.notifyPrintService11+

notifyPrintService(jobId: string, type: 'spooler_closed_for_cancelled' | 'spooler_closed_for_started'): Promise<void>

Notifies the print service of the spooler shutdown 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
jobId string Yes ID of the print job.
type 'spooler_closed_for_cancelled' | 'spooler_closed_for_started' Yes Spooler shutdown information.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let jobId : string = '1';
print.notifyPrintService(jobId, 'spooler_closed_for_started').then(() => {
    console.info('notifyPrintService success');
}).catch((error: BusinessError) => {
    console.error('notifyPrintService error : ' + JSON.stringify(error));
})

print.getPrinterInfoById12+

getPrinterInfoById(printerId: string): Promise<PrinterInfo>

Obtains printer information based on the printer ID. 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<PrinterInfo> Promise used to return the printer information.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let printerId : string = '1';
print.getPrinterInfoById(printerId).then((printerInfo : print.PrinterInfo) => {
    console.info('getPrinterInfoById data : ' + JSON.stringify(printerInfo));
}).catch((error: BusinessError) => {
    console.error('getPrinterInfoById error : ' + JSON.stringify(error));
})

print.notifyPrintServiceEvent12+

notifyPrintServiceEvent(event: ApplicationEvent): Promise<void>

Notifies the print service of the print application events. 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
event ApplicationEvent Yes Print application events.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let event : print.ApplicationEvent = print.ApplicationEvent.APPLICATION_CREATED;
print.notifyPrintServiceEvent(event).then(() => {
    console.info('notifyPrintServiceEvent success');
}).catch((error: BusinessError) => {
    console.error('notifyPrintServiceEvent error : ' + JSON.stringify(error));
})

print.setPrinterPreferences18+

setPrinterPreferences(printerId: string, printerPreferences: PrinterPreferences): Promise<void>

Sets the printer preferences. 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.
printerPreferences PrinterPreferences Yes Printer preferences.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let printerId : string = 'testPrinterId';
let preferences : print.PrinterPreferences = {
    defaultDuplexMode: print.PrintDuplexMode.DUPLEX_MODE_NONE
};
print.setPrinterPreferences(printerId, preferences).then(() => {
    console.info('setPrinterPreferences success');
}).catch((error: BusinessError) => {
    console.error('setPrinterPreferences error : ' + JSON.stringify(error));
})

print.discoverUsbPrinters18+

discoverUsbPrinters(): Promise<Array<PrinterInformation>>

Discovers USB 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

Return value

Type Description
Promise<Array<PrinterInformation>> Promise used to return the information about the discovered USB printers.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

print.discoverUsbPrinters().then((printers : print.PrinterInformation[]) => {
    console.info('discoverUsbPrinters data : ' + JSON.stringify(printers));
}).catch((error: BusinessError) => {
    console.error('discoverUsbPrinters error : ' + JSON.stringify(error));
})

print.setDefaultPrinter18+

setDefaultPrinter(printerId: string, type: DefaultPrinterType): Promise<void>

Sets the default 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.
type DefaultPrinterType Yes Default printer type.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let printerId : string = '1';
let type : print.DefaultPrinterType = print.DefaultPrinterType.DEFAULT_PRINTER_TYPE_SET_BY_USER;
print.setDefaultPrinter(printerId, type).then(() => {
    console.info('setDefaultPrinter success');
}).catch((error: BusinessError) => {
    console.error('setDefaultPrinter error : ' + JSON.stringify(error));
})

print.notifyPrintServiceEvent18+

notifyPrintServiceEvent(event: ApplicationEvent, jobId: string): Promise<void>

Notifies the print service of the print application events. 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
event ApplicationEvent Yes Print application events.
jobId string Yes ID of the print job.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
401 Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let event : print.ApplicationEvent = print.ApplicationEvent.APPLICATION_CREATED;
let jobId : string = '1';
print.notifyPrintServiceEvent(event, jobId).then(() => {
    console.info('notifyPrintServiceEvent success');
}).catch((error: BusinessError) => {
    console.error('notifyPrintServiceEvent error : ' + JSON.stringify(error));
})

print.queryPrinterCapabilityByUri24+

queryPrinterCapabilityByUri(printerUri: string, printerId: string): Promise<PrinterCapabilities>

Queries the printer capability by the printer URI. 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

Model restriction: This API can be used only in the stage model.

Parameters

Name Type Mandatory Description
printerUri string Yes Printer URI.
printerId string Yes Printer ID.

Return value

Type Description
Promise<PrinterCapabilities> Promise used to return the printer capability.

Error codes

For details about the error codes, see Universal Error Codes and Print Service Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
13100005 Can not find the printer in system.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let printerUri : string = "testPrinterUri";
let printerId : string = "testPrinterId";
print.queryPrinterCapabilityByUri(printerUri, printerId).then((capabilities: print.PrinterCapabilities) => {
    console.info('queryPrinterCapabilityByUri success' + JSON.stringify(capabilities));
}).catch((error: BusinessError) => {
    console.error('queryPrinterCapabilityByUri error : ' + JSON.stringify(error));
})

print.addPrinterToCups24+

addPrinterToCups(printerUri: string, printerName: string, printerMake: string): Promise<boolean>

Adds a printer to CUPS. 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

Model restriction: This API can be used only in the stage model.

Parameters

Name Type Mandatory Description
printerUri string Yes Printer URI.
printerName string Yes Printer name.
printerMake string Yes Printer model.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true indicates that the operation is successful, and false indicates the opposite.

Error codes

For details about the error codes, see Universal Error Codes and Print Service Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application
13100003 Add a printer to cups failed.

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let printerUri : string = "testPrinterUri";
let printerName : string = "testPrinterName";
let printerMake : string = "testPrinterMake";

print.addPrinterToCups(printerUri, printerName, printerMake).then((result: boolean) => {
    console.info('addPrinterToCups success' + JSON.stringify(result));
}).catch((error: BusinessError) => {
    console.error('addPrinterToCups error : ' + JSON.stringify(error));
})

print.deletePrinterFromCups24+

deletePrinterFromCups(printerName: string): Promise<void>

Deletes a printer from CUPS. 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

Model restriction: This API can be used only in the stage model.

Parameters

Name Type Mandatory Description
printerName string Yes Printer name.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

ID Error Message
201 the application does not have permission to call this function.
202 not system application

Example

import { print } from '@kit.BasicServicesKit';
import { BusinessError } from '@kit.BasicServicesKit';

let printerName : string = "testPrinterName";

print.deletePrinterFromCups(printerName).then(() => {
    console.info('deletePrinterFromCups success');
}).catch((error: BusinessError) => {
    console.error('deletePrinterFromCups error : ' + JSON.stringify(error));
})