Low Quality Text Printing

C

Curtis Call

Using PrintJobs and Printable instances I am running into a problem
where the printout is of a low quality. From perusing the archives it
appears to be because it is printing at a low resolution. I had a
couple questions I hoped someone could answer:

1. Is it possible to print at a higher resolution using PrintJobs or do
I need to use a more recent API?

2. If so, is there a preferred way to print text that isn't being
displayed on the screen? Most of the messages regarding printing
involve people printing JComponents, but I was under the impression that
they won't print correctly unless they are visible on the screen.
Currently I am using an ArrayList of BufferImages, one per page for my
printout. It works fine except that the text looks choppy.

Any insight would be greatly appreciated!
 
H

Harald Hein

Curtis Call said:
Using PrintJobs and Printable instances I am running into a
problem where the printout is of a low quality. From perusing the
archives it appears to be because it is printing at a low
resolution. I had a couple questions I hoped someone could
answer:

1. Is it possible to print at a higher resolution using PrintJobs
or do I need to use a more recent API?

I would at least use the PrinterJob API, not the PrintJob API. What
values do the getResolution methods of PrintJob return?
2. If so, is there a preferred way to print text that isn't being
displayed on the screen? Most of the messages regarding printing
involve people printing JComponents, but I was under the
impression that they won't print correctly unless they are visible
on the screen.

They are not needed for printing, but lightweight components should
print correctly without beeing displayed.
Currently I am using an ArrayList of BufferImages,
one per page for my printout. It works fine except that the text
looks choppy.

Without knowing the details of your code, you should consider using the
PrinterJobs API, larger BufferedImages, and an AffineTransform to map
these larger images to your page size when printing.

Alternatively, using the PrinterJobs API you might also not need the
ArrayList at all, since the framework calls your print method with a
page number and a Graphics to draw onto. Depending on your application,
you could generate all the pages on the fly.

You could also have a look at the rendering hints and turn text
antialising on.
 
C

Curtis Call

Harald said:
I would at least use the PrinterJob API, not the PrintJob API. What
values do the getResolution methods of PrintJob return?

I mispoke, I am already using the PrinterJob API, not the PrintJob API.

Without knowing the details of your code, you should consider using the
PrinterJobs API, larger BufferedImages, and an AffineTransform to map
these larger images to your page size when printing.

Alternatively, using the PrinterJobs API you might also not need the
ArrayList at all, since the framework calls your print method with a
page number and a Graphics to draw onto. Depending on your application,
you could generate all the pages on the fly.

You could also have a look at the rendering hints and turn text
antialising on.

I am going the larger BufferImages and then scale down to the page size
when printing approach. Using this test code I am trying to scale all
the text I write to be ten times as large and then scale it down by a
tenth when writing to the page. I'm obviously doing something wrong, is
there a better way to do this?

public int print(Graphics graphics, PageFormat pageFormat, int
pageIndex) throws PrinterException {

if( pageIndex > 0 )
return Printable.NO_SUCH_PAGE;

BufferedImage page;
page = new BufferedImage( (int)pageFormat.getWidth()*10,
(int)pageFormat.getHeight()*10, BufferedImage.TYPE_BYTE_BINARY );
Graphics2D gr = page.createGraphics();
gr.scale(10.0, 10.0);
gr.setColor( Color.WHITE );
gr.fillRect(0, 0, (int)pageFormat.getWidth(),
(int)pageFormat.getHeight() );
gr.setColor( Color.BLACK );

gr.translate( pageFormat.getImageableX(),
pageFormat.getImageableY() );
gr.drawString("Test String", 30, 30 );

((Graphics2D)graphics).translate( pageFormat.getImageableX(),
pageFormat.getImageableY() );
((Graphics2D)graphics).scale(.10, .10);
((Graphics2D)graphics).drawImage( page, null, 0, 0 );

return Printable.PAGE_EXISTS;
 

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

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,202
Latest member
MikoOslo

Latest Threads

Top