For some page configuration
NullReferenceException (Object reference not set to an instance of an object.)
occurs in
Code:
MigraDoc.Rendering.TableRenderer.CreateNextBottomBorderPosition()
MigraDoc.Rendering.TableRenderer.CreateBottomBorderMap()
MigraDoc.Rendering.TableRenderer.InitFormat(Area area, FormatInfo previousFormatInfo)
MigraDoc.Rendering.TableRenderer.Format(Area area, FormatInfo previousFormatInfo)
MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel)
MigraDoc.Rendering.FormattedDocument.Format(XGraphics gfx)
MigraDoc.Rendering.DocumentRenderer.PrepareDocument()
in code like this
Code:
document = CreateDocument(... some params ...);
MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(document);
docRenderer.PrepareDocument();
I was able to reproduce this bug in console C# application with "PDFSharp + MigraDoc" installed via NuGet
Code:
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using PdfSharp.Pdf;
using System.Diagnostics;
namespace PDFSharpTest
{
class Program
{
static void Main(string[] args)
{
var doc = new Document();
Section section = doc.AddSection();
var table = section.AddTable();
table.Borders.Width = 0.25;
table.AddColumn();
table.AddColumn();
table.AddColumn();
Row row;
row = table.AddRow(); // row 1
row.Cells[0].AddParagraph("Item 11");
row.Cells[0].MergeDown = 5;
row.Cells[1].AddParagraph("Item 21");
row.Cells[1].MergeDown = 1;
row.Cells[2].AddParagraph("Item 31");
row.Cells[2].MergeDown = 2;
row = table.AddRow(); // row 2
row = table.AddRow(); // row 3
row.Cells[1].AddParagraph("Item 23");
row.Cells[1].MergeDown = 1;
row = table.AddRow(); // row 4
row.Cells[2].AddParagraph("Item 34");
row.Cells[2].MergeDown = 2;
row = table.AddRow(); // row 5
row.Cells[1].AddParagraph("Item 25");
row.Cells[1].MergeDown = 1;
row = table.AddRow(); // row 6
var pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);
pdfRenderer.Document = doc;
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save("Result.pdf");
// ...and start a viewer.
Process.Start("Result.pdf");
}
}
}
Code:
An unhandled exception of type 'System.NullReferenceException' occurred in MigraDoc.Rendering.dll
Additional information: Object reference not set to an instance of an object.