My program prints A6 size pages, however, I often use larger paper. In that situation, I would like to print a border around the A6 virtual page to help me trim the paper. But I want a solution that works if I ever use actual A6 paper.
I am running on macOS.
I configure the pageDialog() with the desired page size (3.75 x 6.75 inches) and a full size imageable area. The validated returned PageFormat matches that size and imageable area.
However, when my Printable is called, the PageFormat is different: the paper size is 3.875 x 7.5 inches, the imagable area is 3.375 x 6.55 inches, with a left margin of .25 inch and a top margin of .2 inch. I can understand the top margin, because the actual printing on 8.5 x 11 inch paper is at the top of the paper. The left margin is not obvious, because the actual printing is centered horizontally. (The printer apparently knows the paper width, but perhaps the software does not know what the printer will do?)
I draw the border:
double paperWidth = 3.75 * 72;
double paperHeight = 6.75 * 72;
g.draw(new Rectangle2D.Double(2, 2, paperWidth - 2, paperHeight - 2));
(The 2 is a fudge factor.)
All I get is a thin line at the bottom, but nothing at the sides. (I don't care about the top.) That makes sense if the imageable area is causing clipping.
I have tried altering the imageable area and clip region, but nothing changes.
pageFormat.getPaper().setImageableArea(0, 0, paperWidth, paperHeight);
g = (Graphics2D) g.create();
g.setClip(0, 0, (int) paperWidth, (int) paperHeight);
g.draw(new Rectangle2D.Double(2, 2, paperWidth - 2, paperHeight - 2));
g.dispose();