问题
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 I'm using CUPS to print. I'm printing using the Printable interface (pretty standard in Java).
My problem:
Text printing quality is very low on every printer resolution (60x60, 120x60, 120x72). It seems like there's no font hinting at all in some printer driver. Letters is looking very ugly. I can't use direct text-out to port (it looks great), 'cause I need also to print graphics on the same page.
It seems that problem is not in Java, cause the same application prints the high-quality text and graphics in Windows. Also it seems that problem is not in CUPS system, cause OpenOffice or Abiword prints the same text with the same fonts with the very good quality (worse than in Windows but still good).
Also problem is not with fonts: i'm tryed the Tahoma font from Windows, and it does the same: low quality while printing in java/linux.
The problem is not with BCI-hinting in X.Org, displaying on the screen is great looking.
When I export any document from OpenOffice to PDF and printing that PDF, I got the same effect - ugly not-hinted fonts on the paper. If the same document is printed from Office, everything is ok.
I tryed different Linuxes (KUbuntu 10.04, Puppy 2, Puppy 4.3.1) and I got the same effect on any Linux.
Maybe the problem is in Ghostscript, I got 9.x version on Puppy and still the same. Or also I think that there can be problem with CUPS rasterizer ('rastertoepson' or 'foomatic-rip').
It's example of output (sorry for the "mobile"-quality photo):
I just got no idea what's going on, help me please.
-- P.S. my final solution is to use 'ESCPrinter.java" open-source class, adding to it a capability of printing images according Epson documentation.
回答1:
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;
}
回答2:
[ 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.
回答3:
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
来源:https://stackoverflow.com/questions/8969909/java-printing-quality-in-linux-on-dot-matrix-printer