Java:打印文件无法工作

3

我使用Java 1.6(JDK),Windows 7和虚拟图像打印机驱动程序。

我尝试打印一些文档。

这是我的代码:

try {    

   System.out.println(" PrintServiceOverseer printFileToDefaultPrinter start "+ 
      fileName);            

   PrintService printService = PrintServiceLookup.lookupDefaultPrintService();

   System.out.println(" default Printer " + printService.getName());

   FileInputStream inputStream = new FileInputStream(new File(fileName));  

   DocFlavor docFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE;   

   Doc printDoc = new SimpleDoc(inputStream, docFlavor, null);

   PrintRequestAttributeSet  pras = new HashPrintRequestAttributeSet();
   pras.add(new Copies(1));   

   DocPrintJob printJob = printService.createPrintJob();

   printJob.print(printDoc, pras);

   inputStream.close();    

   System.out.println(" PrintServiceOverseer printFileToDefaultPrinter end "); 
} catch (Exception ex) {
        ex.printStackTrace();
}

但是它没有起作用。它没有输出任何内容,也没有抛出异常。代码编译和运行顺利,但没有输出结果。

您能给我一些指导吗?

1个回答

0

我遇到了同样的问题,我通过更新打印机驱动程序来解决它,我认为你没有安装正确的驱动程序,可能安装了适用于你的打印机但不是正确的驱动程序。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接