我有一个JtextComponent(JTextarea)。我正在尝试使用新的1.6 .print()功能打印其内容。这很好。我还使用以下方法签名在无头/非交互模式下进行此操作:

boolean print(MessageFormat headerFormat, MessageFormat footerFormat, boolean showPrintDialog, PrintService service, PrintRequestAttributeSet attributes, boolean interactive);

再次打印出我的内容。

但是...我想设置自己的打印参数(即保证金的大小和纸张尺寸)。我的是自定义/非标准,因为这是用于收据打印机 -

使用这种形式的打印时,有什么方法可以设置/配置此信息?

我现在遇到的问题是试图使我的内容适合可打印区域 - 我很想拥有更多的控制权 - 我想使用printjob并通过pageformat对象进行文档,但我不知道该如何使用上面的Crectience Print方法执行同样的操作。

预先感谢-A-

有帮助吗?

解决方案

您需要使用printrequestattributeset属性来指定打印作业的属性。

您创建了一个新实例 PrintRequestAttributeSet

PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();

然后,您需要将请求的属性添加到该集合中。 在这里看看 对于所有可以使用的不同属性。

我想你会需要 MediaSizeMediaPrintableArea

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top