title: Save JFrame in pdf format in netbeans
body: <p>I am using the following codes to print and save the data in pdf format but it doesn't worked. So, what is the code to print the information of jframe in netbeans in pdf format.</p>
  
  <pre><code>PrinterJob job = PrinterJob.getPrinterJob();
  
  job.setJobName("jPanel2");
  
  job.setPrintable (new Printable()
  {
      public int print(Graphics pg, PageFormat pf, int pageNum)
      {
          if (pageNum &gt; 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)
      {
      }
  }
  </code></pre>