日期:2014-05-20  浏览次数:20668 次

紧急求助,打印机纸张方向问题

HashPrintRequestAttributeSet   attributes;
PrinterJob   job   =   PrinterJob.getPrinterJob();
                                        job.setPageable(makeBook());
                                        if(job.printDialog(attributes)){
                                                try   {
                                                        job.print(attributes);
                                                }   catch   (PrinterException   ex)   {
                                                        ex.printStackTrace();
                                                }
                                        }

上面是我的打印部分代码
在打印对话框里面设置了纸张方向为横向,但打印结果仍然是纵向,
望高手指教。


------解决方案--------------------
try {
// fetch the printable
Printable printable = table.getPrintable(JTable.PrintMode.FIT_WIDTH,
new MessageFormat( "My Table "),
new MessageFormat( "Page - {0} "));

// fetch a PrinterJob
PrinterJob job = PrinterJob.getPrinterJob();

// set the Printable on the PrinterJob
job.setPrintable(printable);

// create an attribute set to store attributes from the print dialog
PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();

// display a print dialog and record whether or not the user cancels it
boolean printAccepted = job.printDialog(attr);

// if the user didn 't cancel the dialog
if (printAccepted) {
// do the printing (may need to handle PrinterException)
job.print(attr);
}
} finally {
// restore the original table state here (for example, restore selection)
}