プリンタに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