title: csv to pdf file in java
body: <p>I am trying to get a <code>csv</code> file parsed into a <code>pdf</code>. What I have so far is attached below. </p>
  
  <p>My problem is with this code the file that ends up in the pdf cuts off at the first line of the csv file and I cant figure out why. [<em>examples attached</em>] Essentially I would like a pdf version of the csv file nothing manipulated. I am sure its an issue with how i am adding data to the itext pdf but I cant really find another way of forwarding an array to the pdf file. Any ideas on fixing the code or something simpler?  </p>
  
  <pre><code>public static void main(String[] args) throws IOException, DocumentException {
      @SuppressWarnings("resource")
      CSVReader reader = new CSVReader(new FileReader("data1.csv") ,'\'');
      String [] nextLine;
      while ((nextLine = reader.readNext()) != null) {
              // nextLine[] is an array of values from the line
              System.out.println(nextLine[0]);
              String test; 
              test = nextLine[0];
  
              // step 1
              Document document = new Document();
  
              // step 2
              PdfWriter.getInstance(document, new FileOutputStream("Test.pdf"));
  
              // step 3
              document.open();
  
              // step 4
              PdfPTable arrayTable3 = new PdfPTable(1); 
              arrayTable3.setHorizontalAlignment(Element.ALIGN_LEFT); 
  
              Phrase phrase1 = new Phrase(nextLine[0]); 
              PdfPCell arrayDetailsCell3 = new PdfPCell(); 
  
              arrayDetailsCell3.addElement(phrase1); 
  
              // Add the cell to the table 
              arrayTable3.addCell(arrayDetailsCell3); 
  
              // Add table to the document 
              document.add(arrayTable3); 
  
              // step 5
              document.close();
      }
  }
  </code></pre>
  
  <p>CSV file: <a href="http://dl.dropbox.com/u/11365830/data1.csv" rel="nofollow">http://dl.dropbox.com/u/11365830/data1.csv</a> <br/>
  PDF file: <a href="http://dl.dropbox.com/u/11365830/Test.pdf" rel="nofollow">http://dl.dropbox.com/u/11365830/Test.pdf</a></p>