我想使用一个标签打印机(具体来说是EPSON TM-T88V)来打印PNG图片。我可以成功地进行打印,但当我打印一张尺寸为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: 0 or negative value argument at javax.print.attribute.standard.MediaPrintableArea.<init>(MediaPrintableArea.java:143)
的问题。看起来我无法使用0来初始化MediaPrintableArea。 - alwinc