We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Differents margins between header/footer and document body

Hi,

We tried to create a document with different margins between header/footer and document body. We tried to insert a table in the body with left margin = 0 but we need to maintain left margin = 4 in the body.

Many thanks,

Hi Ignacio,

Thanks for your inquiry. Please use the PageSetup.LeftMargin property to set the distance (in points) between the left edge of the page and the left boundary of the body text. E.g. set it's value to 4.

Please use Table.LeftIndent property to get or set the value that represents the left indent of the table. Set it's value with negative number e.g. -2. Hope this helps you.

If you still face problem, please share your input and expected output documents here for our reference. We will then provide you more information about your query.

Hi Tahir,

It works fine, but now we have the same problem with right margin. We canĀ“t find something like RightIndent property.

Hi Ignacio,

Thanks for your inquiry. Could you please share your input and expected output documents here for our reference? We will then provide you more information about your query.

Hi Tahir,



I share expected output document, the input document is the same without header and footer sections.



Thanks!

Hi Ignacio,

Thanks for sharing the document. In your case, we suggest you please set the table's width less than page's width and set it's alignment to center. Please use CellFormat.Borders property to get the cell's border and set it's color using Border.Color property.

Following code example shows how to set the table's width and border color of last row of it. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");

//Set the width of table

double tablewidth = doc.FirstSection.PageSetup.PageWidth - doc.FirstSection.PageSetup.LeftMargin

- doc.FirstSection.PageSetup.RightMargin;

Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

table.PreferredWidth = PreferredWidth.FromPoints(tablewidth - 100);

table.Alignment = TableAlignment.Center;

//Change the bottom border of last row of table

foreach (Cell cell in table.LastRow.Cells)

{

cell.CellFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.Single;

cell.CellFormat.Borders[BorderType.Bottom].Color = Color.Green;

}

doc.Save(MyDir + "Out.docx");

Good job! It works fine.

Thanks a lot!