2

我尝试使用点阵打印机打印出一张表格,它可以工作,但文本质量非常糟糕。所以我尝试使用简单的 FileWriter 打印它:

FileWriter out;
try 
{
    out = new FileWriter("LPT1:");
    out.write(string);
    out.flush();
    out.close();
} 
catch (IOException ex) 
{
}

问题是,我还想打印图像和线条(以形成表格)。如何在不破坏文本质量的情况下做到这一点。

4

1 回答 1

3

Depending on the quality you expect, the most straight forward solution would be to use some ASCII pseudo graphics for the table.

column 1 | column 2 | column 3
______________________________
value 11 | value 12 | value 13
value 21 | value 22 | value 23
value 31 | value 32 | value 33

I case you expect to get solid lines for the table, you need to print everything in real graphics mode (instead of text mode of the printer). Therefore I would use JasperReports

edit A piece of code to show the principal of using ESC/P printer control codes to switch on/off the underline text printing mode.

final String UNDERLINE_ON = "\u001B\u002D\u0001";
final String UNDERLINE_OFF = "\u001B\u002D\u0000";
final String CRLF = "\r\n";

out.write(UNDERLINE_ON + "column 1 | column 2 | column 3" + UNDERLINE_OFF + CRLF);
out.write("value 11 | value 12 | value 13" + CRLF);
out.write("value 21 | value 22 | value 23" + CRLF);
out.write("value 31 | value 32 | value 33" + CRLF);

edit: The mentioned document about ESC/P codes can be accessed for example via

https://web.archive.org/web/20150213082718/http://support.epson.ru/products/manuals/000350/part1.pdf

于 2013-10-14T14:50:41.840 回答