gpt4 book ai didi

java - 如何在java中设置打印机边距

转载 作者:搜寻专家 更新时间:2023-10-31 19:55:00 26 4
gpt4 key购买 nike

尝试使用 Print API 进行打印时 - 边距似乎不受我们控制!...请帮我设置打印机边距,或者有什么方法可以在操作系统级别设置边距。

默认情况下,左、右、上、下四个都设置为1。

最佳答案

I'm using the Java Printing API, but have problems setting print margins.

...

Solution

I had to provide additional print attributes to override the default print margins, MediaPrintableArea.

Most printers cannot print on the entire surface of the media, due to printer hardware limitations.

MediaPrintableArea can be used to query the acceptable values for a supposed print job, and to request an area within the constraints of the printable area to be used in a print job.

HashPrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
attr.add(new MediaPrintableArea(0f, 0f, w/72f, h/72f, MediaPrintableArea.INCH));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(ps);
job.setPrintable(this);
job.setJobName(jobName);
job.print(attr);
j.setVisible(false);
j.dispose();

The key was to provide the attributes along with the print() command.

来源Help with print margins

关于java - 如何在java中设置打印机边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25283110/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com