我想用横向打印打印 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) {
}
}