Java print quality on Linux dot matrix printer

I need to print a report from a Java desktop application to a dot matrix printer (Epson LX-300 II). The report consists of the text ang of some graphics. The printer is connected via USB, and I use CUPS for printing. I print using the Printable interface (pretty standard in Java).

My problem:

The print quality of the text is very low at each resolution of the printer (60x60, 120x60, 120x72). There seems to be no hint of font in any printer driver. The letters look very ugly. I cannot use direct text output to the port (this looks great) because I also need to print the graphics on the same page.

It seems that the problem is not in Java, because the same application prints high-quality text and graphics on Windows. It also seems that the problem is not in the CUPS system, because OpenOffice or Abiword prints the same text with the same fonts in very good quality (worse than on Windows, but still good).

Also the problem is not in fonts: I tried the Tahoma font from Windows and it does the same thing: poor quality when printing in java / linux.

The problem is not that the BCI hint in X.Org, the display on the screen looks great.

When I export any document from OpenOffice to PDF and print this PDF, I get the same effect - ugly fonts not outlined on paper. If the same document is printed in Office, everything is in order.

I tried different Linux (KUbuntu 10.04, Puppy 2, Puppy 4.3.1), and I got the same effect on any Linux.

Perhaps the problem is in Ghostscript, I got version 9.x on Puppy and still the same. Or also I think that there may be problems with the CUPS rasterizer ("rastertoepson" or "foomatic-rip").

This is an example of output (sorry for the "mobile" -quality of the photo):

enter image description here

I just did not understand what was going on, help me.

- The postscript my final solution is to use the open source class "ESCPrinter.java", adding to it the ability to print images in accordance with the Epson documentation.

+4
source share
3 answers

You can try setRenderingHint to try; copied several calls to simplify input. It may be TEXT_ANTIALIASING, but I would not rule out others.

Another idea would be that somewhere the screen resolution scales to print resolution; a small java application with its own print would show this.

You did not rotate , right? (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; } 
+1
source

From my point of view, this may be due to the fact that fonts are not recognized by Java and other standard fonts are used by default.

You will need to put the ttf files in the $JAVA_HOME/jre/lib/font directory

Perhaps these articles on java fonts and physical fonts might be more useful

0
source

[tl; dr: It's almost impossible. Use a different printer or switch to text mode. ]

Dot matrix printers, especially 9-pin printers (like the Epson LX series), are more or less optimized for text printing. Although you can print graphics, their resolution is really low, much lower than today's standard printers. In the past, you had to optimize your result in order to get the maximum accuracy from your printout; no one in their right mind would try to print text in graphic mode on these printers, which practically guarantees unreadable output. The built-in printer fonts are optimized for readability, but if rasterization is performed by the printer driver without considering the printer, the result should be less than optimal.

The resolution of 9-pin printers, such as the Epson LX, is too low for this. If you do not print in text mode (which, if you did not create this reporting application yourself, is largely impossible), you will not get a better result. There will be enough “reserve” for a 24-pin printer to get a decent enough printout, but a 9-pin printer is already running at its borders.

No matter what complexity you make with the font hint, or whatever, if you are not using really large fonts (where the font is large enough to compensate for the low resolution of the printer), you cannot do anything unless you use another printer. The problem is rasterization, which cannot match the physical limitations of the printer.

(The “right” way to report on a dot matrix printer is to print as much as possible as “clean” text using various ESC / P formatting commands such as bold, underline, etc. If you need graphics, you should enter the graphic mode for this particular graphic object and then continue in text mode. The printer’s built-in fonts are optimized as much as possible, taking into account the limitations of the way the printer works, although you can define your own.)

This is from experience: I still have a 9-pin and several 24-pin printers (all Epsons) and basically bring them in text mode. I can (and do) use a 24-pin printer as a shared Windows (or other) printer, but with a 9-pin printer this is practically impossible. But, with some guesses, I can get good results from them, which will require much more work on more “modern” printers.

0
source

Source: https://habr.com/ru/post/1392440/


All Articles