Page resolution (DPI) in Java 1.4 printing

I

Ixtlan

I got a problem with how to set the DPI of my printout to more than 72 DPI
(I'm using JDK 1.4.2)

I has somehow managed to learn that one should use java.awt.PageAttributes,
bug the Java documentation tersely states that :

"A set of attributes which control the output of a printed page.
............"

Great! So that's how it's done!

My problem is that I want to print a jpeg file that looks good in resolution
300 DPI, but looks crappy in 72 DPI (scaled in Photoshop).

So how to set the resolution to other than 72 DPI?

Any comments/links greatly appreciated!

RCS
 
R

Robert Olofsson

Ixtlan ([email protected]) wrote:
: I got a problem with how to set the DPI of my printout to more than 72 DPI
: (I'm using JDK 1.4.2)

: I has somehow managed to learn that one should use java.awt.PageAttributes,
: bug the Java documentation tersely states that :
: ....
: So how to set the resolution to other than 72 DPI?

I have no problems printing in higher than 72 dpi. I used to have
that problem when I tried to print swing components that were double
buffered, have you tried turning that off?

componentToBePrinted.setDoubleBuffered (false);

/robo
 
I

Ixtlan

My problem is not that the printing does not work, it is that the jpeg image
(that I load from disk) does not look good in 72 DPI (nothing to do with
Java here, it does not look good in Photoshop or other viewers).

My real problem is: how to set the DPI higher than the default 72 in the
Java printing API?

RCS
 
S

Steven Green

I am not sure if it will work or not since I have not tested it, but you
might try setting a print attribute PrinterResolution.

Just lookup the PrinterResolution class to find it.

--Steve
 
R

RCS

I checked the PrinterResolution (throug Eclipse's look-up mechanism, no
hint of this class in the Java documentation), and found that the
resolution attribute is read only, no setResolution, only getResolution.

Thanks for answering, though!

RCS
 
S

Steven Green

The constructor for PrinterResolution takes the resolution.
You simply create a new PrinterResolution and add it to the attribute set
passed to the PrintJob print method. For example:
aset.add(new PrintResolution(600,600,PrintResolution.DPI)

I tested this with my output files, but found no effect on the postscript
file that was generated. Not sure if the effect is different if it is not
writing to a file.

--Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top