Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Printer = class Printer {
- constructor () {
- this._excelvan = require('node-excelvan')
- this._printer = new this._excelvan.Printer()
- this._printer.connect()
- this._printJob = new this._excelvan.PrintJob()
- this._pdf2png = require('pdf2png')
- this.endJob = this.endJob.bind(this)
- }
- print1 () {
- this._printJob.printImage('./tmp/cap.png', {dither: false}, (err, res) => {
- this._printer.print(res._queue)
- })
- }
- print (dataBuffer) {
- this._pdf2png.convert('./tmp/lorem.pdf', (res) => {
- if (res.error) {
- console.error(res.error)
- } else {
- this._printJob.printImage(res.data, {dither: false}, (err, res) => {
- if (err) {
- console.error(err)
- } else {
- this._printer.print(res._queue)
- }
- })
- }
- })
- }
- endJob () {
- this._printJob = new this._excelvan.PrintJob()
- const pj = new this._excelvan.PrintJob()
- pj.pad(5).cut()
- this._printer.disconnect(() =>
- setTimeout(() =>
- this._printer.connect(() =>
- this._printer.print(pj)
- )
- ), 5
- )
- }
- }
- module.exports = new Printer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement