2010-09-22 67 views
3

我有一个奇怪的问题,似乎是特定于Mac电脑。我有一个编程,将AWT绘图表面的内容打印到A3纸上。在Linux和Windows机器上,输出是OK的。从Mac打印我使用相同的预设参数获得相同的对话框,打印机按预期在A3纸张上打印,但出于某种原因,图像被缩放以适合A4区域。以下是相关的代码部分:以A4尺度出现在Mac上的Java A3打印

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

有没有人知道可能是什么原因造成的?

干杯。

+0

可能相关:https://issues.apache.org/jira/browse/PDFBOX-3453 – tresf 2016-08-02 20:45:32

回答

1

尝试调用

PageFormat newFormat =printJob.pageDialog(format); 

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

至少看看调试器,看看它变成了什么。

另请注意,用于横向的Macintosh原生打印坐标系是倒置的。

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

0

处理setImageableArea(),改变价值观和尝试。同时为mac应用reverse_landscape。 并设置A3大小:1190 & 842不是十进制值。