Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (print-paper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
install
npm install print-paperusage
import { Print } from 'print-paper'
const print = new Print('A5', 'vertical', 0)
// size:A4 A5
// direction:horizontal 垂直方向,vertical 水平方向
// margin:纸张距离内容的距离,单位为mm
// 修改成你的容器
const container = document.querySelector('#app')
// 添加元素到容器中(这步操作必须在print.create()前执行)
container.appendChild(print.element)
// 通过setTemplate设置的模板将会重复出现在每一页
// 模板的位置请自行通过css设置,例如 position:absolute;bottom:0;height:40px;
print.setTemplate(`<div style="height:80px;text-align:center;">Header</div>`)
const arr = new Array(30).fill(0).map((_, i) => ({ name: `name${i}` }))
print.setData(arr)
// 通过setActiveTemplate设置单个动态模板,若纸张剩余空间不够,会自动创建新纸张并将未完成的打印数据书写在新纸张上
print.setActiveTemplate(data => {
return `<div>${data.name}</div>`
})
// 生成打印内容
print.create()
// 鼠标右键菜单,自行打印