将文件发送到windows打印机-java
我试图用JAVA编写一个小程序,将X>=1文件发送到windows打印机,打开windows打印机对话框,等待用户选择默认打印机并单击打印。 比如在JS中,我可以使用“window.print()” 我尝试使用以下代码:将文件发送到windows打印机-java,java,cmd,printing,Java,Cmd,Printing,我试图用JAVA编写一个小程序,将X>=1文件发送到windows打印机,打开windows打印机对话框,等待用户选择默认打印机并单击打印。 比如在JS中,我可以使用“window.print()” 我尝试使用以下代码: public void printFile(String path) throws FileNotFoundException { FileInputStream in = new FileInputStream(path); Doc doc = new Sim
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, 100, services, service, null, attrs);
}
但是