Ich drucke ein PNG-Bild auf dem Drucker. Das Bild wird in der Mitte der Seite gedruckt und füllt nicht die ganze Seite aus. Ich habe versucht, die Größe des Bildes zu erhöhen, aber es ist immer in der Mitte der Seite. Irgendwelche Ideen, wie es zur Seite passt?An Seite anpassen, wenn ein Bild gedruckt wird
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();
}
}
Duplizieren von http://stackoverflow.com/questions/27029166/java-printerjob-not-printing-to-fit-paper – SomeDude