我有一個奇怪的問題,似乎是特定於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);
}
有沒有人知道可能是什麼原因造成的?
乾杯。
可能相關:https://issues.apache.org/jira/browse/PDFBOX-3453 – tresf 2016-08-02 20:45:32