无法在Windows 7中使用Java 8打印文本文件
发布时间:2020-12-13 20:12:24 所属栏目:Windows 来源:网络整理
导读:我创建了一个报告并将其导出为文本文件,以便在矩阵打印机中打印,但是作业的结果是空白页.我在ubuntu中也是这样做的,正确打印. 这是 Java bug吗? 这是我向您显示问题的示例代码: public class PrintError extends Application { public static void main(St
我创建了一个报告并将其导出为文本文件,以便在矩阵打印机中打印,但是作业的结果是空白页.我在ubuntu中也是这样做的,正确打印.
这是 Java bug吗? 这是我向您显示问题的示例代码: public class PrintError extends Application { public static void main(String args[]) { launch(args); } public void start(Stage stage) throws PrintException { PrinterJob printerJob = PrinterJob.createPrinterJob(); printerJob.showPrintDialog(stage); PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); printRequestAttributeSet.add(new Copies(printerJob.getJobSettings().getCopies())); printRequestAttributeSet.add(new JobName("test",Locale.getDefault())); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; Doc mydoc = new SimpleDoc(ClassLoader.class.getResourceAsStream("/should-be-printed.txt"),flavor,null); DocPrintJob job = getPrintService(printerJob.getPrinter().getName()).createPrintJob(); job.print(mydoc,printRequestAttributeSet); } private PrintService getPrintService(String name) { for (PrintService printService : java.awt.print.PrinterJob.lookupPrintServices()) { if (name.equalsIgnoreCase(printService.getName())) { return printService; } } return null; } } 此示例在JavaFx 8中创建,并在Windows 7中的Java build 1.8.0-b132中运行.
从
documentation:
当您有一个PrintService实例时,您可以使用getSupportedDocFlavors()方法来查找它支持哪些风格. 当你发现没有一个DocFlavor. INPUT_STREAM. TEXT_PLAIN_ …味道在列表中,它无助于使用AUTOSENSE,因为这仅仅意味着“最好的猜测”,并且PrintService将不太可能猜到它不支持的类型,而是更有可能数据将被误解为支持的格式之一. 在我的Windows机器上,没有一个提供的PrintServices支持打印明文… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在Windows Intel和Solaris Sparc(T1000)上运行JAVA
- 解析 – Dos批处理:如何从不是参数的变量中获取文件名?
- opengl – 将uint属性传递给GLSL
- 如何为Windows上的带宽使用提供正在运行的进程优先级?
- Office Online Server 在线编辑Office文档,安装部署
- windows – Azure教程 – 如何使用本地blob存储
- windows-phone-7 – 您是否需要许可才能开发Windows手机和黑
- Windows Server 2016-Nano Server介绍
- unit-testing – 以编程方式将.reg文件合并到win32注册表中
- Microsoft SQL Compact Edition重命名列
推荐文章
站长推荐
- windows-server-2003 – 可以重命名私有MSMQ队列
- 在Windows中,如何输入Unicode基本多语言平面之外
- Windows 设置定时任务
- [Windows 8] 给我磁盘备援的方法吧-RAID
- winapi – 如何将密钥笔划发送到窗口而不必使用W
- 脚本 – 用于更改MSI中的操作序列记录的脚本
- windows x64函数调用约定(function call convent
- vbscript – 如何在64位Windows中检索启动文件夹
- Windows Phone 7 – Windows Phone开发Visual St
- 超高速多进程操作key为uint32 value为uint32的数
热点阅读