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 Mar 02, 2018 9:53 am

Hello,

I would like to copy the whole content of a word file while also preserving all section breaks in it. In particular, I need to keep into account that the source file may contain different kinds of section breaks, such as “next page” section breaks (i.e., breaks that start the new section on the next page) and “continuous” section breaks (i.e., breaks that start the new section on the same page). Is it possible to achieve this with Spire.Doc?

Thanks

fcs
 
Posts: 2
Joined: Fri Mar 02, 2018 9:44 am

Fri Mar 02, 2018 10:34 am

Dear fcs,

Thanks for your inquiry.
Yes, please use following code.
Code: Select all
            Document sourceDoc = new Document(@"F:\Sample.docx");
            Document destinationDoc = new Document("F:\Des.docx");
            foreach (Section sec in sourceDoc.Sections)
            {
                destinationDoc.Sections.Add(sec.Clone());
            }
            destinationDoc.SaveToFile("Result.docx");

But I found "continuous" section break was missing using my sample document, I have posted it to our Dev team. To help us solve your issue accurately, could you please provide your source file so that we could record your issue according to your document if there is the same issue ?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Mar 02, 2018 3:07 pm

Dear Betsy.jiang,

thank you for your reply. I tried the code you provided: it properly preserves all the section breaks, but it also adds a new and undesired "new page" section break at the beginning of the document. Does this happen also to you? To me it happens with both the trial and pro version of Spire.Doc. It also seems that the first page (the one with the undesired section break) has a different size compared to the other pages.

You can find in the .rar attachment a file, "input.docx", similar to the one I used to test your code with the pro version of Spire.Doc (I cannot provide the original file because there are sensitive data stored in it, my apologies), containing both a "new page" section break (at page 1) and a "continuous" section break (at page 2). You can also find in the .rar attachment the output file, "output.docx", generated with the trial version of Spire.Doc (I cannot use the pro version on the sample file at the moment) still using your code. You can see that the first page of "output.docx" contains a section break not present in "input.docx" and also that it has the "A4" size instead of the "letter" size of the other pages.

Thank you
Last edited by fcs on Mon Mar 05, 2018 9:29 am, edited 1 time in total.

fcs
 
Posts: 2
Joined: Fri Mar 02, 2018 9:44 am

Mon Mar 05, 2018 8:51 am

Dear fcs,

Thanks for your feedback.
After testing with the latest Spire.Doc Pack(hot fix) Version:6.2.3, everything worked fine on my side. Here is my testing code and I attached my result document.
Code: Select all
            Document sourceDoc = new Document(@"F:\input.docx");
            //create a new file
            Document destinationDoc = new Document();
            //copy the content
            foreach (Section sec in sourceDoc.Sections)
            {
                destinationDoc.Sections.Add(sec.Clone());
            }
            destinationDoc.SaveToFile("13124.docx");

1. As for the issue undesired "new page" section break at the beginning of the document, did you use the latest version? What is your code ?

2. For the page size issue, I found both the result you provided and the result I generated were letter on my side. You could check the screenshot as below.
WordVersion.png

What is your OS information ? E.g. Win7 64bit, China/Chinese. And the Word version ?
WordVersion.png

Besides, we promise to keep customer's data confidential and won’t use it for any other purpose. You could send your file(support@e-iceblue.com) to us via email.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Mar 07, 2018 8:35 am

Dear fcs,

Greetings from E-iceblue.
How is your issue going now ? Could you please give us some feedback at your convenience ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc