我正在打印 Legal 尺寸的纸张,当我在没有打开属性对话框的情况下打印它时,它可以正常打印,但是当我点击“属性”按钮确认页面类型时(无论我点击“确定”还是“取消”然后纸张imageableArea 在带有属性按钮的job.print(attributeSet)对话框中发生变化预期高度/宽度:612/1008实际高度/宽度:612/792(在 WPrinterJob.validatePaper() 中设置)打印有问题的页面这是我的代码,private void preparePageFormat(PageFormat pf){ Paper ppr = new Paper(); pf.setOrientation(PageFormat.LANDSCAPE); MediaSizeName msn = MediaSizeName.NA_LEGAL; MediaSize msz = MediaSize.getMediaSizeForName(msn); double inch = 72.0; width = msz.getX(MediaSize.INCH) * inch; height = msz.getY(MediaSize.INCH) * inch; ppr.setSize(a4Width, a4Height); ppr.setImageableArea(0, 0, a4Width, a4Height); pf.setPaper(ppr); }main(){ PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pageFormat = job.defaultPage(); preparePageFormat(pageFormat); job.setPrintable(previewPanel.getPrintable(), pageFormat); PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet(); attributeSet.add(OrientationRequested.LANDSCAPE); attributeSet.add(MediaSizeName.NA_LEGAL); if (job.printDialog(attributeSet)) { attributeSet.add(new MediaPrintableArea((float)pageFormat.getImageableX(),(float)pageFormat.getImageableY(), (float)pageFormat.getImageableWidth(),(float)pageFormat.getImageableHeight(),MediaPrintableArea.INCH)); job.print(attributeSet); }}
添加回答
举报
0/150
提交
取消