Section Format in Blazor DOCX Editor
22 Oct 20262 minutes 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);The maximum value of
Marginis 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 DOCX 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);Footer distance
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);Breaks
You can insert a column break to move the text following the cursor to the next column.
await documentEditor.Editor.InsertColumnBreakAsync();You can insert a page break to move the content following the cursor to the next page.
await documentEditor.Editor.InsertPageBreakAsync();You can insert a next-page section break to start the new section on the next page.
await documentEditor.Editor.InsertSectionBreakAsync(SectionBreakType.NewPage);You can insert a continuous section break to start the new section on the same page.
await documentEditor.Editor.InsertSectionBreakAsync(SectionBreakType.Continuous);Online demo
Explore how to apply section formatting in Word documents using the Blazor DOCX Editor in this live demo.