I need to print the report from a Java desktop application to a dot-matrix printer (Epson LX-300 II). Report consists of text ang some graphics. Printer is connected via USB and
You could give setRenderingHint
a try; copied some calls together for typing ease.
Maybe it is TEXT_ANTIALIASING, but I would not exclude the others.
An other idea, would be that somewhere screen resolution is scaled to print resolution; a small java app with do-it-yourself printing would show that.
You did not do a rotate
, did you? (Just seeing the photo).
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
Graphics2D g = (Graphics2D) graphics;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
return Printable.PAGE_EXISTS;
}
From my expreience, this could be because the fonts are not recognized by Java, and it defaults to other standard fonts.
You'll need to put the ttf files into the $JAVA_HOME/jre/lib/font
directory
Perhaps these articles on java fonts and on physical fonts could be more of help
[ tl;dr: It's practically impossible. Use another printer or switch to text mode. ]
Dot-matrix printers, especially the 9-pin variety (such as Epson's LX series), are more or less optimised for text printing. While it is possible to print graphics, their resolution is really low, much lower than today's standard printers. In times past, you had to optimise your output such as to get maximum fidelity from your printout; nobody in their right mind would have tried to print text in graphics mode on those printers, which practically guarantees an unreadable output. The printer's built-in fonts are optimised for readability, but if the rasterisation is done by the printer driver without regard to the particularities of the printer, the result has to be less optimal.
The resolution of 9-pin printers such as Epson's LX series is way too low for this. Unless you print in text mode (which, if you didn't build that reporting application yourself, is pretty much impossible), you won't get a better result. A 24-pin printer would have enough 'reserve' to still get you decent enough printout, but a 9-pin printer is already operating on its limits.
Whatever trickery you do with font hinting or whatever, unless you use really big fonts (where the font is big enough to offset the low resolution of the printer), there's nothing you can do, short of using another printer. The problem is the rasterisation, which cannot fit the physical limitations of the printer.
( The 'correct' way to do reports on a dot-matrix printer would be to print whatever possible as 'pure' text, exploiting the various ESC/P formatting commands such as boldface, underlining and so on. If you needed graphics, you would enter graphics mode for that particular graphic, then continue in text mode. The printer's built-in fonts are optimised to be as readable as possible, given the limitations of the way the printer operates, though it is possible to define your own. )
This is from experience: I still own a 9-pin and several 24-pin printers (all Epsons) and mostly drive them in text mode. I can (and do) use the 24-pin printer as a generic Windows (or whatever) printer, but with the 9-pin printer this is practically unfeasible. But with some thought, I can get quite nice results out of them which would require a lot more work on more 'modern' printers.