title: iTextsharp, PdfPCell.VerticalAlignment and PdfPCell.HorizontalAlignment
body: <p>Im trying to figure out how to get my text inside a PdfPCell to show in the middle. I have tried many different options, like:</p>
  
  <pre>
  myCell.VerticalAlignment = Element.ALIGN_MIDDLE;
  myCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
  myCell.VerticalAlignment = Rectangle.ALIGN_MIDDLE;
  </pre>
  
  <p>None of that works for me. VerticalAlignment takes an int, so I tried to make a loop, to see if i could find the right number, but everything just get left bottom align..</p>
  
  <pre><code>   Document myDocument = new Document(PageSize.A4);
  
     PdfWriter myPdfWriter = PdfWriter.GetInstance(myDocument, new FileStream(strPDFFilePath, FileMode.Create));
     myDocument.Open();
  
     myDocument.NewPage();
  
     PdfContentByte myPdfContentByte = myPdfWriter.DirectContent;
  
     PdfPCell myCell;
     Paragraph myParagraph;
  
     PdfPTable myTable = new PdfPTable(4);
     myTable.WidthPercentage = 100;
     myTable.SetWidths(new int[4] { 25, 25, 25, 25 });
  
     myTable.DefaultCell.BorderWidth = 1;
     myTable.DefaultCell.BorderColor = BaseColor.RED;                
  
     for (int i = -100; i &lt; 100; i++)
     {
         myParagraph = new Paragraph(String.Format("Alignment: {0}", i));
         myParagraph.Font.SetFamily("Verdana");
         myParagraph.Font.SetColor(72, 72, 72);
         myParagraph.Font.Size = 11;
  
         myCell = new PdfPCell();
         myCell.AddElement(myParagraph);
         myCell.HorizontalAlignment = i;
         myCell.VerticalAlignment = i;                    
         myTable.AddCell(myCell);
     }
  
     myDocument.Add(myTable);
     myDocument.Add(new Chunk(String.Empty));
     myDocument.Close();
  </code></pre>