2010-09-22 35 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不是十進制值。

相關問題