我试图使用标签打印机(EPSON TM-T88V是特定的)来吐出PNG图像。Java使用标签打印机打印到特定页面尺寸
我可以把它打印得很好,除非当我打印图像尺寸时(220x175在72dpi时再次具体),打印图像的顶部有一叠白色空间,我认为这是浪费纸。
关于如何最大限度地减少纸张浪费的任何想法?我希望它只打印图像,最小的空白,然后剪切纸张。
这里是我的代码
AttributeSet aset = new HashAttributeSet();
aset.add(new PrinterName(printerName, null));
/* locate a print service that can handle the request */
PrintService[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.PNG, aset);
if (services.length >= 1) {
/* create a print job for the chosen service */
DocPrintJob pj = services[0].createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
das.add(PrintQuality.HIGH);
das.add(MediaSizeName.ISO_A7); // I know the problem is here somewhere. This Media size seems to work best currently
try {
/*
* Create a Doc object to hold the print data.
*/
Doc doc = new SimpleDoc(imageByteIs, DocFlavor.INPUT_STREAM.PNG, das);
/* print the doc as specified */
pj.print(doc, null);
} catch (PrintException e) {
System.err.println(e);
}
}
感谢您的贡献乔普,但现在我得到一个'java.lang.IllegalArgumentException异常:在javax.print.attribute.standard.MediaPrintableArea中0或负值的说法 \t。(MediaPrintableArea.java:143)' 看来我不能初始化一个MediaPrintableArea与0的 –
alwinc
而如果0.05? –
不...只是在页面的左上角打印小字。我不认为这是MediaPrintableArea的用途。我相信课堂只是说这个媒体的哪个领域是可以印刷的。 IE,如果只有上半部分用于打印等等。所以全屏的0.05会在左上角留下一个小点。乔普......我想你可能离答案很远 – alwinc