读书人

打印机纸张方向有关问题

发布时间: 2012-01-29 21:39:32 作者: rapoo

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

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)
}

读书人网 >J2SE开发

热点推荐