缩小边距 - Java 打印
我正在使用此代码在纸张上打印:
//Overriden from printable interface
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex != 0) {
return Printable.NO_SUCH_PAGE;
}
Paper a4 = new Paper();
a4.setImageableArea(0, 0, a4.getWidth(), a4.getHeight());
pageFormat.setPaper(a4);
pageFormat.setOrientation(PageFormat.PORTRAIT);
Graphics2D g2d = (Graphics2D)g;
//g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
this.setDoubleBuffered(false);
panel.print(g2d);
JOptionPane.showMessageDialog(null, new ImageIcon(image));
this.setDoubleBuffered(true);
return Printable.PAGE_EXISTS;
}
我正在尝试以编程方式减小页边距的大小。无论我做什么,图像的侧面似乎总是缺少一大块(除非我从打印对话框中删除边距 - 但正如我所说,我想以编程方式删除它们以自动化整个过程)。
I am using this code to print on paper:
//Overriden from printable interface
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex != 0) {
return Printable.NO_SUCH_PAGE;
}
Paper a4 = new Paper();
a4.setImageableArea(0, 0, a4.getWidth(), a4.getHeight());
pageFormat.setPaper(a4);
pageFormat.setOrientation(PageFormat.PORTRAIT);
Graphics2D g2d = (Graphics2D)g;
//g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
this.setDoubleBuffered(false);
panel.print(g2d);
JOptionPane.showMessageDialog(null, new ImageIcon(image));
this.setDoubleBuffered(true);
return Printable.PAGE_EXISTS;
}
I am trying to reduce the size of the margins programmatically. Whatever I do, there always seems to be a large missing chunk from the image's sides (Unless I remove the margins from the print dialog - but as I said, I want to remove them programatically to automate the whole process).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如,US Letter 尺寸的纸张尺寸为 8.5 x 11 英寸。每英寸 72 点,即 612 x 792。
在选择该尺寸纸张的典型打印机上,
PageFormat
对象报告以下区域。很少有消费者打印机是全出血,因此可打印区域小于纸张的区域物理尺寸会建议。实际上,打印机无法将墨水放在无法打印的地方。
US Letter sized paper, for example, measures 8½ x 11 inches. At 72 dots per inch, that's 612 x 792.
On a typical printer having paper of that size selected, the
PageFormat
object reports the following area.Few consumer printers are full-bleed, so the pritable area is smaller than the paper's physical dimensions would suggest. In effect, the printer can't put ink where it can't print.