I use Java 1.6 (JDK), Windows 7 and a virtual image printer driver.
I try to print some documents.
Here is my code
try {
System.out.println(" PrintServiceOver开发者_C百科seer 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();
}
But it doesn't work. It prints nothing and no exception is thrown. The code compiles and runs smoothly, but there is no output.
Can you give me some guidance?
I got the same problem, I solved it by updating my printer's driver, I think you didn't install the proper driver, you may installed a driver which works for your printer but not the proper one.
精彩评论