Printing on the Mac OS with Java 7 has been broken for a long time, months in fact. I don’t understand how this can possibly happen. After all printing isn’t exactly a small issue, and the Mac isn’t exactly a small market. So how can this be? For months? I don’t get it…
Specifically the font attributes are not honored on the Mac OS. Java seems to make the proper OS calls but for whatever reason the Mac OS just ignores those calls. Here’s the official bug report. To quote:
“Call to MacOS native function CTTypesetterCreateWithAttributedStringAndOptions did not produce the expected result. Although the font dictionary was passed in options, for unknown reason, it is ignored. Fix is to add the font dictionary in the attributed string and use CTTypesetterCreateWithAttributedString.”
And this only affects the Mac, it works fine in Windows or with Linux. The following code shows how to replicate the Java 7 printing bug on the Mac OS:
Font font = new Font("Times", Font.BOLD, 24);
Graphics2D g = (Graphics2D)graphics;
g.drawString("Hello World", 10, 10);
// Increase font by 10 - Mac OS ignores this next line of code.
g.drawString("Hello World in a bigger font", 10, 100);
The weirdest part of this whole issue is that it’s really only broken in Java 7!! Of course it’s the only stable release of Java. How does that make any sense? It still works on Java 6 which is no longer supported (past it’s End of Life). For Java 8, which is still in beta and does NOT have a stable release, it seems to be working. However for Java 7, nope. Nothing. Nada. Huh???
In case you want to read further information from the better links I found on the issue, they are here, here, here, here, here, here, here, here, here, here, and here. Just a few links. So it’s not exactly an unknown issue. Many people are struggling with it.
That being said, several people have found workaround solutions, including us here at LandlordMax Property Management Software. A common solution I’ve heard is to create an image of what you want to print and print that image. It makes sense and it will work because you’re bypassing the font attributes. I’m not a big fan of this solution, especially since it doesn’t really scale well to multi-page report printouts that we need in LandlordMax.
So what we’ve been forced to do is create a temporary PDF file of the report, ask the Mac OS to print the file using the system command
lp filename.pdf, and then delete the temporary file. This works pretty well, the only downside is that the Page Setup and printer setting options that comes along with most programs are not available because we’re not really printing from the software itself, nor can we pass them on to the system command. It’s not ideal, but it’s the only way to print within Java 7 on the Mac OS.
We added this workaround in the software with Java 7 Update 17. Unfortunately s far as we can tell the bug has been around at least since Update 9, but probably earlier. I just checked and we’re now at Java 7 Update 25, and guess what. Still no fix! No mention of the issue either.
The big question now is whether this is a Java (Oracle) issue or a Mac (Apple) issue? In either case, I would think both companies should want to fix this issue right away. It’s not exactly a minor issue. I don’t understand what’s holding up a resolution to this issue. It makes absolutely no sense to me. This is core functionality that affects both their users in a big way. It’s not a little bug, it’s huge! Printing is important, even in today’s digital world.
Hopefully Apple and Oracle can put their differences aside for a little bit and resolve this issue. It’s affecting a lot of people and we don’t deserve to be the collateral damage to their war against each other.