Articles in this section
Category / Section

Why aren't merged documents added to a new page when merging Word documents using DocIO?

3 mins read

Syncfusion® Essential® DocIO is a .NET Word library that allows you to merge multiple Word documents into a single document. During the merging process, continuous section breaks in the source documents may cause the merged content to appear on the same page instead of starting on a new page. This is expected behavior based on the section break type in the source documents. In this article, we present solution to ensure the merged content starts on a new page and maintain the desired page count.

Modify the section break to “New Page” programmatically

To resolve this, programmatically change the section break type in the source documents to “New Page.” This ensures merged documents start on a new page, maintaining the correct page count.

The following code sample shows how to modify the section break in source document.
C#

using (FileStream sourceStreamPath = new FileStream(Path.GetFullPath(@"Data/SourceDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
   //Opens an source document from file system through constructor of WordDocument class.
   using (WordDocument sourceDocument = new WordDocument(sourceStreamPath, FormatType.Automatic))
   {
       using (FileStream destinationStreamPath = new FileStream(Path.GetFullPath(@"Data/DestinationDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
       {
           //Opens the destination document.
           using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic))
           {
               //Sets the break-code of first section of source document 
               sourceDocument.Sections[0].BreakCode = SectionBreakCode.NewPage;
               //Imports the contents of the source document to the destination document, and
               //applies the formatting of surrounding content to the destination document.
               destinationDocument.ImportContent(sourceDocument, ImportOptions.MergeFormatting);
               //Creates file stream.
               using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
               {
                   //Saves the Word document to file stream.
                   destinationDocument.Save(outputFileStream, FormatType.Docx);
               }
           }
       }
   }
}

You can download a complete working sample from GitHub.

Take a moment to peruse the documentation where you can find basic Word document processing options along with the features like mail merge, merge, split, and compare Word documents, find and replace text in the Word document, protect the Word documents, and most importantly, the PDF and Image conversions with code examples.

Conclusion

I hope you enjoyed learning about how to find and replace image title in .NET Core Word document.

You can refer to our ASP.NET Core DocIO feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core DocIO example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied