Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Nov 03, 2023 3:43 pm

How can I add multiple sections to one page? Now, when I use document.AddSection() a new page is automatically created in my document for each section, and I would prefer to have some sections on the same page if they fit.

Thanks

nataliegracegibbons
 
Posts: 13
Joined: Tue Oct 03, 2023 4:45 pm

Mon Nov 06, 2023 2:12 am

Hi,

Thanks for your inquiry.
Our Spire.Doc supports to add multiple sections to one page, you only need to add a section break in the specified paragraph. Please refer to the following code.
Code: Select all
Document doc = new Document();

// Create a new section instance
Section section = doc.AddSection();

// Add a new paragraph
Paragraph paragraph = section.AddParagraph();

// Append text
paragraph.AppendText("This is the first section");

// Insert a continuous section break,now the document contains two section
paragraph.InsertSectionBreak(SectionBreakType.NoBreak);

// Get the second section
section = doc.Sections[1];

// Add a blank paragraph
section.AddParagraph();

// Add a new paragraph
paragraph = section.AddParagraph();

// Append text
paragraph.AppendText("This is the second section");

// Insert a continuous section break
paragraph.InsertSectionBreak(SectionBreakType.NoBreak);

doc.SaveToFile("result.docx");


result.png

If you have any other questions or concerns, just feel free to contact us. We are here to help.

Have a nice day!

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.Doc

cron