1. Print 打印

1.1. API 调用

1.1.1. QN.print(options)

打印文档或图片

API 调用入参

参数名 类型 是否可选 默认值 含义
options Object 选项
options.query Object 调用参数
options.query.type String 文件类型:image html pdf
options.query.dataType String 数据类型,即 options.query.data 的类型,可选:string base64 url localpath
options.query.data String 文件的数据

各种数据类型的含义:

  • string - 纯文本或字符串
  • base64 - 文件的base64数据
  • url - URL
  • localpath - 本地路径

文件数据类型支持情况

文件类型 数据类型
image base64 url localpath
html string url localpath
pdf url localpath

API 响应结果

参数名 类型 是否一定返回 含义
result Object 响应对象
result.code String 错误码,成功为 QAP_SUCCESS;失败为其他
result.msg String 错误信息

调用示例

// 打印图片
QN.print({
    query: {
        type: 'image',
        dataType: 'base64',
        data: 'iVBORw0KGgoAAAANSUhEUgAAAgAAAA...',
    }
})
.then(result => {
    console.log(result);
})
.catch(error => {
    console.log(error);
});

QN.print({
    query: {
        type: 'image',
        dataType: 'url',
        data: 'https://gw.alicdn.com/tps/TB12TMIPXXXXXbyXpXXXXXXXXXX-750-400.jpg',
    }
})
.then(result => {
    console.log(result);
})
.catch(error => {
    console.log(error);
});
// 打印 HTML
QN.print({
    query: {
        type: 'html',
        dataType: 'string',
        data: '<h1>Hello Print</h1><p>This is html code for print.</p>',
    }
})
.then(result => {
    console.log(result);
})
.catch(error => {
    console.log(error);
});

QN.print({
    query: {
        type: 'html',
        dataType: 'url',
        data: 'https://h5.m.taobao.com/qn/pc/niuba-feeds.html#/detail/10402433?_k=by6n1l',
    }
})
.then(result => {
    console.log(result);
})
.catch(error => {
    console.log(error);
});
// 打印 PDF
QN.print({
    query: {
        type: 'pdf',
        dataType: 'localpath',
        data: '/path/to/foo.pdf',
    }
})
.then(result => {
    console.log(result);
})
.catch(error => {
    console.log(error);
});

results matching ""

    No results matching ""