Java PDF printing spool file size

Java Printing Services allows Java to provide printing in programs. JPS allows you to print some types of file directly. PDF is not a supported type so it needs to be printed by another program (like our JPedal PDF library) rendering it. From a coding point of view, this works very well – you add a print( ) method to your Swing components and just paint onto the Graphics2D object (as you would to draw onto screen). This is converted into a spool file which is then passed to the printer. From a usage point of view, it does however have some issues.

The main problem we have found is that the printing creates some very large spool files. This seems to be partly because the JPS sub-system is hard-coded to render the page to a high resolution output in 32bit RGB colour with transparency. This needs a lot of memory. In addition there is no compression on the spool file (whereas Windows programs do appear to compress the file size).

Another factor that contributes to the spool size when rendering PDFs is that embedded fonts cannot be sent to the printer – they need to be turned into Vector graphics and drawn as shapes (which uses much more memory).

A useful workaround for the second issue is to try to print using built-in Java fonts. Many PDF files use a set of Basic fonts (ie Arial, Courier, Helvetica) for which there are acceptable versions built into Java. Printing with these reduces the size of the spool file.

In JPedal we added a mode to support this which is detailled at http://www.jpedal.org/support_tutPrint.php

Unfortunately JPS remains one of the weaker areas of Java and I hope Oracle will look to improve it when they takeover.

This post is part of our “Printing Articles Index” in these articles, we aim to help you understand printing in Java and PDF’s.

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>