我使用以下代码以pdf格式打印和保存数据,但它不起作用。那么,以pdf格式打印netbeans中jframe信息的代码是什么。
PrinterJob job = PrinterJob.getPrinterJob();
job.setJobName("jPanel2");
job.setPrintable (new Printable()
{
public int print(Graphics pg, PageFormat pf, int pageNum)
{
if (pageNum > 0)
{
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) pg;
g2.translate(pf.getImageableX(), pf.getImageableY());
jPanel2.paint(g2);
return Printable.PAGE_EXISTS;
}
});
boolean ok = job.printDialog();
if (ok)
{
try
{
job.print();
}
catch (PrinterException ex)
{
}
}