Java printing - Enlarged printouts on a small number of printers

465 views Asked by At

On some printers, for whatever reason, the printouts are automatically enlarged with what seems to be default settings when printing through the Java JVM (Java 7). This seems to be with older printers, and it's pretty rare, but it is happening with more than one printer model. Also upgrading the drivers doesn't resolve the issue.

The software uses the JFreeReport (classic engine) library, and when using the library to export as a PDF, everything is great. As well the Print Preview using the library is perfect. However when it comes to printing, and this is only with a very very small number of printers, the printouts are enlarged. They aren't zoomed in, but the fonts are much much bigger and improperly spaced so that they overlap over each others.

These same printers with JDK 6 seem to work fine. Seem, I'm still trying to isolate the issue. My thinking is that possibly these printers do not correctly support Java 7

Update: I found this thread which seems to indicate that there are some issues with JDK 7u21. I didn't see anything in the release notes to address this. In addition here is another example of the a similar bug report.

Update2: For anyone interested, I wrote a blog post called Printing is Broken on Mac OS X with Java 7 about this issue which contains more details and what I discovered.

3

There are 3 answers

0
Stephane Grenier On BEST ANSWER

Apparently there is no solution. The issue is that the font attributes set by the JVM are ignored by the Mac OS as reported in this bug report and this bug report.

The only workaround is to create a temporary file and then print it by using:

try
{
    Process process = Runtime.getRuntime().exec(new String[]{"lp", tempFileFullPath});
    process.waitFor();
} catch (Exception e) {
    // error handling
}

Of course this can be fired off in a thread or through SwingUtils depending if you have a GUI application, but it's the only way possible at this time.

0
MrB On

This is a known bug sadly. While there are a few workarounds (the symmetrical print resolution mentioned in your links, converting to a bufferedimage then printing that) I'm not aware of any fix as yet.

0
user456837 On

This is a known bug - if you don't want to use the PDF-print workaround, you can check out this answer:

https://stackoverflow.com/a/17345102/456837