Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. const Printer = class Printer {
  2. constructor () {
  3. this._excelvan = require('node-excelvan')
  4. this._printer = new this._excelvan.Printer()
  5. this._printer.connect()
  6. this._printJob = new this._excelvan.PrintJob()
  7. this._pdf2png = require('pdf2png')
  8.  
  9. this.endJob = this.endJob.bind(this)
  10. }
  11.  
  12. print1 () {
  13. this._printJob.printImage('./tmp/cap.png', {dither: false}, (err, res) => {
  14. this._printer.print(res._queue)
  15. })
  16. }
  17.  
  18. print (dataBuffer) {
  19. this._pdf2png.convert('./tmp/lorem.pdf', (res) => {
  20. if (res.error) {
  21. console.error(res.error)
  22. } else {
  23. this._printJob.printImage(res.data, {dither: false}, (err, res) => {
  24. if (err) {
  25. console.error(err)
  26. } else {
  27. this._printer.print(res._queue)
  28. }
  29. })
  30. }
  31. })
  32. }
  33.  
  34. endJob () {
  35. this._printJob = new this._excelvan.PrintJob()
  36. const pj = new this._excelvan.PrintJob()
  37. pj.pad(5).cut()
  38. this._printer.disconnect(() =>
  39. setTimeout(() =>
  40. this._printer.connect(() =>
  41. this._printer.print(pj)
  42. )
  43. ), 5
  44. )
  45. }
  46. }
  47.  
  48. module.exports = new Printer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement