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.

Thu Oct 22, 2020 3:45 pm

How do I add a blank new page to the end of the document?
This ideally will be done using either an existing Document object or created from a MemoryStream.
This includes removing the header and footer that has been used throughout the document. It must be completely blank.

So far my attempts have resulted in the document becoming corrupted and not opening.

Many thanks.

AMW_1234
 
Posts: 3
Joined: Thu Oct 22, 2020 3:41 pm

Thu Oct 22, 2020 10:08 pm

I think I found a solution.

Create the document
Create a new section
Add a paragraph to the section with a space.
Set HeadersFooters.LinkToPrevious to false
Add the new section to the document sections

and that should be it.

AMW_1234
 
Posts: 3
Joined: Thu Oct 22, 2020 3:41 pm

Fri Oct 23, 2020 4:31 am

Hello,

Thanks for your post.
Yes, your solution can work. But you can simplify it a bit. Just add a new section and set HeadersFooters.LinkToPrevious to false, as shown below.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile("input.docx");
            Section section = doc.AddSection();
            section.HeadersFooters.LinkToPrevious = false;
            doc.SaveToFile("result1.docx", FileFormat.Docx);

Besides, if your source file doesn’t contain the headers and footers, you can directly add a page break in the last paragraph to add a blank new page. Below is the corresponding code for your reference.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile("input.docx");
            Paragraph paragraph = doc.LastParagraph;
            paragraph.AppendBreak(BreakType.PageBreak);
            doc.SaveToFile("result.docx", FileFormat.Docx);


Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Oct 23, 2020 7:01 am

Hi Brian,

Thanks for getting back to me.

Your first solution is one I had tried but resulted in word not being able to open the file as there is 'unreadable content'.

I think I tried the second one during development but as the document does contain both a header and a footer it was not suitable.

As mentioned, the solution I posted above works for me and the document generated appears to not have any issues.

All the best.

AMW_1234
 
Posts: 3
Joined: Thu Oct 22, 2020 3:41 pm

Fri Oct 23, 2020 8:10 am

Hello,

Thanks for your reply.
Regarding the first solution I provided, I tested it with the latest Spire.Doc Pack(hot fix) Version:8.10.4 and it worked well on my side. Attached are my input file and output file for your reference. I suspect that your issue may be related to your source file. If possible, you can provide us with your source file and output file and then we will further analyze.

Anyway, I’m glad to hear that you found a solution that works for you. If you have any other questions, just feel free to let us know. We are always here to help.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Doc