Why does my thermal printer wastes half a meter of paper for each image?
I am trying to print an image to a thermal printer (Bixolon srp350 plus), using the Java jdk 1.6 PrintService API.
Although I am able to print it, the printer feeds continuously for some time and prints the image at the end. About half a meter of paper is wasted every time I try to print the image using the code below.
DocAttributeSet das = new HashDocAttributeSet();
das.add(new PrinterResolution(180,180,PrinterResolution.DPI));
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
pras.add(new PrinterResolution(180,180,PrinterResolution.DPI));
Pr开发者_开发知识库intService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.JPEG,pras);
if (pss.length == 0) {
throw new RuntimeException("No printer services available.");
}
PrintService ps = pss[0];
String imageResource = "logo.jpg";
DocPrintJob job = ps.createPrintJob();
FileInputStream fis = null;
try {
fis = new FileInputStream(imageResource);
Doc imageDoc = new SimpleDoc(fis, DocFlavor.INPUT_STREAM.JPEG, null);
job.print(imageDoc,pras);
fis.close();
} catch (Exception e1) {
e1.printStackTrace();
}
Am I doing anything wrong?
精彩评论