title: How to display multiple values one below another in single column using itext and java struts2
body: <p>I am able to create pdf but what I need is I want to display values which are being fetched in array and getting displayed over there in single column one below the other.I am able to print those values as well but not able to set those values one below another .I am stuck in this badly .So can anyone help me to solve this problem.Below is my code for generating pdf followed  by image of how does it looks like.  </p>
  
  <pre><code>public String execute() throws Exception {
          // TODO Auto-generated method stub
          HttpServletResponse response = ServletActionContext.getResponse();
          float temp = Integer
                  .parseInt(invoiceVar.getNetAmount().split("\\.")[0])
                  + Integer.parseInt(invoiceVar.getServiceTax().split("\\.")[0])
                  + Integer.parseInt(invoiceVar.getSbcTax().split("\\.")[0]);
          // Double d = new Double(temp);
          long n = (long) temp;
          System.out.println(n);
          float[] columnWidths = { 2, 5, 5, 5 };
          String docname = "invoice"
                  + invoiceVar.getCompanyName().substring(0, 2);
          // + invoiceVar.getInvoiceNumber().substring(0, 2);
          Document document = new Document(PageSize.A4, 50, 50, 50, 50);
          Paragraph addLicense = null;
  
          Paragraph someSectionText = new Paragraph(
                  "Invoice: "
                          + invoiceVar.getInvoiceNumber()
                          + "                                                                 Date: "
                          + invoiceVar.getInvoiceEventsDate() + "\n\n");
          Paragraph someSectionText2 = new Paragraph("To,");
          Paragraph someSectionText3 = new Paragraph("          "
                  + invoiceVar.getCompanyName());
  
          System.out.println("Into Action Class...");
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
  
          PdfWriter writer = PdfWriter.getInstance(document, baos);
          PdfPTable table = new PdfPTable(4);
          table.setSpacingBefore(25);
          table.setWidths(columnWidths);
          table.setWidthPercentage(100);
          table.setSpacingAfter(25);
  
          PdfPCell c1 = new PdfPCell(new Phrase("Details "));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          table.addCell(c1);
  
          c1 = new PdfPCell(new Phrase(" "));
          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("Amount Details"));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          table.addCell(c1);
          table.setHeaderRows(1);
  
          table.addCell("\n ");
          table.addCell("\n");
          for (int i = 0; i &lt; invoiceVar.getLicName().length; i++) {
              addLicense=new Paragraph(invoiceVar.getLicName()[i]);
              table.addCell(addLicense);
                  }
  
          table.addCell("\n");
  
          table.addCell("Pan Number: ");
          table.addCell(invoiceVar.getPanNumber());
          table.addCell("Net Amount");
          table.addCell(invoiceVar.getNetAmount());
  
          table.addCell("Service Tax Number: ");
          table.addCell(invoiceVar.getServiceTaxNumber());
          table.addCell("Service Tax @ 0.14 %");
          table.addCell(invoiceVar.getServiceTax());
          table.addCell("");
          table.addCell("");
          table.addCell("Sbc Tax @0.50%");
          table.addCell(invoiceVar.getSbcTax());
          table.addCell("");
          table.addCell("");
          table.addCell("Total Amount");
          table.addCell(invoiceVar.getInvoiceTotalAmount());
  
          Paragraph amountPara = new Paragraph("\nTotal amount in words is :    "
                  + Conversion.evaluate(n) + " Only.");
          Paragraph someSectionText4 = new Paragraph(
                  "\nReceiver's Signature:                                                                        Proprietor: ");
  
          document.open();
          document.add(someSectionText);
          document.add(someSectionText2);
          document.add(someSectionText3);
          document.add(table);
          document.add(amountPara);
          document.add(someSectionText4);
          document.close();
          System.out.println(invoiceVar.getEventName());
          Database database = new Database();
          Connection con = database.Get_Connection();
  
          PreparedStatement ps = con
                  .prepareStatement("UPDATE PDFSTATUS SET I_PDF=? WHERE EVENT_NAME=? AND COMPANY_NAME=?");
          ps.setString(1, "one");
          ps.setString(2, invoiceVar.getInvoiceNumber());
          ps.setString(3, invoiceVar.getCompanyName());
          ps.executeUpdate();
          System.out.println("I_PDF RECORDS UPDATED !!");
          ServletOutputStream outputStream = response.getOutputStream();
          baos.writeTo(outputStream);
          response.setHeader("Content-Disposition",
                  "attachment; filename=\"InvoicePDF.pdf\"");
          response.setContentType("application/pdf");
          outputStream.flush();
          outputStream.close();
  
          return "success";
      }
  
  }
  </code></pre>
  
  <p>Here <code>invoiceVar.getLicName()[i]</code> displays all the values stored in the array.<a href="https://i.stack.imgur.com/AN14V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AN14V.png" alt="Error"></a>
  Here <code>Dcp Office</code>, <code>Liquor License</code> and <code>Rangabhoomi</code> are values which are getting displayed from that above array but they are getting displayed in new cells but I want that values in same column one below another.</p>