title: Itext Table Row , Table Header , Table cell
body: <p>I have a requirement to generated the PDF using itext in java</p>
  
  <p>Need to generate the table with 3 rows and 2 columns  , able to create the table.
  Country     Langugage
  USA         English
  Canada       French</p>
  
  <p>When I was trying to read the pdf VIA NVDA Desktop App , the table is not reading the cells properly , say when I want to focus the pointer on Canada , it should the Country - Canada </p>
  
  <p>Following is the code </p>
  
  <p>public class Test {</p>
  
  <pre><code>public static final String CSS = "tr { text-align: center; } th { background-color: lightgreen; padding: 3px; } td {background-color: lightblue;  padding: 3px; }";
  
  public static void main(String sunil[])
  {
      String pFileName = "Test.pdf";
      String pFilePath = "C:/local/home/dna/pushlive/" + pFileName;
      try {
  
          FileOutputStream baosPDF = new FileOutputStream(pFilePath);
          com.itextpdf.text.Rectangle pageSize = new com.itextpdf.text.Rectangle(1836, 2376);
          com.itextpdf.text.Document document =  new  com.itextpdf.text.Document(pageSize, 36, 36, 36, 36);
          PdfWriter writer = PdfWriter.getInstance(document, baosPDF);
          writer.setTagged(); 
  
          document.open();
  
          PdfPTable bannerTable = new PdfPTable(4);
  
  
          document.add(createFirstTable());
  
          document.close();
  
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (DocumentException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }   
  }
  
  public static PdfPTable createFirstTable() {
      // a table with three columns
      PdfPTable table = new PdfPTable(2);
  
      // the cell object
      PdfPCell cell;
      // we add a cell with colspan 3
      //create header cell for first row
      // now we add a cell with rowspan 2
  
  
      //add metadata for each cell in the body.
  
  
      // we add the four remaining cells with addCell()
      cell = new PdfPCell(new Phrase("Country"));
      table.addCell(cell);
      cell = new PdfPCell(new Phrase("Language"));
      table.addCell(cell);
  
      cell = new PdfPCell(new Phrase("USA")); 
      table.addCell(cell);
  
  
      cell = new PdfPCell(new Phrase("English")); 
      table.addCell(cell);
  
      cell = new PdfPCell(new Phrase("Canada"));  
      table.addCell(cell);
  
      cell = new PdfPCell(new Phrase("French"));  
      table.addCell(cell);
  
  
      //set header row for the table
      table.setHeaderRows(1);
  
      return table;
  }
  </code></pre>