title: How to change cell color in iText Java
body: <p>i am new to to using itext and i need help on i can change format of cells heading 1 and heading 2 , i want it to have a different color background and font to be bold. </p>
  
  <p>the code below simply makes a table with a title.
  <a href="https://i.stack.imgur.com/JJzO8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JJzO8.png" alt="this is the current output on pdf"></a></p>
  
  <pre><code>import com.itextpdf.text.BaseColor;
  import com.itextpdf.text.Document;
  import com.itextpdf.text.Element;
  import com.itextpdf.text.FontFactory;
  import com.itextpdf.text.Image;
  import com.itextpdf.text.Paragraph;
  import com.itextpdf.text.Rectangle;
  import com.itextpdf.text.pdf.PdfContentByte;
  import com.itextpdf.text.pdf.PdfPCell;
  import com.itextpdf.text.pdf.PdfPTable;
  import com.itextpdf.text.pdf.PdfPageEventHelper;
  import com.itextpdf.text.pdf.PdfWriter;
  import java.awt.Font;
  import java.io.FileOutputStream;
  import java.util.Date;
  
  public class Pdfcreate{
  
      public static void main(String[] args) {
          //PdfPrint pdf = new PdfPrint();
          try{
              Document document = new Document();
              PdfWriter.getInstance(document , new FileOutputStream("test.pdf")); // name of pdf
              document.open();
  
              PdfPTable table = new PdfPTable(2); 
              PdfPCell cell = new PdfPCell(new Paragraph("Title")); 
              cell.setColspan(2); // colspan 
              cell.setHorizontalAlignment(Element.ALIGN_CENTER); 
              cell.setBackgroundColor(BaseColor.GREEN); 
              table.addCell(cell);  
  
              table.addCell("heaading 1"); // how to change cell to have different font and bold and background color
              table.addCell("heading 2"); // how to change cell to have different font and bold and background color
              table.addCell("item3");
              table.addCell("item4");
              document.add(table);
  
              System.out.println("PRINTED");
              document.close();
          }catch(Exception e){
              System.out.println(e);
          }       
      }
  
  
  
  }
  </code></pre>