java - 如何在Windows操作系统中使用打印机以及在Linux ubuntu中使用我的程序

标签 java printing epson

我在服务器 linux ubuntu 中的程序和我在 Windows 中的打印机 我想从链接打印数据并在 Windows 中打印 我尝试打印:

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

但是没用 有解决办法吗?

我的代码是:

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();

我的打印机是EPSON TM-U295

最佳答案

你应该使用PrinterJob

这就是 Java 为此类情况提供的 API。 这是一个可以帮助您入门的小代码片段:

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

我刚刚意识到我忘记提及如何连接到打印机,这是一个有用的 link

关于java - 如何在Windows操作系统中使用打印机以及在Linux ubuntu中使用我的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36788149/

相关文章:

Java - 无法从 MySQL StoredProcedure 返回/访问结果集

windows - 网络中断时打印到本地共享打印机

printing - 在 Debian Wheezy 上设置 USB 串行收据打印机(epson tm-t88ii/iii 兼容)

javascript - 如何在客户端不弹出打印对话框的情况下打印收据

java - 使用涉及日期限制的 JPA2 通过 EntityManger 重写 Hibernate SessionFactory 查询

java - Android 应用程序上的 Math.min 问题

java - 使用流 api 查找最大的目录

java - 如何制作 JFrame 的 PDF(包括未显示的 JScrollPane 部分)?

java - 在Java中打印带有下一行的字符串(斑马线模式)

objective-c - 使用 Swift 的 Epson 打印机找不到 arm64 的符号