title: C# - iTextSharp The document has no pages
body: <p>I do have here the codes and I keep on getting the error message: The document has no pages. I also set the table widths and phrase, but still the error message occurred. I'm totally out now, I've tried searching some other cases however, they tried to fix their upon setting table widths. Is there anything that I miss. Any help would be appreciated. Thank you!</p>
  
  <pre><code>private void printPDF(object sender, EventArgs e)
      {            
  
              Document docu = new Document(PageSize.LETTER);
              PdfWriter writer = PdfWriter.GetInstance(docu, new FileStream("C:\\Report\\" + empno + ".pdf", FileMode.Create));
              Phrase phrase = null;
              PdfPCell cell = null;
              PdfPTable table = null;
              BaseColor color = null;
  
              docu.Open();
  
              //Header Table
              table = new PdfPTable(2);
              table.TotalWidth = 500f;
              table.LockedWidth = true;
              table.SetWidths(new float[] { 0.3f, 0.7f });
  
              //Company Name and Address
              phrase = new Phrase();
              phrase.Add(new Chunk("Company Name\n\n", FontFactory.GetFont("Arial", 16, iTextSharp.text.Font.BOLD, BaseColor.ORANGE)));
              phrase.Add(new Chunk("Company Address", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK)));
              cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
              cell.VerticalAlignment = PdfPCell.ALIGN_TOP;
              table.AddCell(cell);
  
              docu.Add(table);
              docu.Close();
      }
  private static PdfPCell PhraseCell(Phrase phrase, int align)
      {
          PdfPCell cell = new PdfPCell(phrase);
          cell.BorderColor = BaseColor.WHITE;
          cell.VerticalAlignment = PdfPCell.ALIGN_TOP;
          cell.HorizontalAlignment = align;
          cell.PaddingBottom = 2f;
          cell.PaddingTop = 0f;
          return cell;
      }
  </code></pre>