How to set page margin in word document


Is there a way to set page margins on the word document like Sections?

(similar to section.PageSetup.LeftMargin )

S Shah


In Word documents page margins are per section. You need to loop through Section objects setting the margins you want if you want it for the whole document. We might later provide convenience property Document.PageSetup, but it will do just that - loop through all Sections.


How do I do that - iterate through each Section? I’m attempting to create a bookmark but it is always getting butted up to the left margin and I’d like to apply some margin to it.


Here's an example:

Document doc = new Document(filename);

foreach(Section section in doc.Sections) {

// set the margin in points here (72 points =1 inch)

section.PageSetup.LeftMargin = 36;