This is started from nowhere today. I have made my first PDF with Migradoc without major issues and thus I was ready to widely employ the library for the other PDF required by my application following the same code pattern explained in your examples.
Now everytime I try to add a Table instance to the LastSection of a document I get this error at the PdfRenderer.RenderDocument call.
Code:
private void AddData(Document document, int bookmarkCounter)
{
Section section = document.AddSection();
section.PageSetup.OddAndEvenPagesHeaderFooter = true;
section.PageSetup.StartingNumber = 1;
section.PageSetup.HeaderDistance = new Unit(1.0, UnitType.Centimeter);
section.PageSetup.FooterDistance = new Unit(0.5, UnitType.Centimeter);
HeaderFooter header = section.Headers.Primary;
header.AddParagraph("\t.......");
header = section.Headers.EvenPage;
header.AddParagraph("...........");
Paragraph paragraph = new Paragraph();
paragraph.AddTab();
paragraph.AddPageField();
section.Footers.Primary.Add(paragraph);
section.Footers.EvenPage.Add(paragraph.Clone());
Paragraph paragraph = document.LastSection.AddParagraph("............", "Heading2");
// Removed but doesn't make a difference
// paragraph.AddBookmark("bkm" + bookmarkCounter.ToString("D3"));
Table table = new Table();
table.Borders.Width = 0.0;
Column column = table.AddColumn(Unit.FromCentimeter(5));
column.Format.Alignment = ParagraphAlignment.Left;
table.AddColumn(Unit.FromCentimeter(12));
AddRowToTable(table, "LABEL", "VALUE");
document.LastSection.Add(table);
}
private void AddRowToTable(Table table, string textCol1, string textCol2)
{
Row row = table.AddRow();
Cell cell = row.Cells[0];
cell.AddParagraph(textCol1);
cell = row.Cells[1];
cell.AddParagraph(textCol2);
return row;
}
The following is the StackTrace at the exception
Code:
in System.Collections.Generic.Dictionary`2.get_Item(TKey key)
in MigraDoc.Rendering.TableRenderer.Format(Area area, FormatInfo previousFormatInfo)
in MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel)
in MigraDoc.Rendering.FormattedDocument.Format(XGraphics gfx)
in MigraDoc.Rendering.DocumentRenderer.PrepareDocument()
in MigraDoc.Rendering.PdfDocumentRenderer.PrepareDocumentRenderer(Boolean prepareCompletely)
in MigraDoc.Rendering.PdfDocumentRenderer.PrepareRenderPages()
in MigraDoc.Rendering.PdfDocumentRenderer.RenderDocument()
in NE.CRParser.StampaFlussoCR.Esecuzione(Boolean anteprima, List`1 dati, Flussi flussi) in H:\_Sviluppo\Antiriciclaggio\CRParser\CRPDFWriter\StampaFlussoCR.cs:riga 47
in NE.CRParser.PDFWriter.cmdPDF_Click(Object sender, EventArgs e) in H:\_Sviluppo\Antiriciclaggio\CRParser\CRPDFWriter\PDFWriter.cs:riga 117
Thanks for your attention
Steve
NB. I am using Migradoc 1.50.4000 and PDFSharp 1.50.4000