Catatan Seorang Prajurit Kecil

Ikon

biarlah semua itu berjalan sesuai "skenario" NYA – jika kau telusuri, semua logika itu akan kau temukan

Java Direct Printing with Countinues Paper

Hi guys,

This article show you how to create direct print with continues paper in Java SE. Direct Print is a term refer that print with line mode, you can find this case in mini market, billing system etc, direct print enable you to print line per line without reload the paper, so you can use continues paper.

In Java, you can use FileWriter object to write text to printer device, in the end of this article I attach the file which show to you how it work. I try that code with EPSON LX-300+ II and it’s running correctly.

Below the step how to write text to printer device:

First:

Define your printer device location. Commonly you can use \\127.0.0.1\PRINTERNAME as printer device location. Just remember, you have to share your printer device. Until today I call it’s bug, so if you have fix it, please comment this article and give me reference to fix it. Once again, just remember in java you have to use \\\\127.0.0.1\\PRINTERNAME (read java character for more information)

Second:

Create FileWriter Object with refer to printer location. For example look at this code: 
FileWriter writer = new FileWriter(“\\\\127.0.0.1\\LX300”);
Where LX300 is my printer device name

Third:
Write something which you want to write to your printer device. For example:
writer.write(“This will be write to your paper…”);

Basically, with 3 step above, you have successfully write, but sometime, we need more complex character, such as: Carriage Return, Tabulation etc.. In Java you can use character ‘\n’ for carriage return (read Java API Character for more information).

Just an information, my friend have try to use direct print with other program language, it’s Delphi. He said that “in Delphi you cant use ‘\n’ to write the carriage return”

So..please share, if you have any experiment about it..Download source code here.

If you download source code, you will find more complex character and feature to direct print with other resource, such as: from local file, from url file and etc… so try it, share if you have an experiment or question 🙂

Filed under: Algorithm and Programming, ,

Navigasi

Total Pengunjung

  • 109,971 hits