@wowjoy/print
v0.6.50
Published
report print utils
Downloads
22
Keywords
Readme
华卓平台中心打印工具
安装
npm install -S @wowjoy/printAPI
htmlPrint 打印html
语法
htmlPrint(ele: HTMLElement, isPreview?: boolean): promise使用方法
import {htmlPrint} from "@wowjoy/print"
htmlPrint(document.querySelector('.print')).then(() => {
console.log("htmlPrint success")
})函数定义
interface IHtmlPrintParams {
isPreview?: boolean,
printer?: number | undefined | string
}
export async function htmlPrint(ele: HTMLElement, params: IHtmlPrintParams): Promise<string>
export async function htmlPrint(ele: HTMLElement, isPreview?: boolean): Promise<string>参数
- ele
HTMLElement需要打印的 html 元素 - isPreview
boolean是否开启预览模式 - printer
string | number | undefind打印机名称 或者序号 可以通过 getPrinters 获取打印机列表
pdfPrint 打印 pdf 当 isPreview 为true 是 会用浏览器的打印 否则是静默打印
语法
import {pdfPrint} from "@wowjoy/print"
pdfPrint(pdfurl: string, isPreview?: boolean = false)函数定义
interface IPdfPrintParmas {
/* pdf 链接 */
url: string,
isPreview? : boolean,
printer?: undefined | string | number,
}
export async function pdfPrint(url: string, isPreview?: boolean): Promise<any>;
export async function pdfPrint(params: IPdfPrintParmas): Promise<any>;
参数
- pdfurl
string可以为具体的 http 链接 或者 存储服务返回的 key 值 如果不是http链接 会把他当成存储接口返回的key值 - isPreview
boolean是否开启预览模式 - printer
undefined | string | number打印机名称 或者序号 可以通过 getPrinters 获取打印机列表
templatePrint 配置模版的打印
import {templatePrint} from "@wowjoy/print"
async function templatePrint (templateId: string, params?:Record<string, any> | boolean, isPreview?: boolean) => Promise
函数定义
interface ITemplatePrintParams {
/* 模版id */
templateId: string,
/** 模版参数 */
params?: Record<string, string>,
/* 是否预览 */
isPreview?: boolean,
/* 打印机 name 或者 index 只有在静默打印的时候生效 */
printer?: string | number
}
export async function templatePrint(params: ITemplatePrint): Promise<string>
export async function templatePrint(templateId: string, params: Record<string, string>, isPreview?: boolean): Promise<string>
export async function templatePrint(templateId: string): Promise<string>
export async function templatePrint(templateId: string, isPreview: boolean): Promise<string>
参数
- templateId:
string | ITemplatePrintParams- 积木报表生成的模板id - params:
object | boolean拼接到url后面的参数 为boolean 时 会当做 - isPreview:
boolean是否开启预览 - printer
undefined | string | number打印机名称 或者序号 可以通过 getPrinters 获取打印机列表
返回值
promise
templateUploadPdf 只上传 pdf
async function templateUploadPdf(templateId: string, params?: Record<string, any>): Promise参数
- templateId 积木的模版id
- params 拼接在后面的参数
getLodop 获取lodop 对象 获取后可自行调用lodop打印接口 文档参考lodop文档
用法
import {getLodop} from "@wowjoy/print"
(async () => {
let lodop = await getLodop()
// lodop.xxx()
})()getPrinters 获取所有打印接列表
用法
import {getPrinters} from "@wowjoy/print"
(async () => {
let printers = await getPrinters()
console.log('printers', 'printers')
})()loadLodop 检测是否存在lodop
用法
import {loadLodop} from "@wowjoy/print"
loadLodop().then(() => {console.log('存在')}).catch(() => {console.log('不存在')})
vscode 查看文档技巧
- 有重载的函数 mac
command + shift + spacewinctrl + shift + sapce然后上下键可以选择查看不同的重载
