How to find out minimum margins for a printer?

Using J2SE 1.4 on Windows XP.

I want to find out the minimum margins for a printer. If I do this:

PrintService ps = ...;

PrinterJob job = PrinterJob.getPrinterJob ();

job.setPrintService (ps);

PageFormat pf = job.defaultPage ();

...then pf.getImageableX() and pf.getImageableY() return 72.0 for every printer I've tried!

On Windows, what I want is GetDeviceCaps (hDC, PHYSICALOFFSETX)

Can I get this data in Java?

Thanks

- rick

[496 byte] By [rbc_cda] at [2007-9-19]
# 1

Just for reference, I believe I've found out how to do this. Not very intuitive, and I hope Sun will consider improving this next time 'round!

To determine the minimum margins on a printer, create a PrinterJob & set it to refer to the PrintService for the printer. Then execute some code like this:

PageFormat pf = job.defaultPage();

Paper paper = pf.getPaper();

paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight());

pf = job.validatePage(pf);

The Paper in the PageFormat now represents the maximum imageable area on the printer.

Even if Sun fixes defaultPage so that it returns a PageFormat in this state, this code will still work.

Cheers

- rick

rbc_cda at 2007-7-8 > top of java,Security,Cryptography...
# 2
A small correction:After setting the imageable area of the paper, it's necessary to call pf.setPaper (paper).- rick
rbc_cda at 2007-7-8 > top of java,Security,Cryptography...