After trying several methods and packages, I was able to achieve success by:
- sharing the printer
- using node-cmd to send a copy of the file to the shared printer.
Note, I have only used and tested on Windows.
yarn add node-cmd
Example
const fs = window.require('fs')
const path = window.require('path')
const cmd = window.require('node-cmd')
//Save the raw output to the filesystem
const filePath = path.join(__dirname, 'rawprint.prn') //or wherever you want to save it
//Create a command to copy the file to the shared printer path (e.g. \\localhost\DPD ). Make sure that var is sanitised first!
const command = `COPY /B "${filePath}" "${pathToSharedPrinter}"`
cmd.get( command, (err, data, stderr) => {
if ( !err ) {
console.log('Success!')
} else {
console.log( err.message )
}
})