Set the top- bottonm left- right Margins in Word document

Hi
I am creating a word doc with Aspose Word.
I set the margins using the Word’s PageSetup API
but somehow it’s not working.

Can you share some code to do this properly.

Hi Nitin,

Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v13.4.0) from here and let us know how it goes on your side. If the problem still remains, please attach your input Word document here for testing. I will investigate the issue on my side and provide you more information.

Following code example shows how to Specify paper size, orientation, margins and other settings for a section.

DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.PageSetup;
ps.PaperSize = Aspose.Words.PaperSize.Legal;
ps.Orientation = Aspose.Words.Orientation.Landscape;
ps.TopMargin = ConvertUtil.InchToPoint(1.0);
ps.BottomMargin = ConvertUtil.InchToPoint(1.0);
ps.LeftMargin = ConvertUtil.InchToPoint(1.5);
ps.RightMargin = ConvertUtil.InchToPoint(1.5);
ps.HeaderDistance = ConvertUtil.InchToPoint(0.2);
ps.FooterDistance = ConvertUtil.InchToPoint(0.2);
builder.Writeln("Hello world.");
builder.Document.Save(MyDir + "PageSetup.PageMargins Out.doc");

Thank you - that is great!
I will try that