I'm using the Java Printing API, but have problems setting print margins.
...
Solution
I had to provide additional print attributes to override the default
print margins,
MediaPrintableArea.
Most printers cannot print on the entire surface of the media, due to
printer hardware limitations.
MediaPrintableArea
can be used to query the acceptable values for a supposed print job,
and to request an area within the constraints of the printable area to
be used in a print job.
HashPrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
attr.add(new MediaPrintableArea(0f, 0f, w/72f, h/72f, MediaPrintableArea.INCH));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(ps);
job.setPrintable(this);
job.setJobName(jobName);
job.print(attr);
j.setVisible(false);
j.dispose();
The key was to provide the attributes along with the print()
command.
Source Help with print margins