How to set cell background color in MigraDoc table

I have a MigraDoc table where I specify a row height of 0.75 cm and the text is aligned vertically in the middle of the cell. When I set cell.Format.Shading.Color to something not white, there is still a part of the cell next to the border that is shown as white around all four sides.

I found that I can remove the white section to the left and right of the text by setting column.LeftPadding = 0 and column.RightPadding = 0. However, I cannot figure out how to get white bars at the top / bottom of the text to disappear without affecting the vertical alignment of the text . If I change the height of the line of the paragraph to 0.75 cm, the bars will disappear, but the text will be aligned to the bottom edge of the cell. I cannot set the color of the shading of the columns, because each cell in the column contains a different color. Does anyone know a way to make the paragraph fill the cell vertically (or else get the background color of the form in the cell)?

Here is an example of my code (in C #) where the table is of type MigraDoc.DocumentObjectModel.Tables.Table:

... // Add a column at index #2 var column = table.AddColumn(); column.LeftPadding = 0; column.RightPadding = 0; // Add more columns ... // Iterate through the data printed in each row foreach (var rowData in myData) { // Create a row for the data var row = table.AddRow(); row.Height = ".75cm"; row.Format.Font.Size = 11; row.VerticalAlignment = VerticalAlignment.Center; ... // The following is for illustrative purposes... the actual // colors and text is determined by the data within the cell var cell = row.Cells[2]; cell.Format.Shading.Color = Colors.Black; cell.Format.Font.Color = Colors.White; var paragraph = cell.AddParagraph("Example"); ... } 
+8
pdfsharp migradoc
source share
1 answer

Try cell.Shading.Color instead of cell.Format.Shading.Color - the first sets the color of the cell, the last sets the background color of the text (and adding the cell will have a different color).

+14
source share

All Articles