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 May 25, 2022 6:58 am

Hello,

I am using "<p style='page-break-after: always;'></p> " this line from database to add a page break in word file. It was working before. but currently it is not working.

Looking for your help.

niralihvora
 
Posts: 14
Joined: Fri Nov 10, 2017 2:03 pm

Wed May 25, 2022 8:42 am

Hello,

Thanks for your inquiry.

I have tried the latest version(10.4.6) of Spire.Doc and an old version 7.1.1(released in 2019/11). For "<p style='page-break-after: always;'></p> " both of them cannot achieve page break effect. Which version did you use before?
Besides, you can do this by inserting page breaks after paragraphs. The reference code is as follows. Please test if it meets your current needs and feedback if there is any other question.

Code: Select all
            Document document = new Document();
            Section section=document.AddSection();
            section.AddParagraph().AppendText("hello world");
            //section.AddParagraph().AppendHTML("<p style='page-break-after: always;'></p> ");
            section.AddParagraph().AppendBreak(BreakType.PageBreak);
            section.AddParagraph().AppendText("hello world sec page");
            document.SaveToFile("result.docx",FileFormat.Docx);
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed May 25, 2022 9:24 am

Hello,

We are using Spire.Doc Pro Edition 9.2.

I am manipulating string, in this text content I have "<p style='page-break-after: always;'></p> " and I want to page break when I find "<p style='page-break-after: always;'></p> " in my string.

After this manipulation I Appended text to paragraph.

My code is as below:

string finalstring = "TEST 1 <pd4ml:page.break> TEST 2"
strHTMLContent += finalstring.Replace("<pd4ml:page.break>", "<p style='page-break-after: always;'></p>").Replace("<p> </p>", "").Replace("</pd4ml:page.break>", "");
FPARA.AppendHTML(strHTMLContent ");

I want to page break between "TEST 1" and "TEST 2"

niralihvora
 
Posts: 14
Joined: Fri Nov 10, 2017 2:03 pm

Wed May 25, 2022 10:34 am

Hello,

I have tested the version 9.2.0 but "<p style='page-break-after: always;'></p> " still didn't work. I have tried another solution to achieve the same purpose.
Here is my test code for your reference. Hope it can help you.

Code: Select all
            Document document = new Document();
            string finalstring = "TEST 1 <pd4ml:page.break> TEST 2";
            string strHTMLContent = finalstring.Replace("<pd4ml:page.break>", "$placeholder-page-break");
            Paragraph paragraph = document.AddSection().AddParagraph();
            paragraph.AppendHTML(strHTMLContent);
            //find the placeholder key
            TextSelection[] textSelections = document.FindAllString("$placeholder-page-break", false,true);
           
            foreach(TextSelection selection in textSelections)
            {
                TextRange range = selection.GetAsOneRange();
                Paragraph ownerParagraph = range.OwnerParagraph;
                int index=ownerParagraph.ChildObjects.IndexOf(range);
                //insert a pagebreak into the position of the placeholder
                ownerParagraph.ChildObjects.Insert(index,new Break(document, BreakType.PageBreak));
                //remove the placeholder
                ownerParagraph.ChildObjects.Remove(range);
            }

            document.SaveToFile("output.docx",FileFormat.Docx);
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.Doc