title: How to write data from a TableView to the pdf?
body: <p>I tried a lot and got itext pdf code below. However I want to write data from a <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableView.html" rel="nofollow"><code>TableView</code></a> to the pdf. How can this be achieved ?</p>
  
  <pre><code>  public class Pdf2 {
      public static final String RESULT
          = "c:/temp/FirstPdf.pdf";
  
      /**
       * Main method.
       * @param    args    no arguments needed
       * @throws DocumentException 
       * @throws IOException
       */
      public static void main(String[] args)
          throws IOException, DocumentException {
          new Pdf2().createPdf(RESULT);
      }
  
      /**
       * Creates a PDF with information about the movies
       * @param    filename the name of the PDF file that will be created.
       * @throws    DocumentException 
       * @throws    IOException
       */
      public void createPdf(String filename)
          throws IOException, DocumentException {
          // step 1
          Document document = new Document();
          // step 2
          PdfWriter.getInstance(document, new FileOutputStream(filename));
          // step 3
          document.open();
          // step 4
          document.add(createFirstTable());
          // step 5
          document.close();
      }
  
      /**
       * Creates our first table
       * @return our first table
       */
      public static PdfPTable createFirstTable() {
          PdfPTable table = new PdfPTable(5);
  
      PdfPCell c1 = new PdfPCell(new Phrase("QTY"));
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell(c1);
  
      c1 = new PdfPCell(new Phrase("Item"));
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell(c1);
  
      c1 = new PdfPCell(new Phrase("Description"));
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell(c1);
       c1 = new PdfPCell(new Phrase("Unit Price"));
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell(c1);
      c1 = new PdfPCell(new Phrase("Total"));
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      table.addCell(c1);
      table.setHeaderRows(1);
  
      table.addCell("1");
      table.addCell("2");
      table.addCell("3");
       table.addCell("4");
      table.addCell("5");
  
  
          return table;
      }
  } 
  </code></pre>
  
  <p>This code above is itext pdf in java. Can I create a PDF with data from a javafx table inserted? Is there any other way to build pdf using JavaFX application?</p>