在netbeans中以pdf格式保存JFrame

时间:2015-01-21 14:52:25

标签: java pdf netbeans

我使用以下代码以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)
    {
    }
}

0 个答案:

没有答案