Is there any way to programmatically change the PageFormat or other
properties in java?
Thanks
Andrew
Andrew Chau wrote:
You can create a PageFormat with a Paper, for instance, and call
the PrinterJob.validatePage(PageFormat) method, which returns a
PageFormat; and you can set your margins then accordingly. E.g.
I use this in one of my programs:
PrinterJob pjob = PrinterJob.getPrinterJob();
PageFormat pform = getPageFormat(pjob);
....
private PageFormat getPageFormat(PrinterJob pjob) {
PageFormat pform = pjob.defaultPage();
customizePaper(pform);
/* some information */
PrintInfo.out(" after setting paper ", pform);
return pjob.validatePage(pform);
}
private void customizePaper(PageFormat pform) {
Paper paper = pform.getPaper();
paper.setImageableArea(0, 5, paper.getWidth(),
paper.getHeight() - 2 * 5);
pform.setPaper(paper);
}
public int print(....){.....}
Just to give you an idea, this can be differently of course,
and not all printers support this well, for instance I get a
bit different result on different printers,a description can
be found in the FAQ, too:
http://java.sun.com/products/java-media/2D/forDevelopers/java2dfaq.html#margin
Linda
--
\ / To where the water and the earth caress and the down of a
- * - peach says mmh, yes,do I look for those millionaires like
/ \ a Machiavellian girl would when I could wear a sunset?
Kate Bush, The Sensual World