将文件发送到Windows打印机-Java

问题描述

我试图用JAVA制作小程序,我将向Windows打印机发送X> = 1个文件,并打开Windows打印机对话框,等待用户选择认打印机并单击“打印”。 就像在JS中可以使用“ window.print()”一样。

我尝试使用以下代码

public void printFile(String path) throws FileNotFoundException {
    FileInputStream in = new FileInputStream(path);
    Doc doc = new SimpleDoc(in,DocFlavor.INPUT_STREAM.AUTOSENSE,null);
    
    PrintService[] services = PrintServiceLookup.lookupprintServices(null,null);
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();

    PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
    attrs.add(Sides.DUPLEX);
    
    PrintService selection = ServiceUI.printDialog(null,100,services,service,null,attrs); 
}

但是

  1. 它打开Java打印对话框,而不是Windows打印对话框,
  2. 它不会发送我的文件(因为我不知道该如何处理“ doc”变量)
  3. 及其不包含多个文件的选项...

我该怎么办?

tnx

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)