我正在打印机上打印PNG图像。图像打印在页面的中心,并且不会填满整个页面。我试图增加图像的大小,但它总是在页面的中心。任何想法如何使其适合页面?打印图像时适合页面
psStream = new URL(url).openStream();
if (psStream == null) {
return "Unable to fetch image";
}
DocFlavor flavor = DocFlavor.INPUT_STREAM.PNG;
Doc myDoc = new SimpleDoc(psStream, flavor, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintServiceAttributeSet attributes = new HashPrintServiceAttributeSet();
attributes.add(new PrinterName(printData.printer, Locale.getDefault()));
final PrintService[] printServices = PrintServiceLookup.lookupPrintServices(flavor, attributes);
if (printServices.length == 0) {
return "Could not find printer " + printData.printer;
} else {
myPrinter = printServices[0];
DocPrintJob job = myPrinter.createPrintJob();
try {
job.print(myDoc, aset);
return null;
} catch (Exception e) {
e.printStackTrace();
return "Could not print : " + e.getMessage();
}
}
重复http://stackoverflow.com/questions/27029166/java-printerjob-not-printing-to-fit-paper – SomeDude