Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes printing on A4 paper Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "printing on A4 paper" Watch "printing on A4 paper" New topic

printing on A4 paper

Ken Sobieralski

Joined: Feb 07, 2001
Posts: 4
The paper object creates a letter sized piece of paper with one inch margins. Is there any way to set different margins to allow
a page designed to fit on letter to also print on A4 by reducing the margins? Or any other ideas?
Ravi Kumarasinghe

Joined: Jun 07, 2001
Posts: 6
There is a method called setImageableArea (shown below)
public void setImageableArea(double x,
double y,
double width,
double height)
Sets the imageable area of this Paper.
x, y - the coordinates to which to set the upper-left corner of the imageable area of this Paper
width - the value to which to set the width of the imageable area of this Paper
height - the value to which to set the height of the imageable area of this Paper
By changing x,y,width and height i was able to reduce the margine size.
eg. in print() method
Paper p=pageFormat.getPaper();
Mark Newton
Ranch Hand

Joined: Jan 31, 2006
Posts: 129
Sorry - I realise that this is an old topic, but I found it when searching for the same problem, and just thought I'd add one small point that I found.

The values you get back for imageable area are in 1/72nds (1/72ths?) of an inch, but the values displayed in the Page Setup dialogue are (I assume) based on your regional settings and/or OS (for me, UK, Windows XP - I see millimetres). Fairly obvoius from looking at the API, but caused me a minor headache, so I thought I'd mention it.

Also, perhaps I'm being thick, but I was surprised that I had to get the Paper object seperately and use the pageFormat.setPaper(p) line. I expected to be able to just use pageFormat.getPaper().setImageableArea(...), but that didn't work.
I agree. Here's the link:
subject: printing on A4 paper
It's not a secret anymore!