在Mac上的Java A3打印出来的A4规模 [英] Java A3 printing on Macs coming out at A4 scale

查看:559
本文介绍了在Mac上的Java A3打印出来的A4规模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个似乎是专门针对Mac电脑的一个奇怪的问题。我有一个打印AWT绘图表面的纸张的A3纸的内容编。在Linux和Windows机器的输出就可以了。从Mac打印我得到同样的preSET参数相同的对话框,如预期的一纸纸A3打印机打印,但由于某些原因对图像进行缩放以适合A4纸面积。下面是code的相关章节:

I have an odd problem that seems to be specific to Mac computers. I have a prog that prints the content of an AWT drawing surface to an A3 sheet of paper. On Linux and windows machines the output is OK. Printing from a Mac I get the same dialog with the same preset parameters, the printer prints on an A3 sheet of paper as expected, but for some reason the image is scaled to fit an A4 area. Below are the relevant sections of code:

public void print() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    PageFormat format = new PageFormat();
    format.setOrientation(PageFormat.LANDSCAPE);

    double margin = 18; // quarter inch
    double m2 = margin * 2;
    Paper paper = format.getPaper();
    paper.setSize(16.54 * 72, 11.69 * 72); // A3 Landscape
    paper.setImageableArea(margin, margin,  paper.getWidth()-m2, paper.getHeight()-m2);
    format.setPaper(paper);
    printJob.setPrintable(this, format);

    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    attributes.add(MediaSizeName.ISO_A3);
    attributes.add(OrientationRequested.LANDSCAPE);
    attributes.add(new MediaPrintableArea((int)margin, (int)margin,
            (int)(paper.getWidth()-m2), (int)(paper.getHeight()-m2),
            MediaPrintableArea.INCH));

    if(printJob.printDialog(attributes) ){
      try {
        printJob.print(attributes);
      } catch(PrinterException pe) {
        pe.printStackTrace();
      }
    }
  }

  public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    if (pageIndex > 0) {
      return(NO_SUCH_PAGE);
    } else {
      Graphics2D g2d = (Graphics2D)g;
      g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
      if(this.componentToBePrinted instanceof PlannerView){
          setScale(g2d);
      }
      disableDoubleBuffering(componentToBePrinted);
      componentToBePrinted.paint(g2d);
      enableDoubleBuffering(componentToBePrinted);
      return(PAGE_EXISTS);
    }
  }

  public void setScale(Graphics2D g2d){
      PlannerView planner = (PlannerView)this.componentToBePrinted;
      planner.resetZoom();
      double scale = 1.0 / planner.getRowLength();
      scale *= 4.0; 
      g2d.scale(scale, scale);
  }

有谁知道这可能是造成这?

Does anyone know what could be causing this?

干杯。

推荐答案

尝试调用

PageFormat newFormat =printJob.pageDialog(format);

在打印前,打印机可以修改的边缘。

before printing, the printer may modify the margins.

至少需要在调试器看看,看看它会变成。

At least take a look in the debugger and see what it turns into.

另外请注意,在Macintosh本地打印坐标系景观反转。

Also note that the Macintosh native printing coordinate systems for landscape is inverted.

因此​​,也许有REVERSE_LANDSCAPE,而不是景观试试吧(而且可能翻转,但可能不会得到转换列表)

So maybe try it with REVERSE_LANDSCAPE instead of LANDSCAPE ( and it might be flipped, but may not get list in translation)

这篇关于在Mac上的Java A3打印出来的A4规模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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