This discussion is archived
1 Reply Latest reply: Oct 26, 2011 2:20 PM by ArtashesGamarian RSS

Print quality issues

896364 Newbie
Currently Being Moderated
I have created a custom applet that mimics an existing document viewer functionality being replaced by AutoVue. I used the awtsample.java as the basis for my print Action, but I find the print quality is poor for most documents. It looks like when I call VueBean#renderOnToGraphics(...), it always assumes a zoom level of 100%, which for most documents is unreadable. I notice that the JVue print functionality has no such limitation and always prints with very high quality. How can I use the VueBean API to do this same high-quality printing?
  • 1. Re: Print quality issues
    ArtashesGamarian Explorer
    Currently Being Moderated
    Java printing framework assumes by default 72 DPI. The printer graphics typically has a transformation to scale from 72 DPI to printer's resolution.
    To achieve better quality the simplest approach is to scale down printer graphics and to scale up by the same factor destination rectangle in RenderOptions.

    E.G. here is modified code snippet from AWTSample:

    final double scale = 2.0;
                        
    ((Graphics2D)graphics).scale(1.0/scale, 1.0/scale);

    Rectangle pageRect = new Rectangle((int)(pageFormat.getImageableX() * scale),
    (int)(pageFormat.getImageableY() * scale),
    (int)(pageFormat.getImageableWidth() * scale),
    (int)(pageFormat.getImageableHeight() * scale));

    For best quality you need to reset the graphics transform to identity and scale destination rectangle by scale factor that graphics originally had, but in this case you will need to band data that you send to printer (call renderOntoGraphics() in a loop, shifting source and destination), otherwise for some file formats you will easily run out of memory.

    Hope this helps. Let me know if you still have issues with it.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points