Recently we have had a request to allow auto rotation of printed pdf pages without centering them within the print pages imageable area. This was an easy enough task to achieve but has made some changes I thought it wise to write about so as to give a little more detail.
The first and most important change to mention is the removal of a public variable. The variable isAutoRotateAndCenter within SwingPrinter has been completely removed. This variable was a flag that allowed the page to be both rotated and centered, as we are split this functionality we now need two flags, one for each.
In place of isAutoRotateAndCenter we now have two flags which can be controlled using SwingPrinter.setAutoRotate(boolean) and SwingPrinter.setCenterOnScaling(boolean).
On top of this I have also added a new method to the PdfDecoder so we have a complete set of methods in this class to alter the rotation and centering of the printer page.
PdfDecoder.setPrintAutoRotate(boolean) sets a flag to control if the page should auto rotate to best fit the printed page imageable area.
PdfDecoder.setCenterOnScaling(boolean) sets a flag to control if center the page within the printed page imageable area.
PdfDecoder.setPrintAutoRotateAndCenter(boolean) sets the flags to control if the page should auto rotate to best fit the printed page imageable area and center it within the imageable area.
That’s it, there aren’t many changes in this one but as it has resulted in the removal of a public variable we thought it would be best to post something.
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 write or read JPEG in Java?
We have an easy guide on how to write JPEG in Java using ImageIO and JDeli.
You can learn how to read/write most of the image files in ImageIO. However, it gives little control over the process.
JDeli is easy to use and offers complete support, so why don't you give a try?