Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

print change page margins?

843807Aug 21 2005 — edited Jun 19 2007
Hi,

I am using the following code to setup printer output. The code does not consider my page settings
but the printJob.printDialog always proposes 1 inch margins. Is this an error in the API?

Thanks
golpe

call using: PrintUtilities.printComponent(this);

public class PrintUtilities implements Printable {
private Component componentToBePrinted;
Paper myPaper = null;
PageFormat myPageFormat = null;

public static void printComponent(Component c) {
new PrintUtilities(c).print();
}

public PrintUtilities(Component componentToBePrinted) {
this.componentToBePrinted = componentToBePrinted;
}

public void print() {
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.PORTRAIT);
aset.add(new Copies(1));
aset.add(new JobName("Delivery Sheet", null));
aset.add(MediaSizeName.ISO_A4);
aset.add(Chromaticity.MONOCHROME);
PrinterJob printJob = PrinterJob.getPrinterJob();

try {
printJob.setPrintService(services[1]);
myPaper = new Paper();
myPaper.setImageableArea(54, 36, 505, 751);
myPageFormat = new PageFormat();
myPageFormat.setPaper(myPaper);
printJob.setPrintable(this, myPageFormat);
if (printJob.printDialog(aset)) printJob.print(aset);
} catch(PrinterException pe) {
System.out.println("Error printing: " + pe);
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 17 2007
Added on Aug 21 2005
9 comments
1,126 views