将Printer PageLayout边距设置为零 [英] Set Printer PageLayout margin to zero

查看:232
本文介绍了将Printer PageLayout边距设置为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个允许用户打印节点的小型Javafx应用程序。我希望保证金为零。我在下面使用了以下代码,但它没有用。

I created a small Javafx application that allows the user to print a node. I want the margin to be zero. I used the following code below, but it didn't work.

printer = javafx.print.Printer.getDefaultPrinter();
pageLayout = printer.createPageLayout(Paper.JAPANESE_POSTCARD,  PageOrientation.PORTRAIT, 0.0f, 0.0f, 0.0f, 0.0f);

根据文档, createPageLayout 是边距(左,右,上,下)。我进行了打印测试,但打印文档中仍然有 0.5英寸边距

According to the documentation, the last four parameters in createPageLayout is the margins(Left,Right,Top,Bottom). I made a print-test but there still a 0.5 inch margin in the printed document.

发生了什么事?任何想法?

What's going on? Any Idea?

推荐答案

您正面临硬件限制问题即可以应用于Paper的边距取决于硬件/打印机,而不仅仅是用于访问它的 API 。在这种情况下,尽管JavaFX允许您将保证金值传递为 0 ,但稍后会重新分配它们以支持打印机的最小值。

You are facing a hardware limitation issue i.e. the margin that can be applied to a Paper depends on the hardware / printer and not just the API used to access it. In this case, though JavaFX allows you to pass margin values as 0, but they are later re-assigned to support the printers minimum values.

来自 Javadocs


一个客户端需要知道哪些保证金值合法应该首先使用HARDWARE_MINIMUM边距获得PageLayout。

A client that needs to know what margin values are legal should first obtain a PageLayout using the HARDWARE_MINIMUM margins.

如果打印机不能支持指定的布局,它会将返回的布局调整为支持的配置

If the printer cannot support the layout as specified, it will adjust the returned layout to a supported configuration

您可以使用 Printer.MarginType.HARDWARE_MINIMUM 创建布局时,检查允许的最低保证金。

You can use Printer.MarginType.HARDWARE_MINIMUM while creating a layout, to check the minimum margin allowed.

pageLayout = printer.createPageLayout(Paper.JAPANESE_POSTCARD,  
             PageOrientation.PORTRAIT, Printer.MarginType.HARDWARE_MINIMUM);

这篇关于将Printer PageLayout边距设置为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆