Trying to run simple example(with slight modifications) of creating Pdf document using iTextSharp Library. Getting exception "Dimensions of a Cell can't be calculated."
Line "cell.Left = 10f;" in valueCell function, throws exception "Dimensions of a Cell can't be calculated.". Commenting this line everything works fine. What could be the reason for this exception?
private static Cell valueCell(string content)
{
var cell = new Cell(content);
cell.BackgroundColor = new iTextSharp.text.Color(SystemColor.AliceBlue);
cell.Left = 10f;
return cell;
}
private static void TestPdfExport_iTextSharp()
{
var filePath = string.Format("D:\\Temp\\GeneratedPdf_iTs_{0}.pdf", DateTime.Now.ToString("yy-MM-dd hh mm ss"));
// step 1: creation of a document-object
Document document = new Document();
try
{
// step 2: we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter writer = PdfWriter.GetInstance(document,
new FileStream(filePath, FileMode.Create));
// step 3: we open the document
document.Open();
// step 4: we create a table and add it to the document
Table aTable = new Table(2, 2); // 2 rows, 2 columns
aTable.DefaultCell.Left = 10f;
aTable.DefaultCell.Bottom = 10f;
aTable.AddCell(valueCell("Metric"));
aTable.AddCell(valueCell("Current Value"));
aTable.AddCell(valueCell("Leverage"));
aTable.AddCell(valueCell("3.2"));
document.Add(aTable);
}
catch (DocumentException de)
{
}
// step 5: we close the document
document.Close();
}