We are trying out using a PdfTable in our document. When we assign the StructureElement to the PdfTable, we get a NullReferenceException. When we do not assign the StructureElement, the table works, but the table structure is (of course) not embedded in the document structure.
Here is a part of the code that triggers the error:
- Code: Select all
var x = 2.0f;
var y = 2.0f
var pageStructure = document.DocumentStructure.AppendChildElement(PdfStandardStructTypes.Part);
var sectionStructure = pageStructure.AppendChildElement(PdfStandardStructTypes.Section);
var tableStructure = sectionStructure.AppendChildElement(PdfStandardStructTypes.Table);
String[] data = {
Key;Description;Value",
"1;First description;First value"
};
String[][] dataSource = new String[data.Length][];
for (int j = 0; j < data.Length; j++)
{
dataSource[j] = data[j].Split(';');
}
var pdfTable = new PdfTable();
pdfTable.DataSource = dataSource;
pdfTable.StructureElement = tableStructure;
pdfTable.Columns.Add(new PdfColumn("Key"));
pdfTable.Columns.Add(new PdfColumn("Description"));
pdfTable.Columns.Add(new PdfColumn("Value"));
pdfTable.Draw(page, x, y);
This is the error:
System.NullReferenceException: Object reference not set to an instance of an object.
at spr꙲.悽()
at spr꙲.忾(Int32 A_0, PdfLayoutParams A_1, Boolean A_2)
at spr꙲.叁(PdfLayoutParams A_0)
at spr㧁.悽(PdfLayoutParams A_0)
at Spire.Pdf.Tables.PdfTable.Layout(PdfLayoutParams param)
at Spire.Pdf.Graphics.PdfLayoutWidget.Draw(PdfPageBase page, RectangleF layoutRectangle, PdfTextLayout format)
at Spire.Pdf.Graphics.PdfLayoutWidget.Draw(PdfPageBase page, Single x, Single y, PdfTextLayout format)
at Spire.Pdf.Graphics.PdfLayoutWidget.Draw(PdfPageBase page, Single x, Single y)
at ... (own code)
Can you tell us if we are doing something wrong here?