4
我对Java打印服务问题。我需要打印一个简单的文本文档,到我的默认打印机。我在Windows机器上使用HP Deskjet作为我的打印机,安装了所有驱动程序。这是源代码,我使用:打印作业提交到打印机,但没有打印任何东西。 Java的
import java.io.*;
import javax.print.*;
public class PrintTest {
public static void main(String[] args) throws IOException {
File file = new File("print.txt");
InputStream is = new BufferedInputStream(new FileInputStream(file));
//Discover the default print service.
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
//Doc flavor specifies the output format of the file.
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
// Create the print job
DocPrintJob job = service.createPrintJob();
//Create the Doc
Doc doc = new SimpleDoc(is, flavor, null);
//Order to print
try {
job.print(doc, null);
} catch (PrintException e) {
e.printStackTrace();
}
is.close();
System.out.println("Printing done....");
}
}
我可以看到打印机队列中的打印作业时前的走了几个milisecond。但没有打印。我听说这是因为在JDK 1.6的Java打印服务仍然是越野车。但我不完全确定。任何想法为什么?
请让我知道如果你发现任何解决方案,我面临同样的问题。给你的回应[这里](http://stackoverflow.com/questions/15810865/print-current-html-page-on-printer-from-java-bean-in-jsf) –