Tuesday, 3 October 2017

JavaScript - sending raw text to printer

While I'm working on the receipt printer, I found this nice code to send the raw text to printer. You will have more freedom and control over the print out.

function doPrint(rawText) {
  var printWindow = window.open();
  printWindow.document.open('text/plain')
  printWindow.document.write(rawText);
  printWindow.document.close();
  printWindow.focus();
  printWindow.print();
  printWindow.close();
}


Reference

https://stackoverflow.com/questions/36570689/javascript-send-raw-text-to-printer-no-server-requests-method-calls-able-to

Notes

In the receipt printer driver, goto Advanced tab and change the driver to "generic/text only". Then, the following codes will print the raw text.

We are moving

We are moving this blog to our new blog site: https://ciysys.com/blog/nodejs.htm