0

When I print images it seems like zoomed in the result page. But there is normal scaling when we'll try to save image to file.

How can I print images in original scale?

There is a sample code:

@Override
public int print(Graphics graphics, PageFormat pageFormat, int page) throws PrinterException {
    if(page < sequence.size()) {
        BufferedImage image = sequence.get(page).getImage();
        String filename = ((Integer)page).toString()+".png";
        File outputFile = new File(filename);

        try {
            ImageIO.write(image, "png", outputFile);
        } catch (IOException e) {
            e.printStackTrace();
        }

        graphics.drawImage(image, (int)pageFormat.getImageableX(), (int)pageFormat.getImageableY(), null);
        return PAGE_EXISTS;
    } else {
        return NO_SUCH_PAGE;
    }
}
Atorich
  • 1
  • 1
  • This can be a rather complex subject, but generally speaking, printers print at a much higher resolution (DPI) then is rendered to the screen (and some files). Take a look at [this example](http://stackoverflow.com/questions/12173515/fit-image-into-the-printing-area/12174371#12174371), [this example](http://stackoverflow.com/questions/22241711/setting-print-size-of-a-jlabel-and-put-a-jradiobutton-on-the-print/22244116#22244116), [this example](http://stackoverflow.com/questions/18975595/how-to-design-an-image-in-java-to-be-printed-on-a-300-dpi-printer/18975822#18975822) – MadProgrammer Apr 12 '14 at 09:13
  • [this example](http://stackoverflow.com/questions/18460008/printable-prints-bufferedimage-with-incorrect-size/18466550#18466550) and [this example](http://stackoverflow.com/questions/17904518/fit-scale-jcomponent-to-page-being-printed/17961911#17961911) for some ideas. Some may discuss concepts not directly related to your problem, but they will provide additional information and concepts that might be helpful – MadProgrammer Apr 12 '14 at 09:15
  • Also, understand, `print` may be called multiple times for a given page, all the file I/O is going to slow things down. Load the file for the given page until the page number changes ;) – MadProgrammer Apr 12 '14 at 09:16
  • Writing image to file is just for test purposes but thanks anyway :) – Atorich Apr 12 '14 at 09:20

0 Answers0