Section Format in Blazor DOCX Editor

14 Aug 20261 minute to read

Blazor DOCX Editor (Document Editor) supports various section formatting such as page size, page margins, and more.

Page size

You can get or set the size of a section at the cursor position by using the following sample code.

await documentEditor.Selection.SectionFormat.SetPageWidthAsync(500);
await documentEditor.Selection.SectionFormat.SetPageHeightAsync(600);

You can change the orientation of the page by swapping the values of page width and height respectively.

Page margins

The left and right page margins define the gap between the document content and the left and right sides of the page. The top and bottom page margins define the gap between the document content and the header and footer of the page.

Refer to the following sample code.

await documentEditor.Selection.SectionFormat.SetLeftMarginAsync(10);
await documentEditor.Selection.SectionFormat.SetRightMarginAsync(10);
await documentEditor.Selection.SectionFormat.SetTopMarginAsync(10);
await documentEditor.Selection.SectionFormat.SetBottomMarginAsync(10);

NOTE

The maximum value of Margin is 1584, as per the Microsoft Word application, and you can set any value less than or equal to 1584 to this property. If you set any value greater than 1584, then the Syncfusion Document Editor will automatically reset it to 1584.

Header distance

You can define the distance of header content from the top of the page by using the following sample code.

await documentEditor.Selection.SectionFormat.SetHeaderDistanceAsync(72);

You can define the distance of footer content from the bottom of the page by using the following sample code.

await documentEditor.Selection.SectionFormat.SetFooterDistanceAsync(72);

Online demo

Explore how to apply section formatting in Word documents using the Blazor Document Editor in this live demo.