Domanda

I've tried to print out a table using a dotmatrix printer, it worked but the text quality was very bad. So I tried to print it using the simple FileWriter:

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

The problem is, I also want to print images and lines (to form a table). How do I do this without messing up the quality of the text.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top