Question

Using java swing, I want to print with accurate physical dimensions irrespective to user's printer and its resolution

e.g: i want to print exactly 5cm x 3cm rectangle on paper.

I don't know how to find the current dpi for selected printer (consider even select printer might have multiple configuration for dpi which user might change from print dialog box while printing).

Was it helpful?

Solution

Java's printing API pretty much "assumes" 72dpi, even though it can print to printers with a much higher resolution then this.

This makes things much easier, as you simply don't need to care.

Essentially, you can convert cm to pixels by converting to dpi...

double cms = 5;
pixels = (cms * 0.393700787d) * 72
// 0.393700787d is the number of cms per inch ;)

Take a look at How to design an image in java to be printed on a 300 dpi printer for further details

OTHER TIPS

Printer understands length/paper size in points only using java API. 1 inch contains 72 points on paper. Hence you need to refer (inch * 72)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top