0

我想用横向打印打印 jpanel。我尝试了以下代码,但文本打印不正确。如果我删除pf.setOrientation(PageFormat.LANDSCAPE);了,那么它将在纵向页面中打印。横向打印的程序是什么?

if(arg0.getActionCommand().equals("print")){
            final PrinterJob job = PrinterJob.getPrinterJob();
             job.setJobName("Printing");

             job.setPrintable (new Printable() {    
                public int print(Graphics pg, PageFormat pf, int pageNum){
                    if (pageNum > 0){
                    return Printable.NO_SUCH_PAGE;
                    }
                    pf.setOrientation(PageFormat.LANDSCAPE);
                    Graphics2D g2 = (Graphics2D) pg;                
                    g2.translate(pf.getImageableX(), pf.getImageableY());
                    panel01.printAll(g2);
                    return Printable.PAGE_EXISTS;
                }
             });
             boolean ok = job.printDialog();
             if (ok) {
                 try { 
                      job.print();
                 } catch (PrinterException ex) {

                 }
        }
4

1 回答 1

1

使用job.setPageable(yourImplementationOfPageableHere). 然后你可以实现

PageFormat getPageFormat(int pageIndex) 

接口的方法为每个页面返回所需的页面格式。

于 2013-09-03T12:50:32.033 回答