Itsik Mauyhas Itsik Mauyhas - 2 months ago 17
Javascript Question

JS - print a String using window.print()

Can I use

window.print()
to print a
String
, I know it print the current page content. my final goal is to print to
pdf
, I had tried to use
jsPDF
lib, but it does not support
UTF-8
, so how can I print a
String
to pdf with this method?

Answer

If you need to print just a string, best way is probably to create a temporary window, print it and then close it:

var win = window.open()
win.document.write('Some string')
win.print()
win.close()
Comments