Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to size a table to the page width in MigraDoc?

I am trying to resize a table automatically to full width of the page. That table should have 2 columns, 50% width each.

How can I achieve this? I tried LeftIndent and RightIndent properties with no luck.

like image 998
jstuardo Avatar asked Jul 27 '14 22:07

jstuardo


People also ask

How do I change the row width in a table?

To set the row height to a specific measurement, click a cell in the row that you want to resize. On the Layout tab, in the Cell Size group, click in the Table Row Height box, and then specify the height you want. To use the ruler, select a cell in the table, and then drag the markers on the ruler.


1 Answers

Here's an approach that avoids hardcoding widths and allows for more flexible paper formats. Make sure to include the using MigraDoc.DocumentObjectModel; statement in your class.

Document document = new Document();

Section section = document.AddSection();
section.PageSetup.PageFormat = PageFormat.A4;

Table table = section.AddTable();

float sectionWidth = section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin;
float columnWidth = sectionWidth / 2;

Column column = table.AddColumn();
column.Width = columnWidth;
Column column2 = table.AddColumn();
column2.Width = columnWidth;

Row row = table.AddRow();
row.Cells[0].AddParagraph("Row 1, Column A");
row.Cells[1].AddParagraph("Row 1, Column B");
like image 169
Kidquick Avatar answered Sep 19 '22 14:09

Kidquick