提示
本插件在浏览器接口__printer的基础上扩展了远程使用打印的功能
# 获取打印机的状态信息 getPrinterState
获取打印机的状态信息
type ReqBody = {
deviceName: string,//打印机设备名称
}
type ResBody = {
resultCode: number,//0表示成功,-1或其他表示失败
resultMessage: string, //具体错误信息
data?: object //打印机列表数据
}
zwexplorer.SystemPrinter.getPrinterState(
data: {deviceName: 'XXX'},
callback?: (res: ResBody)=>void
): Promise<ResBody>
参数 | 类型 | 必然存在 | 说明 |
---|---|---|---|
data.deviceName | String | 否 | 需要查询的打印机设备名称 |
参数 | 类型 | 必然存在 | 说明 |
---|---|---|---|
res.resultCode | Number | 是 | 接口返回的状态码 |
res.resultMessage | String | 是 | 接口返回的信息 |
res.data | Array | 否 | 打印机的状态信息,传入的参数deviceName不存在或为空时返回系统默认打印机的数据 |
res.data.connected | Boolean | 否 | 是否已经连接 (linux系统中没有) |
res.data.name | String | 否 | 打印机的名称 |
res.data.jobs | Array | 否 | 打印机任务队列 |
res.data.jobs[index] | Array | 否 | 打印机任务队列中任务的信息,index为任务的序号 |
res.data.jobs[index].id | Number | 否 | id |
res.data.jobs[index].name | String | 否 | 打印机名称 |
res.data.jobs[index].document | Number | 否 | 文件路径 |
res.data.jobs[index].format | String | 否 | 打印数据格式 |
res.data.jobs[index].startTime | Number | 否 | 开始打印的时间戳 |
res.data.jobs[index].size | Number | 否 | 打印字节大小 |
res.data.jobs[index].user | Number | 否 | 用户名 |
res.data.jobs[index].totalPages | Number | 否 | 打印总页数(linux系统中没有) |
res.data.jobs[index].driverName | String | 否 | 打印机驱动程序名称(linux系统中没有) |
res.data.jobs[index].pagesPrinted | Number | 否 | 已打印页数(linux系统中没有) |
res.data.jobs[index].machineName | Number | 否 | 任务使用打印机的机器名称(linux系统中没有) |
zwexplorer.SystemPrinter.getPrinterState({}, (res) => {});
# 获取打印机列表 getPrinters
获取打印机列表
type ResBody = {
resultCode: number,//0表示成功,-1或其他表示失败
resultMessage: string, //具体错误信息
data?: array //打印机列表数据
}
zwexplorer.SystemPrinter.getPrinters(
data: {},
callback?: (res: ResBody)=>void
): Promise<ResBody>
参数 | 类型 | 必然存在 | 说明 |
---|---|---|---|
res.resultCode | Number | 是 | 接口返回的状态码 |
res.resultMessage | Boolean | 是 | 接口返回的信息 |
res.data | Array | 否 | 打印机的列表数据 |
res.data[index] | Object | 否 | 打印机的信息,index为数组序号 |
res.data[index].description | String | 否 | 打印机描述信息 |
res.data[index].displayName | String | 否 | 打印机展示名称 |
res.data[index].isDefault | Boolean | 否 | 是否为系统默认打印机 |
res.data[index].name | String | 否 | 打印机名称 |
res.data[index].options | Object | 否 | 打印机属性信息 |
res.data[index].status | Number | 否 | 打印机状态码 |
zwexplorer.SystemPrinter.getPrinters({}, (res) => {});
# 打印pdf文件 printPdf
提示
在Linux系统(信创环境)中,color属性参数无法使用,
需要预生成对应的类别(彩色或黑白)的PDF
打印 pdf 文件
type PageRanges= {
from: number;
to: number;
}
type printObj={
deviceName?: string;//打印设备的名称
color?: boolean;//是否彩色打印,默认为true
landscape?: boolean;//打印方向,false为纵向,true为横向。默认为false
copies?: number;//打印副本数量
pageRanges?: PageRanges[];//打印的具体页数,从某页到某页
pageSize?: "A3" | "A4" | "A5" ; //打印纸张格式,值为`A3`, `A4`, `A5`
duplexMode?:('duplex'| 'duplexshort'| 'duplexlong' 'simplex')
}
type ReqBody = {
data?: string, //pdf的base64字符串 或 本地路径 或 在线url
options?: printObj
}
type ResBody = {
resultCode: number,//0表示成功,-1或其他表示失败
resultMessage: string, //具体错误信息
data?: any //保留备用
}
zwexplorer.SystemPrinter.printPdf(
data: ReqBody,
callback?: (res: ResBody)=>void
): Promise<ResBody>
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
req.data | String | 是 | 需要打印的pdf的base64字符串 或 本地路径 或 在线url |
req.options | Object | 否 | 打印网页时的打印参数 |
req.options.deviceName | String | 否 | 打印机的设备名 |
req.options.color | Boolean | 否 | 是否彩色打印,true 为彩色,false 为黑白,默认为 true |
req.options.copies | Number | 否 | 打印份数,默认为 1 份 |
req.options.pageRanges | PageRanges[] | 否 | 打印页数 |
req.options.pageRanges[index].from | Number | 否 | 起始页,index 为数组序数 |
req.options.pageRanges[index].to | Number | 否 | 结束页,index 为数组序数 |
req.options.landscape | Boolean | 否 | 是否竖向打印,false 为竖向,true 为横向 |
req.options.pageSize | Boolean | 否 | 打印纸张尺寸,取值为'A3' |
参数 | 类型 | 必然存在 | 说明 |
---|---|---|---|
res.resultCode | Object | 是 | 返回调用弹窗接口的入参 |
res.resultMessage | Boolean | 是 | 返回点击弹窗的按钮结果 |
let req = {
data: "https://demo.zwexplorer.com/native-api/resources/5%E5%8F%B7%E6%96%87.pdf",
options: { pageSize: "A4", color: false },
};
zwexplorer.SystemPrinter.printPdf(req, (res) => {});
# 打印网页 printPage
提示
由于插件无法使用浏览器的页面权限,
无法打印当前网页地址,
需要使用打印当前页请使用 __printer.printPage
打印网页,支持在线网址。
type Margins = {
//只有在值为custom的情况下才需要以下四个方位的外边距参数
marginType?: ('default' | 'none' | 'custom');
top?: number;
bottom?: number;
left?: number;
right?: number;
}
type PageRanges = {
from: number;
to: number;
}
type printPageOpt = {
silent?: boolean;
printBackground?: boolean;
deviceName?: string;
color?: boolean;
margins?: Margins;
landscape?: boolean;
scaleFactor?: number;
pagesPerSheet?: number;
copies?: number;
pageRanges?: PageRanges[];
duplexMode?: ('simplex' | 'shortEdge' | 'longEdge');
dpi?: Record<string, number>;
pageSize?: (string) | (Size);
}
type ReqBody = {
data?: string,
options?: printPageOpt
}
type ResBody = {
resultCode: number,//0表示成功,-1或其他表示失败
resultMessage: string, //具体错误信息
data?: any //保留备用
}
zwexplorer.SystemPrinter.printPage(
req: ReqBody,
callback?: (res: ResBody)=>void
): Promise<ResBody>
● 请求参数
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
req.data | String | 是 | 需要打印的网页url地址 |
req.options | Object | 否 | 打印网页时的打印参数 |
req.options.deviceName | String | 否 | 打印机的设备名 |
req.options.color | Boolean | 否 | 是否彩色打印,true为彩色,false为黑白,默认为true |
req.options.copies | Number | 否 | 打印份数,默认为1份 |
req.options.dpi | Number | 否 | 打印质量,默认为300 |
req.options.pageRanges | PageRanges[] | 否 | 打印页数 |
req.options.pageRanges[index].from | Number | 否 | 起始页,index为数组序数 |
req.options.pageRanges[index].to | Number | 否 | 结束页,index为数组序数 |
req.options.margins | Margins | 否 | 边距 |
req.options.margins.marginType | String | 否 | 默认、无、自定义:('default' | 'none' | 'custom') |
req.options.margins.top | Number | 否 | 上边距 |
req.options.margins.right | Number | 否 | 右边距 |
req.options.margins.bottom | Number | 否 | 下边距 |
req.options.margins.left | Number | 否 | 左边距 |
req.options.slient | Boolean | 否 | 是否静默打印,true为静默打印 |
req.options.landscape | Boolean | 否 | 是否竖向打印,false为竖向,true为横向 |
req.options.printBackground | Boolean | 否 | 是否带背景颜色打印 |
req.options.headerFooter | Boolean | 否 | 是否带页头和页尾打印 |
req.options.scaleFactor | Boolean | 否 | 缩放大小,取值为1~100,默认为100 |
req.options.pageSize | Boolean | 否 | 打印纸张尺寸,取值为'A3' | 'A4' | 'A5' |
参数 | 类型 | 必然存在 | 说明 |
---|---|---|---|
res.resultCode | Number | 是 | 打印成功与否的状态码,-1 为打印失败,0 为打印成功 |
res.resultMessage | String | 是 | 返回是否打印成功的消息提示 |
let req = { data: "www.baidu.com", options: { pageSize: "A4", copies: 2 } };
zwexplorer.SystemPrinter.printPage(req, (res) => {});