Java打印 - 打印队列中的假脱机

时间:2016-01-16 16:22:30

标签: java printing

我想使用基于java的软件(特别是Netbeans)将pdf文件打印到打印机。当我在下面运行我的代码时,我看到文档处于打印队列中,文件名为" Java Document" 假脱机状态

问题是:

我想知道为什么我的打印机即使在队列中也不打印文档? 是因为代码还是因为我的打印机?

这是我的代码:

    public String gonnaGo(String newfile) throws FileNotFoundException,   PrintException, IOException{

     System.out.println("Hello!" + newfile);
     InputStream is;
        is = new BufferedInputStream(new FileInputStream(newfile)); //The new file will be the one to be printed
        Doc doc = new SimpleDoc(in, DocFlavor.INPUT_STREAM.AUTOSENSE,null);
        PrintService service = PrintServiceLookup.lookupDefaultPrintService();
  // Locate the default print service for this environment.
            System.out.println("Default printer: " +    PrintServiceLookup.lookupDefaultPrintService().getName()); 
  //Check if the file  directory of the file to be printed is included

        PrintRequestAttributeSet params = new HashPrintRequestAttributeSet(); //ADD PRINTING PROPERTIES HERE
        params.add(new Copies(1));

        DocPrintJob printJob = service.createPrintJob(); //used to determine whether the print job is finished
        printJob.addPrintJobListener(new JobCompleteMonitor());


        service.createPrintJob().print(doc, params);

        System.out.println("Exiting app");
        is.close();
    return null;        
        }

这是输出,不打印任何内容。我的打印机已连接。 我使用佳能ip2770系列,Epson Stylus TX117和带有最新驱动程序的HP Deskjet 2510系列。 enter image description here

0 个答案:

没有答案