Printing problem on Mountain Lion with java7

Timo Tommila timo.tommila at
Sun Feb 10 06:04:29 PST 2013


Printing on Mountain Lion with java7 is not working correctly!

If I try to change font family, font size or to use bold effect etc, 
I always get the same 'unknown' font, the font  size is fixed and the bold effect is not applied.

The code works correctly on XP with java7 on the same MacBook Pro (with help of VMWare) and
of course the code works also on windows PC.

Is this a known bug?

I am using following setup:

java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

MacOSX 10.8.2


ps. You will find the test code below:


package printingtest;

import java.awt.*;
import java.awt.print.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;

public class PrintingTest implements Printable {

    public PrintingTest() {

        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        aset.add(new JobName("Test printing job", null));
        PrinterJob pj = PrinterJob.getPrinterJob();
        PrintService[] services = PrinterJob.lookupPrintServices();

        if (services.length > 0) {
            try {
                if (pj.printDialog(aset)) pj.print(aset);

            } catch (PrinterException pe) {}
    Font titleFont = new Font("Times", Font.BOLD, 24);
    Font textFont = new Font("monospaced", Font.PLAIN, 12);
    Font signatureFont = new Font("Serif", Font.PLAIN, 7);

    public int print(Graphics g, PageFormat pf, int pageIndex) {
        if (pageIndex == 0) {
            Graphics2D g2d = (Graphics2D) g;
            g2d.translate(pf.getImageableX(), pf.getImageableY());
            g2d.setFont(titleFont);     g2d.drawString("Title string in Times(24,bold)", 150, 260);
            g2d.setFont(textFont);      g2d.drawString("Text string in monospaced(12)", 150, 280);
            g2d.setFont(signatureFont); g2d.drawString("Signature string in Serif(7)", 150, 300);

            return Printable.PAGE_EXISTS;
        } else  return Printable.NO_SUCH_PAGE;

    public static void main(String arg[]) {
        PrintingTest sp = new PrintingTest();

More information about the macosx-port-dev mailing list