PDFsharp icon indicating copy to clipboard operation
PDFsharp copied to clipboard

Setting the border color of a cell bricks SetEdge()

Open Neralem opened this issue 1 year ago • 0 comments

I can use Table.SetEdge(...) to modify the edges of a range of cells. This wont work if I set the border color of a cell.

Image

Take a look at this test code:

using System.Diagnostics;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;

Document document = new();

Section section = document.AddSection();

#region Table 1   -   All good
Table table = section.AddTable();
table.Borders.Visible = true;

table.AddColumn(Unit.FromCentimeter(2));
table.AddColumn(Unit.FromCentimeter(2));
table.AddColumn(Unit.FromCentimeter(2));
table.AddColumn(Unit.FromCentimeter(2));

table.AddRow()[0].AddParagraph("Test");
table.AddRow()[1].AddParagraph("Test");
table.AddRow()[2].AddParagraph("Test");
table.AddRow()[3].AddParagraph("Test");

table.SetEdge(0, 0, table.Columns.Count, table.Rows.Count, Edge.Interior, BorderStyle.None, 0);
#endregion

section.AddParagraph();

#region Table 2   -   If I color the table, SetEdge wont work properly
Table table2 = section.AddTable();
table2.Borders.Visible = true;

table2.AddColumn(Unit.FromCentimeter(2));
table2.AddColumn(Unit.FromCentimeter(2));
table2.AddColumn(Unit.FromCentimeter(2));
table2.AddColumn(Unit.FromCentimeter(2));

table2.AddRow()[0].AddParagraph("Test");
table2.AddRow()[1].AddParagraph("Test");
table2.AddRow()[2].AddParagraph("Test");
table2.AddRow()[3].AddParagraph("Test");


Color c = Color.Parse("#00FF00");

foreach (Row r in table2.Rows.OfType<Row>())
{
    foreach (Cell cell in r.Cells.OfType<Cell>())
    {
        cell.Borders.Color = c;
    }
}

table2.SetEdge(0, 0, table2.Columns.Count, table2.Rows.Count, Edge.Interior, BorderStyle.None, 0);
#endregion


PdfDocumentRenderer pdfRenderer = new() { Document = document };
pdfRenderer.RenderDocument();
using FileStream outputStream = new("output.pdf", FileMode.Create);
pdfRenderer.PdfDocument.Save(outputStream);

Expected Behavior

The second Table should have only outline borders like the first table but in green.

Actual Behavior

The second table has partially removed interior borders. Some in black and only some in green.

Steps to Reproduce the Behavior

  • Create a new .Net 8 Console App
  • Install nuget package PDFsharp-MigraDoc v6.1.1
  • Insert & run the given code
  • Take a look at output.pdf

Neralem avatar Jan 20 '25 15:01 Neralem