如何在Java中设置打印机边距 [英] How to set printer margin in java

查看:203
本文介绍了如何在Java中设置打印机边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用Print API进行打印时-似乎无法控制边距!..请帮助我设置打印机边距,或者有任何方法可以在操作系统级别设置边距.

when trying to print using the Print API - the margins seem to be something not in our control!.. Please help me out to set printer margins or is there any way to set margins at Operating system level.

默认情况下,左,右,顶部和底部四个全部设置为1.

By default all the four left, right, top and bottom are set to 1.

推荐答案

我正在使用Java Printing API,但是在设置打印边距时遇到问题.

...

解决方案

我必须提供其他打印属性以覆盖默认设置打印边距, MediaPrintableArea .

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 可用于查询假定的打印作业的可接受值,并请求在可打印区域限制范围内的区域在打印作业中使用.

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();

关键是要提供属性以及 print()命令.

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

来源打印边距帮助

这篇关于如何在Java中设置打印机边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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