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.

Tue Jul 29, 2014 9:56 am

How to realize the following paragraph format with spire.DOC? We like to suppress the page break inside a table.

With Selection.ParagraphFormat
.KeepWithNext = True
.KeepTogether = True
End With

Thank you in advance

Vogel_M13
 
Posts: 3
Joined: Tue Nov 06, 2012 3:01 pm

Wed Jul 30, 2014 2:36 am

Hello,

Thanks for your inquiry.
Please refer to the following code snippet.
Code: Select all
           Document doc = new Document();
            doc.LoadFromFile("..\\..\\1.docx");
            foreach (Section section in doc.Sections)
            {
                for (int i = 0; i < section.Body.Paragraphs.Count; i++)
                {
                    Paragraph paragraph = section.Body.Paragraphs[i];
                    if (HasPageBreak(paragraph))
                    {
                        section.Body.Paragraphs.Remove(paragraph);
                    }
                }

            }
            string output = "result.docx";
            doc.SaveToFile(output,FileFormat.Docx);
            System.Diagnostics.Process.Start(output);       
        }
        static bool HasPageBreak(Paragraph paragraph)
        {
            bool result = false;
            for (int i = 0; i < paragraph.ChildObjects.Count; i++)
            {
                DocumentObject obj = paragraph.ChildObjects[i];
                if (obj.DocumentObjectType == DocumentObjectType.Break)
                {
                    if ((obj as Break).BreakType == BreakType.PageBreak)
                    {
                        result = true;
                    }
                }
            }
            return result;
        }


If you still have this problems, please provide us your document and we will provide you a demo to achieve it.

Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc