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.

Wed Mar 26, 2014 9:54 am

Hi

How can I remove all page breaks from word document.

tatvasoft
 
Posts: 9
Joined: Tue Mar 25, 2014 9:56 am

Thu Mar 27, 2014 3:05 am

Hello,

Thanks for your inquiry.
Please use the code below, it shoud remove all page breaks from the document.
Code: Select all
Document document = new Document();
document.LoadFromFile("test.docx");
foreach (Section sec in document.Sections)
            {
                foreach (Paragraph para in sec.Paragraphs)
                {
                   
                    if (para.Format.PageBreakBefore)
                    {
                        para.Format.PageBreakBefore = false;
                    }
                    if (para.Format.PageBreakAfter)
                    {
                        para.Format.PageBreakAfter = false;
                    }
                    for (int i = 0; i < para.Items.Count; i++)
                    {
                        if (para.Items[i].DocumentObjectType == DocumentObjectType.Break)
                        {
                            para.Items.Remove(para.Items[i]);
                        }
                    }

                }
            }
document.SaveToFile(@"..\..\result.docx");

If you need any futher help , please feel free to ask.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Apr 01, 2014 9:28 am

Hello,

Have you tried the method? Has your issue been resolved? Could you please provide us some feedback if convenience?

If there are any questions, welcome to get it back to us.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc