本文介绍了缩小边距-Java打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在纸上打印:

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).

推荐答案

美国信函尺寸的纸张尺寸为8½x 11英寸.每英寸72点,即612 x 792.

US Letter sized paper, for example, measures 8½ x 11 inches. At 72 dots per inch, that's 612 x 792.

在选择了该尺寸纸张的典型打印机上, PageFormat 对象报告以下区域.

On a typical printer having paper of that size selected, the PageFormat object reports the following area.

System.out.println(pf.getImageableX() + " " + pf.getImageableY()
    + " " + pf.getImageableWidth() + " " + pf.getImageableHeight());

18.0 18.0 576.0 734.0
18.0 18.0 576.0 734.0

全出血的消费者打印机很少,因此可售区域较小超出了纸张的物理尺寸所建议的范围.实际上,打印机无法在无法打印的地方放置墨水.

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.

这篇关于缩小边距-Java打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:25