简体   繁体   English

JS-使用window.print()打印一个字符串

[英]JS - print a String using window.print()

Can I use window.print() to print a String , I know it print the current page content. 我可以使用window.print()打印一个String ,我知道它可以打印当前页面的内容。 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? 我的最终目标是打印到pdf ,我曾尝试使用jsPDF lib,但它不支持UTF-8 ,那么如何使用此方法将String打印到pdf?

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM