当我尝试在当前的大学项目中为特定标签打印机打印某些内容时,出现此错误:
java.awt.print.PrinterException: Paper's imageable width is too small.
at sun.print.RasterPrinterJob.printPage(Unknown Source)
at sun.print.RasterPrinterJob.print(Unknown Source)
at sun.print.RasterPrinterJob.print(Unknown Source)
at Printer.print(Printer.java:91)
at Printer.<init>(Printer.java:43)
at VisitorDBTest.main(VisitorDBTest.java:10)
但我看不出原因。我有该特定打印机的确切标签代码,标签宽度和高度正确。我将可成像尺寸设置为精确的标签尺寸(以 1/72 英寸为单位),然后尝试将其设置得更小,但没有成功。 当我在 A4 页面上使用普通喷墨打印机打印时,此代码工作正常。仅当我尝试打印到 DYMO 450 标签打印机(使用不同的 Paper 和 PageFormat 对象)时,才会出现错误。 看看谷歌的结果,我似乎是历史上唯一遇到此错误的人。
编辑:将可成像宽度打印到屏幕后,我得到以下结果:
Paper imageable width is 196.0
PageFormat imageable width is 151.0
PrinterJob imageable width is -65.0267716535433
据我所知,PageFormat 从纸张中获取其可成像宽度,而 PrinterJob 从 PageFormat 中获取其可成像宽度。 我显然在这里遗漏了一些东西。
最佳答案
我解决了添加
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.PORTRAIT);
aset.add(MediaSizeName.INVOICE);
job.print( aset);
关于java - "PrinterException: Paper' s 可成像宽度太小 "I can see what' s 错误,但我该如何修复它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10601620/