Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to Move, Reorder, and Rearrange Pages in Word using Ruby
# How to reorder or rearrange pages in word documents
# Create an instance of the Pages API
@pages_api = GroupDocsMergerCloud::PagesApi.from_keys(@app_sid, @app_key)
# Initialize MoveOptions
@options = GroupDocsMergerCloud::MoveOptions.new
@options.file_info = GroupDocsMergerCloud::FileInfo.new
@options.file_info.file_path = 'rearrange_pages/word-pages.docx'
@options.output_path = "rearrange_pages/move-pages.docx"
@options.page_number = 3
# Position to move docx page
@options.new_page_number = 5
# Rearrange pages in Docx file
result = @pages_api.move(GroupDocsMergerCloud::MoveRequest.new(@options))
puts("Successfully organized word page by page number.")
# How to swap pages in word file
# Create an instance of the Pages API
@pages_api = GroupDocsMergerCloud::PagesApi.from_keys(@app_sid, @app_key)
# Create SwapOptions instance
@options = GroupDocsMergerCloud::SwapOptions.new
@options.file_info = GroupDocsMergerCloud::FileInfo.new
@options.file_info.file_path = 'rearrange_pages/word-pages.docx'
@options.output_path = "rearrange_pages/swap-pages.docx"
@options.first_page_number = 2
@options.second_page_number = 5
# Swap pages in word document
@result = @pages_api.swap(GroupDocsMergerCloud::SwapRequest.new(@options))
puts("Successfully swapped word pages by page numbers.")

Learn how to rearrange and reorder word document pages using Cloud REST API:

The following topics shall be covered in this article:

  1. REST API to Rearrange Word Pages – Installation
  2. How to Rearrange Pages in Word Document using Ruby
  3. How to Swap Word DOCX Pages using REST API in Ruby
# Load the gem https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-ruby in Ruby application for http://api.groupdocs.cloud
require 'groupdocs_merger_cloud'
# Get your client_id and client_secret from https://dashboard.groupdocs.cloud after free registration.
@app_sid = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@app_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment