Meaningless Drivel is fun!*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "printing on A4 paper" Watch "printing on A4 paper" New topic
Author

printing on A4 paper

Ken Sobieralski
Greenhorn

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
Greenhorn

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.
Parameters:
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();
p.setImageableArea(x,y,width,height);
pageFormat.setPaper(p);
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.
 
 
subject: printing on A4 paper