[英]Java - Printing to a receipt printer
I need to print a few lines to a receipt printer (Star TSP100). 我需要在收据打印机(Star TSP100)上打印几行。 I can write the text to a file and use this line to print: 我可以将文本写入文件并使用以下行进行打印:
Desktop.getDesktop().print(new File("test.txt"));
The problem is that the text size when I do this is very tiny. 问题是我执行此操作时的文本大小很小。 Since the file is plain text, I don't know how to adjust the size. 由于文件是纯文本,因此我不知道如何调整大小。
What's the easiest way to make this text readable? 使文本可读的最简单方法是什么?
Just change your TXT
file to an RTF
( Rich Text Format ) file! 只需将您的TXT
文件更改为RTF
( 富文本格式 )文件即可! java.io.File
can read a lot of different types! java.io.File
可以读取很多不同的类型!
But... if you want to have full control over what you print, draw everything to a Graphics2D
object, then print that. 但是...如果您想完全控制打印内容,请将所有内容绘制到Graphics2D
对象,然后进行打印。 There's a nice tutorial on how to do that here . 这里有一个很好的教程,介绍了如何做到这一点 。
Sending lpr commands directly to the printer results in a reasonable text size. 直接将lpr命令发送到打印机会产生合理的文本大小。 This solution works for my situation. 此解决方案适用于我的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.