In the following C# code I attempt to determine the width of the page so that I can stretch a table with 3 columns to the full width of the page (minus the margins). Initially, I thought that I should set the width of each table column as 1/3 of the page width. However, I found that section.PageSetup.PageWidth
, section.PageSetup.LeftMargin
and section.PageSetup.RightMargin
in the code below return a value of 0.
Section section = document.AddSection();
section.PageSetup.PageFormat = PageFormat.A4;
section.PageSetup.Orientation = Orientation.Portrait;
int sectionWidth = (int)Math.Ceiling(section.PageSetup.PageWidth -
section.PageSetup.LeftMargin -
section.PageSetup.RightMargin);
int columnWidth = (int)Math.Ceiling(sectionWidth / 3);
I assumed that setting the page format to PageFormat.A4
and the orientation to Orientation.Portrait
will set the value of section.PageSetup.PageWidth
accordingly and will also set the values for the margins to some default values. Can someone please tell me what I am doing wrong? I only just started using MigraDoc yesterday. Many thanks.