1

I am using the class Graphics2D to print some texts from a Java application. To print it I am implementing the interface Printable and the class Graphics2D. Then I use the method drawString from Graphics2D.

The thing is that sometimes (depending on the string I am printing), some characters are on top of each other and the spacing between characters is crazy.

Does anyone know why?

averageman
  • 893
  • 3
  • 12
  • 19
  • A code sample, and perhaps a screenshot, would help us find your answer. – Hannele Feb 15 '12 at 17:27
  • As for why, I guess different String could be overlapping, or possibly the font could be odd. You can use the: g.setFont(new Font(String name, int mod, int size)); –  Feb 15 '12 at 17:28
  • I noticed I had "kerning on". What is it anyway? – averageman Feb 15 '12 at 17:39
  • For better printable output, consider using a report writer library instead of Swing. Often it comes down to using the best tool for the job. You could easily integrate this with your current Swing application if needed. – Hovercraft Full Of Eels Feb 15 '12 at 17:52

2 Answers2

2

This question mentions setting RenderingHints. Fractional metrics, anti-aliasing or hinting might be of use. You could try another font too.

Community
  • 1
  • 1
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
-1

For workaround of this issue Set the public static property RasterPrinterJob.shapeTextProp to true.

Ekrem Kucuk
  • 481
  • 4
  • 4