我想用横向打印打印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) {
}
}
答案 0 :(得分:1)
使用job.setPageable(yourImplementationOfPageableHere)
。然后你可以实现
PageFormat getPageFormat(int pageIndex)
接口的方法,为每个页面返回所需的页面格式。