Forum Stats

  • 3,815,470 Users
  • 2,259,033 Discussions


Mac OS X - Printing - PrinterGraphicsConfig.getDefaultTransform() throws a NullPointerException

shruda Member Posts: 16
edited Jul 22, 2014 10:18AM in Abstract Window Toolkit (AWT)

Hello guys, I currently try to get our Swing application working on Mac OS X and I found one problem which blocks me. Our application usese the java.awt.print package to generate print-outs.

One very important information for us is the printers used DPI/PPI setting. We've found a long time ago a tutorial which uses the given Graphics object of the java.awt.Printable.print(Graphics, PageFormat, int) method to get this neseccary information.

The implementation of our looks like the following:

 * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
  if (pageIndex != 0)
  return Printable.NO_SUCH_PAGE;

  Graphics2D graphics2D = (Graphics2D) graphics;

  // get the current scale
  AffineTransform defaultDeviceTransform = graphics2D.getDeviceConfiguration().getDefaultTransform();
  double deviceScaleX = defaultDeviceTransform.getScaleX();
  double deviceScaleY = defaultDeviceTransform.getScaleY();

  * this method gets an graphics from the printer which is already scaled to the desired resolution and therefore
  * the dpi can be calculated by the scale of the transformation.
  * -> no other way to determine the dpi were found

  double dpi = deviceScaleX * 72;
  System.out.println("The Printer uses the following DPI setting: " + dpi);

  myPrintingMethod(graphics2D, dpi);
  return Printable.PAGE_EXISTS;

This way to get the DPI/PPI setting of the printer works perfect if the operating system is Microsoft Windows. But in case of the Mac OS X throws the Line 13. the following NullPointerException:


at java.awt.geom.AffineTransform.<init>(

at sun.print.PrinterGraphicsConfig.getDefaultTransform(

at com.intergraph.web.plugin.printing.PrintableDocument.print(

at sun.lwawt.macosx.CPrinterJob$

at sun.lwawt.macosx.CPrinterJob.printAndGetPageFormatArea(

at sun.lwawt.macosx.CPrinterJob.printLoop(Native Method)

at sun.lwawt.macosx.CPrinterJob.print(

at com.intergraph.web.plugin.printing.PrintEngine.print(


at java.util.concurrent.ThreadPoolExecutor.runWorker(

at java.util.concurrent.ThreadPoolExecutor$


I tried to find a workaround but I wasn't sucessful and I only found the following thread from 2008 Simple Printing example that raises many questions .... the result of this thread is not the same but it describes the same problem...

Does anybody of you know a way to figure out the DPI/PPI setting of a printer?

I'm tested it with:

JDK 8u5

OS X 10.9.4

Thanks in advance!

Best Regards,




This discussion has been closed.