【发布时间】:2015-08-30 14:43:37
【问题描述】:
我正在尝试使用 JAVA PrintServices API 打印非常简单的 HTML 文件。
这就是我为此写的 -
public class WebTest {
public static void main(String args[]) throws Exception {
String filename = "C:/tmp/PrintTest.html";
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
if (defaultService != null) {
DocPrintJob job = defaultService.createPrintJob();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
}
System.exit(0);
}
但是,我的输出文件格式不正确 - 这是我在打印输出中看到的 -
<!DOCTYPE html>
<html>
<body>
<h2>Hello World.</h2>
</body>
</html>
我想看到输出为 -
Hello World.
我也尝试过为此使用 Microsoft 命令 - "C:\\Program Files\\Microsoft Office\\Office14\\msohtmed.exe\" /p C:/tmp/PrintTest.html
但是它提示我打印框,我想摆脱它。
我的目标只是获得正确的打印输出。
请提出合适的选择。
我已经参考了其他链接,但找不到我正在寻找的确切答案。
非常感谢您的帮助。
【问题讨论】: