打印作业已提交到打印机,但未提交';不要打印任何东西。JAVA
我对Java打印服务有问题。我需要在默认打印机上打印一个简单的文本文档。我在Windows计算机上使用HP Deskjet作为打印机,安装了所有驱动程序。这是我使用的源代码:打印作业已提交到打印机,但未提交';不要打印任何东西。JAVA,java,service,printing,Java,Service,Printing,我对Java打印服务有问题。我需要在默认打印机上打印一个简单的文本文档。我在Windows计算机上使用HP Deskjet作为打印机,安装了所有驱动程序。这是我使用的源代码: import java.io.*; import javax.print.*; public class PrintTest { public static void main(String[] args) throws IOException { File file = new File("print.txt")
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....");
}
}
我可以在打印机队列中看到打印作业数毫秒后才消失。但是什么也没印出来。我听说这是因为JDK1.6中的Java打印服务仍然存在缺陷。但我不完全确定。你知道为什么吗?我知道这是一个很晚的答案,但我在Windows和PDF(不是文本)上遇到了同样的问题。似乎打印机可能无法处理本机PDF,因此接受该作业,但什么也没有发生(也没有错误)。我通过使用第三方lib解决了这个问题,它的效果非常好
我通过回答一个类似的问题编写了一些代码示例。如果您找到任何解决方案,请告诉我,我也面临同样的问题。给出你的回答