Hello,
I'm exploring the Infragistics.Documents.Word library, version 13.1 to create Word documents. I'm using the object model.
How does one go about changing the document page margins?
My first document is pretty simple and creates an Avery label for which I'd like to change the margins for the label.
Document doc = new Document();
Table table; table = doc.ContentBlocks.AddTable(); table.Properties.BorderProperties.Style = TableBorderStyle.None; table.Properties.Layout = TableLayout.Fixed; table.Properties.PreferredWidthAsPercentage = 100; table.Properties.CellSpacing = 4;
table.Columns.Add().PreferredWidth = 50; table.Columns.Add().PreferredWidth = 50;
TableRow row = table.Rows.Add();
Paragraph p = row.Cells.Add().ContentBlocks.AddParagraph(); p.ContentRuns.AddTextRun("Full Name 1"); p.ContentRuns.AddNewLine(); p.ContentRuns.AddTextRun("Address 1");
Paragraph p = row.Cells.Add().ContentBlocks.AddParagraph(); p.ContentRuns.AddTextRun("Full Name 2"); p.ContentRuns.AddNewLine(); p.ContentRuns.AddTextRun("Address 2");
doc.Save(@"C:\Test\doc.docx");
This works fine, but obviously margins are pretty important here. Any suggestions welcome.
Thank you.
That did it. Thank you!
Hi Robert,
Thank you for posting to our forums.
What you could do in order to set the margins of a word document with code similar to yours is to set the PageMargins property of the document. To do that use the following line before the doc.Save call in your sample code:
doc.FinalSection.Properties.PageMargins = new Infragistics.Documents.Word.Padding(100, 100, 100, 100);
Let me know if you have any additional questions.