print change page margins?
843807Aug 21 2005 — edited Jun 19 2007Hi,
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);
}
}