tojocky / node-printer

Native node.js printer
1.54k stars 443 forks source link

Print image using DataURL #189

Open aabanaag opened 7 years ago

aabanaag commented 7 years ago

Hi, I have a question if printing an image using dataURL will be possible? Also any updates on sending the print via buffer? It is possible to utilize async/await from ES6?

ChimingPhang commented 6 years ago

@aabanaag this works for me in electron

let imageData = canvas.toDataURL('image/jpeg')
let base64Data = imageData.replace(/^data:image\/\w+;base64,/, '')
let dataBuffer = Buffer.from(base64Data, 'base64')

printer.printDirect({
      data: buffer,
      type: 'JPEG',
      printer: this.printer, 
      success: function (jobID) {
        console.log('sent to printer with ID: ' + jobID)
      },
      error: function (err) {
        console.log(err)
      }
})
prasheel888 commented 2 years ago

its says Error: StartDocPrinterW error: code: 1804, message: The specified datatype is invalid. Had a same issues...

prasheel888 commented 2 years ago

Hi, I have a question if printing an image using dataURL will be possible? Also any updates on sending the print via buffer? It is possible to utilize async/await from ES6?

Bro How did you managed to get this functionality? I'm having a same issue