使用新的 java 1.6 JTextComponent print() 时如何更改打印参数

发布于 2024-10-05 23:58:18 字数 554 浏览 0 评论 0原文

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

boolean print(MessageFormat headerFormat, MessageFormat footerFormat, boolean showPrintDialog, PrintService 服务, PrintRequestAttributeSet 属性, boolean Interactive);

这再次打印出我的内容。

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

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

我现在遇到的问题是试图让我的内容适合可打印区域 - 我希望有更多的控制权 - 我想使用 PrintJob 和 Document 这可以通过 PageFormat 对象获得 - 但我不知道如何使用上面的便捷打印方法执行相同的操作。

提前致谢 -一个-

I have a JTextComponent (JTextArea). I am trying to print its contents with using the new 1.6 .print() functionality. This is working well. I am also doing this in a headless/non-interactive mode using the following method signature:


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

Again this prints out my content.

HOWEVER... I would like to set my own print parameters (namely Margin size and Paper Size)..Mine are custom/non-standard as this is for a receipt printer -

Is there any way to set/configure this information when using this form of printing ?

The problem I am having now is trying to get my content to fit the printable area - and I would love to have more control - I guess using PrintJob and Document this would be available through the PageFormat object - But I don't know how to do same using the convience print method above.

Thanks in advance
-A-

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

佞臣 2024-10-12 23:58:18

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

您创建一个 PrintRequestAttributeSet 的新实例,

PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();

然后需要将请求的属性添加到该集合中。 查看此处了解所有您可以使用不同的属性。

我认为您需要 MediaSizeMediaPrintableArea

You need to use the PrintRequestAttributeSet attributes to specify the attributes of the print job.

You create a new instance of the PrintRequestAttributeSet

PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();

You then need to add the attributes for your request to that set. Take a look here for all the different attributes that you can use.

I think you will need MediaSize and MediaPrintableArea

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文