We get to find some intriguing bugs in Java, and today I stumbled across an interesting print issue. This exception was being thrown in Java Printing
java.lang.IllegalArgumentException: Width (3) and height (0) must be > 0
As the exception was happening deep inside the JDK and not our code it was a rather difficult issue to hunt down. We had to step through the PDF commands until we identified the one causing the issue.
It turned out that Java printing was being passed a tiny (8×1 pixels) image. This was being scaled down with an AffineTransform to produce a final image with a height less than 1. As Java cannot handle fractions of pixels, this was being truncated to zero and causing the issue. Adding some code to ignore the image removed the issue.
This post is part of our “Printing Articles Index” in these articles, we aim to help you understand printing in Java and PDF’s.
Do you need to solve any of these problems in Java?
Convert PDF to HTML5
Convert PDF to SVG
View Forms in the browser
View PDF Documents
Convert PDF to image
Extract Text from PDF
Convert Image to PDF