allora, nel frattempo ho fatto svariati tentativi.
l'unico che mi ha funzionato è questo:
anche se come dici giustamente te sto paragonando patate e carote.codice:public class PrintImage implements Printable { private BufferedImage[] images; private PrinterJob printJob; public PrintImage(PrinterJob printJob, BufferedImage[] images) { this.images = images; this.printJob = printJob; } @Override public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex < images.length) { pageFormat = printJob.defaultPage(); double x = pageFormat.getImageableX(); double y = pageFormat.getImageableY(); double width = pageFormat.getImageableWidth(); int pWidth = 0; int pHeight = 0; if (pageFormat.getOrientation() == PageFormat.PORTRAIT) { pWidth = (int) Math.min(width, (double) images[pageIndex].getWidth()); pHeight = pWidth * images[pageIndex].getHeight() / images[pageIndex].getWidth(); } else { pHeight = (int) Math.min(width, (double) images[pageIndex].getHeight()); pWidth = pHeight * images[pageIndex].getWidth() / images[pageIndex].getHeight(); } graphics.drawImage(images[pageIndex], (int) x, (int) y, pWidth, pHeight, null); return PAGE_EXISTS; } else { return NO_SUCH_PAGE; } } }

Rispondi quotando