1

my program in server linux ubuntu and my printer in Windows i want to print data from link and print in windows i try to print with:

SMB:\\\\Ip printer\\Name printer

but it don't work have solution?

my code is:

string1="test";
InputStream br = new ByteArrayInputStream(test.getBytes());
BufferedReader in = new BufferedReader(new InputStreamReader(br));
String line;
FileWriter out = new FileWriter("SMB:\\\\IP printer\\name printer");
while((line = in.readLine()) != null)
{  
    System.out.println("line"+line);
    out.write(line);
    out.write(0x0D);  CR
    out.write('\n');
    writer.println(line);
}
out.close();
in.close();

my printer is EPSON TM-U295

lucky kurniawan
  • 136
  • 2
  • 8

1 Answers1

0

you should use PrinterJob

This is what Java provides as API for such cases. Here is a small code snippet to get you started:

PrinterJob printerJob = PrinterJob.getPrinterJob();
printerJob.setPrintable(new CustomPrintable("DATA TO PRINT"));
boolean printOK = printerJob.printDialog();
if (printOK){} 
    try {
        printerJob.print();
    }
    catch (PrinterException e){
        // Error
    }
}

I just realized I forgot to mention how to connect to you printer, here is a usefoul link

Community
  • 1
  • 1
Borislav Stoilov
  • 3,247
  • 2
  • 21
  • 46