I have the following code
Code:
var document = new Document();
var section = document.AddSection();
section.PageSetup = document.DefaultPageSetup.Clone();
section.PageSetup.PageFormat = PageFormat.A4;
section.PageSetup.TopMargin = Unit.FromPoint(18);
section.PageSetup.LeftMargin = section.PageSetup.RightMargin = Unit.FromPoint(18);
section.PageSetup.BottomMargin = Unit.FromPoint(18);
Unit page_width = section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin;
Unit page_height = section.PageSetup.PageHeight - section.PageSetup.TopMargin - section.PageSetup.BottomMargin;
var table = section.AddTable();
table.Borders.Top.Style = BorderStyle.Single;
table.Borders.Top.Width = Unit.FromPoint(1);
table.Borders.Top.Color = Colors.Black;
table.Borders.Bottom = table.Borders.Top.Clone();
table.Borders.Left = table.Borders.Top.Clone();
table.Borders.Right = table.Borders.Top.Clone();
table.AddColumn(page_width / 8);
table.AddColumn(page_width / 8);
table.AddColumn(page_width / 8);
table.AddColumn(page_width / 8);
table.AddColumn(page_width / 8);
table.AddColumn(page_width / 8);
table.AddColumn(page_width / 8);
table.AddColumn(page_width / 8);
var row = table.AddRow();
row.Cells[0].MergeRight = 3;
row.Cells[0].AddParagraph("[0,0]");
row.Cells[4].AddParagraph("[0,4]");
row.Cells[4].MergeDown = 1;
row.Cells[4].VerticalAlignment = VerticalAlignment.Center;
row.Cells[5].AddParagraph("[0,5]");
row.Cells[5].MergeDown = 1;
row.Cells[5].VerticalAlignment = VerticalAlignment.Center;
row.Cells[6].AddParagraph("[0,6]");
row.Cells[6].MergeDown = 1;
row.Cells[6].VerticalAlignment = VerticalAlignment.Center;
row.Cells[7].AddParagraph("[0,7]");
//row.Cells[7].MergeDown = 1; // <-- Cant set to Merge Down = 1
row.Cells[7].VerticalAlignment = VerticalAlignment.Center;
row = table.AddRow();
row.Cells[0].MergeRight = 3;
row.Cells[0].MergeDown = 2;
row.Cells[0].AddParagraph("[1,0]");
row = table.AddRow();
row.Cells[4].AddParagraph("[2,4]");
row.Cells[4].MergeDown = 1;
row.Cells[4].VerticalAlignment = VerticalAlignment.Center;
row.Cells[5].AddParagraph("[2,5]");
row.Cells[5].MergeDown = 1;
row.Cells[5].MergeRight = 1; // <-- Cant set to MergeRight = 2
row.Cells[5].VerticalAlignment = VerticalAlignment.Center;
row = table.AddRow();
var pdf = new PdfDocument();
var renderer = new DocumentRenderer(document);
renderer.PrepareDocument();
for (int i = 1; i <= renderer.FormattedDocument!.PageCount; i++)
{
var page = pdf.AddPage();
var gfx = XGraphics.FromPdfPage(page);
renderer.RenderPage(gfx, i);
}
return pdf;
This produces the following:
But I need the [0,7] cell to merge down (just like the other [0,4], [0,5] & [0,6] cells)
And I need the [2,5] cell to merge right 2, currently I can only get it to merge right 1.
If i try and apply the MergeDown = 1 to the [0,7] cell or the MergeRight = 2 to the [2,5] cell I get the following exception:
Code:
InvalidOperationException: GetMinMergedCell: Unexpected problem #1
MigraDoc.Rendering.TableRenderer.GetMinMergedCell(int row)
MigraDoc.Rendering.TableRenderer.CreateNextBottomBorderPosition(ref int skipIndex, ref int lastBorderRow)
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, bool topLevel)
MigraDoc.Rendering.FormattedDocument.Format(XGraphics gfx)
MigraDoc.Rendering.DocumentRenderer.PrepareDocument()
PdfApp.DoSBuilderService.Render(Document document) in DoSBuilderService.cs
renderer.PrepareDocument();
PdfApp.DoSBuilderService.BuildAsync(CancellationToken cancellationToken) in DoSBuilderService.cs
using (var pdf = Render(document))
PdfApp.Controllers.HomeController.Index() in HomeController.cs
return await builder.BuildAsync();
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask<IActionResult> actionResultValueTask)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
I dont understand what I'm doing wrong, Can you please help.