Hello,
I want to display the page settings dialog like that :
Page dialog snapshot
The values I want to display are :
size : A4
orientation : landscape
margins : left=15, right=15, top=15, bottom=15 (millimeters)
I use a HashPrintRequestAttributeSet instance to pass parameters to the 'getPageFormat' of 'PrinterJob', then I pass the calculated format to the pageDialog function, but the values displayed in the dialog are not correct, particulary the margins.
Could you correct the code below, to get exactly 15mm for each margin in the dialog ?
Thank you.
Chris
What I have tried:
public void actionPerformed(ActionEvent arg0) {
try {
PrinterJob pj = PrinterJob.getPrinterJob() ;
HashPrintRequestAttributeSet printRequestSet = initializePrintingAttributes() ;
PageFormat pf = pj.getPageFormat(printRequestSet) ;
pj.pageDialog(pf) ;
} catch (Throwable e) {
e.printStackTrace();
}
}
private HashPrintRequestAttributeSet initializePrintingAttributes() {
HashPrintRequestAttributeSet printRequestSet = new HashPrintRequestAttributeSet() ;
printRequestSet.add(OrientationRequested.LANDSCAPE) ;
float width = MediaSize.ISO.A4.getX(MediaPrintableArea.MM) ;
float height = MediaSize.ISO.A4.getY(MediaPrintableArea.MM) ;
printRequestSet.add(new MediaPrintableArea(15f, 15f, (float)width-15*2, (float)height-15*2, MediaPrintableArea.MM)) ;
printRequestSet.add(MediaSizeName.ISO_A4) ;
return printRequestSet ;
}