• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

Java printing on Star Micronics lineprinter ...

The model is called DP8340 ... but the main problem is that it is a lineprinter. The only way I know of getting data out on a printer is by creating a graphic area a draw stuff on it .... see below ...

So, if anybody know a way of solving this problem, please help me ...

Thanks in advance

/Chris


    private void OnClickPrint(Object source, Event e)
    {
        Toolkit tools = Toolkit.getDefaultToolkit();
        WPrintJob wpj = (WPrintJob)tools.getPrintJob(null, "Print?", null);
        if(wpj != null)
        {
            Graphics g = wpj.getGraphics();
            Font font = new Font("Courier", 0, 24);
            g.setFont(font);
            if(g != null)
            {
                g.drawString("Printing!!!", 50, 50);
                g.dispose();
            }
            wpj.end();
               
        }        
    }
0
ChristerH
Asked:
ChristerH
  • 4
  • 4
  • 2
  • +1
1 Solution
 
ChristerHAuthor Commented:
I think I forgot to tell you .. the problem is that the code I passed before does not work for lineprinters.
0
 
heyhey_Commented:
you can send text only information directly to the printer (port) ..

OutputStream os = new OutputStream("LPT1"); // win;
os.write("\n\rPrinting ...");

for other OSes - use the appripriate device.
0
 
vladi21Commented:
  If you simply want to print text, then write it to a file and print the
     file. Or open a filename that corresponds to the printer. On Windows,
     that is "LPT1" and the code looks like:

     try {
         FileOutputStream fos = new FileOutputStream("LPT1");
         PrintStream ps = new PrintStream(fos);
                 ps.print("Your string goes here");
                 ps.print("\f");
                 ps.close();
     } catch (Exception e) {
         System.out.println("Exception occurred: " + e);
     }
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Ravindra76Commented:

Hi : vladi21,

 If it is unix, what is the related command?

Thank you
0
 
ChristerHAuthor Commented:
This works ok!

FileOutputStream fos = new FileOutputStream("LPT1");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeChars("Hello Star!\n");
dos.close();

Thanks!

What about the points?
0
 
vladi21Commented:
Answer:

   If you simply want to print text, then write it to a file and print the
     file. Or open a filename that corresponds to the printer. On Windows,
     that is "LPT1" and the code looks like:

     try {
         FileOutputStream fos = new FileOutputStream("LPT1");
         PrintStream ps = new PrintStream(fos);
                 ps.print("Your string goes here");
                 ps.print("\f");
                 ps.close();
     } catch (Exception e) {
         System.out.println("Exception occurred: " + e);
     }
 
0
 
heyhey_Commented:
greedy vladi :)
we can at least split the points ...
0
 
vladi21Commented:
heyhey_: You have a lot of points:)
0
 
heyhey_Commented:
I see - today is your answering day :)

why don't you go out for some night life ? :)
0
 
heyhey_Commented:
Server's poor response
Not quick enough for browser.
Timed out, plum blossom.
0
 
vladi21Commented:
problems with provider... :)
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now