node-printer icon indicating copy to clipboard operation
node-printer copied to clipboard

Print image using DataURL

Open aabanaag opened this issue 8 years ago • 3 comments

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?

aabanaag avatar Sep 21 '17 05:09 aabanaag

@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)
      }
})

ChimingPhang avatar Jan 04 '18 12:01 ChimingPhang

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

prasheel888 avatar Mar 16 '22 04:03 prasheel888

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

prasheel888 avatar Apr 11 '22 11:04 prasheel888