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 May 17, 2019 9:02 pm

Hi, new to Spire.doc. I have an existing document that has 2 pages. Some of the content on the first 2 pages needs changing, so I've used:-

Code: Select all
   Spire.Doc.Document doc = new Spire.Doc.Document();
            doc.LoadFromFile(path);
            doc.Replace("##DATEOFISSUE##", DateVar, true, true);


The above works fine, but I now want to add a 3rd new page and start adding new text to it.

I'm not able to insert a PageBreak after the existing 2 pages to create a new page, and then add new text after the PageBreak.

Wilshaw
 
Posts: 6
Joined: Fri May 17, 2019 8:44 pm

Mon May 20, 2019 5:56 am

Hello,

Thanks for your inquiry.
Please kindly refer to the following sample code to achieve your requirement, if there is any question, please share us with your existing document to help further look into it. You could send it to us via email (support@e-icbelue.com).
Code: Select all
 Document document = new Document();
 document.LoadFromFile(@"sample.docx");
 //get the last section of document
 Section lastSection = document.LastSection;
 //add page break after the last paragraph of last section 
 document.LastSection.Paragraphs[document.LastSection.Paragraphs.Count - 1].AppendBreak(BreakType.PageBreak);
 //add new paragraph to the last section
 Paragraph newPara = lastSection.AddParagraph();
 //add new text
newPara.AppendText("This is a test!");
 //save the file
 document.SaveToFile("result.docx", Spire.Doc.FileFormat.Docx2013);

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Tue May 21, 2019 3:58 pm

That's perfect thanks, all working!

Wilshaw
 
Posts: 6
Joined: Fri May 17, 2019 8:44 pm

Wed May 22, 2019 1:28 am

Hello,

Thanks for your valuable feedback. If you need further assistance, please do not hesitate to contact us.
Wish you all the best!

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc