Aspose.Words PageBorder Margins

Hi,

I’m trying to put a page border in my document, however the problem im having is that my tables are overlapping these borders. I could put some left indent in the table cells however that looks really untidy. Here’s my code:


' Create doc
doc = New Document()
builder = New DocumentBuilder(doc)
' Set custom page layout
Dim ps As PageSetup = builder.PageSetup
ps.PaperSize = PaperSize.A5
ps.Orientation = Aspose.Words.Orientation.Landscape
ps.TopMargin = ConvertUtil.MillimeterToPoint(5)
ps.BottomMargin = ConvertUtil.MillimeterToPoint(15)
ps.LeftMargin = ConvertUtil.MillimeterToPoint(10)
ps.RightMargin = ConvertUtil.MillimeterToPoint(10)
ps.HeaderDistance = ConvertUtil.MillimeterToPoint(12.5)
ps.FooterDistance = ConvertUtil.MillimeterToPoint(12.5)
ps.DifferentFirstPageHeaderFooter = False
ps.PageStartingNumber = 1
ps.RestartPageNumbering = True
ps.Borders.LineStyle = LineStyle.Single
ps.Borders.Color = System.Drawing.Color.Black
ps.BorderAlwaysInFront = False
builder.StartTable()
builder.InsertCell()
builder.Write("Test")
builder.EndRow()
builder.EndTable()

How can i put some padding between the page border and the left edge of the table? I think i’m looking for the page border margins however i can’t find anything in the api for this. Also is there anything in the api for the “Align paragraph borders and table edges with page border” and “Surround header” options that are found in ‘Page Border & Shading’ options in word.

Many thanks,

Greg

Hi Greg.

You can apply cell formatting options as it is shown in the article:
https://reference.aspose.com/words/net/aspose.words.tables/cellformat

Note that “left padding” is the value being added to the cell. So if you want to indent the cell negative value should be specified:

builder.CellFormat.LeftPadding = –10

For the paragraph formatting see this:
https://reference.aspose.com/words/net/aspose.words/paragraphformat

You can change formatting options in ParagraphFormat.

For the other settings please clarify what of them you would like to control.

Regards,

Thanks for the reply. Does Aspose.Words not have a page border feature? I can get the desired results in MS Word by going Format --> Borders and Shading --> Page Border --> Options. Is it possible to mimick these options programmatically?

Your suggestion for negative padding is what i was looking for, however as in my first post does aspose.words support the “surround header” feature found in the page border options?

Hi Greg.

We’ve found the better way to indent the table. Consider using RowFormat.LeftIndent property:

builder.StartTable()

’ shift table 10 points to the left from the page border

builder.RowFormat.LeftIndent = 10
builder.InsertCell()
builder.Write("Test")
builder.InsertCell()
builder.Write("Test")
builder.EndRow()
builder.EndTable()

Manipulating LeftPadding, in this case setting it to negative value, is not a good way of solving the problem.

LeftPadding controls the distance between left cell border and cell text. Setting it to negative for the first cell in the row indeed causes the table to shift left. But the text in the cell is pressed to the left. As the result you loose the option to control the distance between the cell text and its left border. I’m sorry for that recommendation even if it helps at first glance.

“Surround header” and “surround footer” features are not exposed in the public API. I’ve initiated this as issue #3212. We will notify you when these features are supported.

Regards,

Excellent.

Thanks for the help.

Greg

We have released a new version of Aspose.Words that contains a fix for your issue.

The new version is available at:
https://downloads.aspose.com/words/net

Best regards