title: How to save scrollable jpanel into pdf or any format
body: <p>I have a jpanel within jscrollpane, I want to export all the contents of <code>jpanel</code> (which include some <code>label</code>,<code>textarea</code>) to pdf format. currently I am using this code on a <code>jbutton</code>:</p>
  
  <pre><code>Document document = new Document(PageSize.A4.rotate(),50,50,50,50);
  try {
  PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\Admin\\Desktop\\test1.pdf"));
  document.open();
  PdfContentByte contentByte = writer.getDirectContent();
  //jp is the jpanel
  PdfTemplate template = contentByte.createTemplate(jp.getWidth(), jp.getHeight());
  Graphics2D g2 = template.createGraphics(jp.getWidth(),jp.getHeight());
  g2.scale(0.8, 1);
          jp.printAll(g2); // also tried with jp.paint(g2), same result
          g2.dispose();
  
          //document.close();
  contentByte.addTemplate(template, 5, 60);
  } catch (Exception e) {
  e.printStackTrace();
  }
  finally{
  if(document.isOpen()){
      document.close();
  }
  
  }
  </code></pre>
  
  <p><strong>Output:</strong> I am getting the lower portion of <code>jpanel</code> in pdf...(I made sanpshot of the jpanel but my reputation does not allow to post images),the upper portion is getting discarded.I think the last portion is getting exported as single page is used. first portion is over written(this is only a guess!)
  In order to view the whole <code>jpanel</code> we need to scroll... how to export the whole panel(from top to bottom) to pdf into multiple pages as height of jpanel is more than A4 page.please do help. thanks in advance.</p>
  
  <p><strong>Note:</strong> i am using netbeans to develop my gui and <code>itextpdf-5.4.1</code>.I am a beginner in java programming.</p>