Rearrange Word Pages using C# .NET

In the digital world, word processing documents are one of the most commonly used file formats that are used to create and edit documents. While dealing with large documents, it is really not easy to move pages without losing the formatting. Formatting loss often happens when we try to combine multiple documents of different types or we simply merge the same type of files into one single document. In order to rearrange the pages, this article discusses, how to programmatically move pages in Word documents (DOC/DOCX) using C#.

.NET API to Move Word Document Pages

GroupDocs.Merger provides the .NET API that enables moving, removing, splitting of documents, and extraction of pages, changes in page orientation, and rotation of document pages within the .NET applications. Today, we will use this API to move pages of DOC/ DOCX files using C#. For the details and other features of the API, you can visit the documentation.

You can download the DLLs or MSI installer from the downloads section or install the API in your .NET application via NuGet.

PM> Install-Package GroupDocs.Merger

Move Pages in Word Documents using C#

The moving of pages is simple. Just command that particular page to move to its new position. The following are the steps that rearrange the pages of a Word document using C#.

  • Define the page number of the target page and its new position using the MoveOptions class.
  • Load the DOC/DOCX document using the Merger class.
  • Use MovePage method to move the page.
  • Save the rearranged document using the Save method.

The following C# code helps rearrange the pages of a Word document. Precisely, it moves the 7th page of a DOCX document to the 2nd place.

Get a Free API License

You can get a free temporary license in order to use the API without the evaluation limitations.

Conclusion

To conclude, we learned how to change page order in Word documents using C# within .NET applications. We saw the source code example that changed the position of the page in a DOCX file. You can build your own application that can rearrange Word pages online by easily shuffling the pages.

For more details about the API, visit the documentation. For queries, contact us via the forum.

See Also