How to rearrange Word DOC pages in Java

Move, Reorder, and Rearrange Pages in Word Online using Java.

Have you ever found yourself in a situation where you needed to rearrange the pages in a Word document? In certain cases, you may need to move and reorder certain pages to the beginning or end of a document to create a more logical flow. Manually rearranging pages in a large document can be a time-consuming task, but there’s a solution that can simplify this process for you – GroupDocs.Merger Cloud SDK for Java. In this article, you will learn how to move, reorder, and rearrange pages in Word online using Java.

The following topics shall be covered in this article:

Java REST API to Rearrange Word Pages - SDK Installation

GroupDocs.Merger Cloud SDK for Java is a very powerful document manipulation API that allows developers to work with various document formats, including Word documents. It provides a comprehensive set of features for moving, reordering, merging, rotating, and manipulating documents. Integrating the SDK into Java-based applications is made simple and efficient.

You can either download the API’s JAR file or install it using Maven by adding the following repository and dependency into your project’s pom.xml file:

Maven Repository:

<repository>
    <id>groupdocs-artifact-repository</id>
    <name>GroupDocs Artifact Repository</name>
    <url>https://repository.groupdocs.cloud/repo</url>
</repository>

Maven Dependency:

<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-merger-cloud</artifactId>
    <version>23.2</version>
    <scope>compile</scope>
</dependency>

Next, you need to sign up for a free trial account or purchase a subscription plan on the GroupDocs website to get your API key. Once you have the Client Id and Client Secret, add below code snippet to a Java-based application:

How to Rearrange Pages in Word Online using Java

Moving pages in a Word document using GroupDocs.Merger Cloud SDK for Java is a straightforward process. Here are steps and an example code snippet to get started:

  • Firstly, create an instance of the PagesApi class.
  • Secondly, create an instance of the FileInfo class.
  • Next, set the input word file path.
  • Now, create an instance of MoveOptions class.
  • Then set the setFileInfo and setOutputPath.
  • Provide the page number for setPageNumber and setNewPageNumber.
  • After that, create the MoveRequest class instance and pass the MoveOptions parameter.
  • Finally, call the move method and pass the MoveRequest parameter.

The following code snippet shows how to rearrange pages in Word online using Java:

Finally, the above code snippet will save the rearranged Word pages on the cloud.

Swap Word Document Pages in Java using REST API

Swapping pages in a Word document using GroupDocs.Merger Cloud SDK for Java follows a similar process as moving pages. Here are steps and a code snippet to achieve this:

  • Firstly, create an instance of the PagesApi class.
  • Secondly, create an instance of the FileInfo class.
  • Next, set the input word file path.
  • Then, create an instance of the SwapOptions.
  • Then set the setFileInfo and setOutputPath.
  • Provide the page number for setPageNumber and setNewPageNumber.
  • After that, create the SwapRequest class instance and pass the SwapOptions parameter.
  • Finally, call the swap method and pass the SwapRequest parameter.

The following code snippet elaborates on how to swap pages in a Word document using Java REST API:

How to reorder pages in Word online for free? Please try the following free online tool to change the order of word pages online, which is developed using the above API.

Conclusion

In conclusion, GroupDocs.Merger Cloud SDK for Java is a valuable tool for moving, reordering, and rearranging pages in Word documents. The following is what you have learned in this article:

  • how to move, and rearrange pages in Word online using Java;
  • and how to swap Word document pages using Java.

Additionally, we also provide an API Reference section that lets you visualize and communicate with our APIs directly through the browser. Java SDK’s complete source code is freely available on Github. Please check the GroupDocs.Merger Cloud SDK for Java Examples here.

Moreover, we suggest you follow our Getting Started guide for detailed steps and API usage.

Finally, we keep writing new blog posts on different document operations using REST API. So, please get in touch for the regular updates.

Ask a question

If you have any questions about how to rearrange pages in Word, please feel free to ask us on the forum.

FAQs

Is it possible to move pages between different sections within a Word document?

Yes, GroupDocs.Merger Cloud SDK for Java allows you to move pages within the same document, even if they contain multiple sections.

Does the Java SDK preserve document formatting and other elements during page rearrangement?

Yes, GroupDocs.Merger Cloud SDK for Java ensures that your document’s formatting and other elements are preserved when moving, reordering, or rearranging pages.

See Also

Here are some related articles that you may find helpful: