Discussions
Categories
- 196.7K All Categories
- 2.2K Data
- 235 Big Data Appliance
- 1.9K Data Science
- 449.8K Databases
- 221.5K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 549 MySQL Community Space
- 477 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 532 SQLcl
- 4K SQL Developer Data Modeler
- 186.8K SQL & PL/SQL
- 21.3K SQL Developer
- 295.4K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.1K Development Tools
- 104 DevOps
- 3.1K QA/Testing
- 645.9K Java
- 27 Java Learning Subscription
- 37K Database Connectivity
- 153 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 17 Java Essentials
- 158 Java 8 Questions
- 85.9K Java Programming
- 79 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.2K Java SE
- 13.8K Java Security
- 203 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 393 LiveLabs
- 37 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.6K Other Languages
- 2.3K Chinese
- 170 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 230 Portuguese
Mac OS X - Printing - PrinterGraphicsConfig.getDefaultTransform() throws a NullPointerException

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) */ @Override 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:
java.lang.NullPointerException
at java.awt.geom.AffineTransform.<init>(AffineTransform.java:488)
at sun.print.PrinterGraphicsConfig.getDefaultTransform(PrinterGraphicsConfig.java:101)
at com.intergraph.web.plugin.printing.PrintableDocument.print(PrintableDocument.java:122)
at sun.lwawt.macosx.CPrinterJob$6.run(CPrinterJob.java:697)
at sun.lwawt.macosx.CPrinterJob.printAndGetPageFormatArea(CPrinterJob.java:707)
at sun.lwawt.macosx.CPrinterJob.printLoop(Native Method)
at sun.lwawt.macosx.CPrinterJob.print(CPrinterJob.java:299)
at com.intergraph.web.plugin.printing.PrintEngine.print(PrintEngine.java:177)
at com.intergraph.web.plugin.printing.controller.PrintDocumentJob.run(PrintDocumentJob.java:41)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
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,
Steve
Answers
-
I tested it with the following printer
Konica Minolta bizhub C353
-
Any suggestions?