Hi im getting an empty PDF using ItextSharp C#, only is empty before the Header section, i know this problem occurs when the colspan of columns doesnt fill the table, but my tblData have (2) columns and cells each one have 1 colspan, sorry for my bad english.
static void Main(string[] args)
{
DataTable dt = new DataTable();
dt = GetData();
Document doc = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(@"D:\prueba.pdf", FileMode.Create));
doc.Open();
iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 9, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
iTextSharp.text.Font CompanyFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
iTextSharp.text.Font HeaderGrowerFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
//Header ---------------------------------------------------------------
PdfPTable tblHeader = new PdfPTable(3);
tblHeader.WidthPercentage = 100;
PdfPCell Date = new PdfPCell(new Phrase("Date: 09/28/17", _standardFont));
Date.BorderWidth = 0;
Date.HorizontalAlignment = Element.ALIGN_LEFT;
Date.Colspan = 1;
Date.FixedHeight = 40f;
PdfPCell CompanyName = new PdfPCell(new Phrase("T H E Q U E E N ' S F L O W E R S", CompanyFont));
CompanyName.BorderWidth = 0;
CompanyName.HorizontalAlignment = Element.ALIGN_CENTER;
CompanyName.Colspan = 1;
CompanyName.FixedHeight = 40f;
PdfPCell PageNumber = new PdfPCell(new Phrase("Page 1", _standardFont));
PageNumber.HorizontalAlignment = Element.ALIGN_RIGHT;
PageNumber.BorderWidth = 0;
PageNumber.Colspan = 1;
PageNumber.FixedHeight = 40f;
PdfPCell Time = new PdfPCell(new Phrase("Time: 06 53 32", _standardFont));
Time.BorderWidth = 0;
Time.Colspan = 1;
Time.FixedHeight = 40f;
PdfPCell Text = new PdfPCell(new Phrase("LARRIGLO", _standardFont));
Text.BorderWidth = 0;
Text.Colspan = 2;
Text.HorizontalAlignment = Element.ALIGN_RIGHT;
Text.FixedHeight = 40f;
PdfPCell HeaderGrower = new PdfPCell(new Phrase("STARTING POSITION BY GROWER", HeaderGrowerFont));
HeaderGrower.BorderWidth = 0;
HeaderGrower.Colspan = 3;
HeaderGrower.HorizontalAlignment = Element.ALIGN_CENTER;
HeaderGrower.FixedHeight = 40f;
HeaderGrower.BorderWidthBottom = 0.75f;
tblHeader.AddCell(Date);
tblHeader.AddCell(CompanyName);
tblHeader.AddCell(PageNumber);
tblHeader.AddCell(Time);
tblHeader.AddCell(Text);
tblHeader.AddCell(HeaderGrower);
doc.Add(tblHeader);
//Data ---------------------------------------------------------------
PdfPTable tblData = new PdfPTable(2);
tblData.WidthPercentage = 100;
PdfPCell WhitheSpace = new PdfPCell(new Phrase("", _standardFont));
WhitheSpace.BorderWidth = 0;
WhitheSpace.Colspan = 1;
WhitheSpace.FixedHeight = 10f;
PdfPCell Awb = new PdfPCell(new Phrase("AWB: 2716 AAO: 554 DATE: 09/28/2017", _standardFont));
Awb.BorderWidth = 0;
Awb.Colspan = 1;
Awb.FixedHeight = 10f;
tblData.AddCell(WhitheSpace);
tblData.AddCell(Awb);
doc.Add(tblData);
doc.Close();
writer.Close();
}
Header section is fine, but Data section is empty and i dont know what im doing wrong.
Result:
