Search code examples
c#migradoc

C# / MigraDoc - Bold table columns


I have a table with two columns and several rows and I need to make the first column bold. I tried using column.Format.Font.Bold = true; but it does not change the font to bold. If I use column.Format.Font.Colors = Colors.Blue; that works, but the bold style does not work. Can someone please advise what I am doing wrong? This is the code fragment that creates the table:

        Table topTable = pdfReport.LastSection.AddTable();
        topTable.Borders.Visible = true;
        topTable.Borders.Color = Colors.Gray;
        topTable.Format.Font.Name = "Calibri Light";
        topTable.Format.Font.Size = 8;
        topTable.Format.Font.Color = Colors.Black;
        topTable.Format.SpaceAfter = 0;
        topTable.Format.SpaceBefore = 0;
        Column column;
        column = topTable.AddColumn(90);
        column.Format.Font.Bold = true;       //    <-- this
        column = topTable.AddColumn(400);
        Row row;
        row = topTable.AddRow();
        row.Cells[0].AddParagraph("Analysis Run:");
        row.Cells[1].AddParagraph(_report.AnalysisRun.ToString());
        row = topTable.AddRow();
        row.Cells[0].AddParagraph("Case Number:");
        row.Cells[1].AddParagraph(_report.CaseNumber);
        row = topTable.AddRow();
        row.Cells[0].AddParagraph("Sample ID:");
        row.Cells[1].AddParagraph(_report.SampleID);
        row = topTable.AddRow();
        row.Cells[0].AddParagraph("Comments:");
        row.Cells[1].AddParagraph(_report.Comments);

Solution

  • Just a guess: I think the problem is the font 'Calibri Light'. There is no bold version for 'Calibri Light' and MigraDoc does not know that 'Calibri Regular' should be used when a "Calibri Light Bold" is needed.

    I hope MigraDoc will handle this correctly when you change the font name to 'Calibri' or 'Arial' or any other font that supports both Regular and Bold.

    Setting the font name 'Calibri' for the first column should do the trick.