Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/afdc33c1b6dff2d6f36c3dbdeb7198e8 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/afdc33c1b6dff2d6f36c3dbdeb7198e8 to your computer and use it in GitHub Desktop.
How to Rotate PDF Pages using Rest API in Ruby
# This code example demonstrates how to rotate all pages in a PDF document.
# Create a new instance of PagesApi
@pages_api = GroupDocsMergerCloud::PagesApi.from_keys(@app_sid, @app_key)
# Initialize RotateOptions
@options = GroupDocsMergerCloud::RotateOptions.new
@options.file_info = GroupDocsMergerCloud::FileInfo.new
@options.file_info.file_path = 'flip_pages/pdf-pages.pdf'
@options.output_path = "flip_pages/rotate90-pages.pdf"
# Set desired page rotation to 90, 180 or 270 degrees.
@options.mode = "Rotate90"
# Rotate pages in PDF file
@result = @pages_api.rotate(GroupDocsMergerCloud::RotateRequest.new(@options))
puts("Successfully rotated all pages in PDF file using Rest API.")
# This code example demonstrates how to rotate PDF documents.
# Initialize new instance of PagesApi
@pages_api = GroupDocsMergerCloud::PagesApi.from_keys(@app_sid, @app_key)
# Initialize RotateOptions
@options = GroupDocsMergerCloud::RotateOptions.new
@options.file_info = GroupDocsMergerCloud::FileInfo.new
@options.file_info.file_path = 'flip_pages/pdf-pages.pdf'
@options.output_path = "flip_pages/rotate270-pages.pdf"
# Specify pages range start and end page numbers
@options.start_page_number = 1
@options.end_page_number = 5
@options.mode = "Rotate270"
# Rotate pages in PDF file
@result = @pages_api.rotate(GroupDocsMergerCloud::RotateRequest.new(@options))
puts("Successfully rotated 270 degree PDF document using Rest API.")
# This code example demonstrates how to rotate pages in PDF document.
# Initialize new instance of PagesApi
@pages_api = GroupDocsMergerCloud::PagesApi.from_keys(@app_sid, @app_key)
# Initialize RotateOptions
@options = GroupDocsMergerCloud::RotateOptions.new
@options.file_info = GroupDocsMergerCloud::FileInfo.new
@options.file_info.file_path = 'flip_pages/pdf-pages.pdf'
@options.output_path = "flip_pages/rotate180-pages.pdf"
@options.mode = "Rotate180"
# Get only even or odd pages from the specified page range by setting range_mode property.
@options.start_page_number = 1
@options.end_page_number = 10
# Set range mode to 'AllPages' or 'OddPages' or 'EvenPages'
@options.range_mode = "EvenPages"
# Rotate pages in PDF document
@result = @pages_api.rotate(GroupDocsMergerCloud::RotateRequest.new(@options))
puts("Successfully rotated Even PDF pages using Rest API.")
# This code example demonstrates how to rotate pages in PDF files.
# Initialize new instance of PagesApi
@pages_api = GroupDocsMergerCloud::PagesApi.from_keys(@app_sid, @app_key)
# Initialize RotateOptions
@options = GroupDocsMergerCloud::RotateOptions.new
@options.file_info = GroupDocsMergerCloud::FileInfo.new
@options.file_info.file_path = 'flip_pages/pdf-pages.pdf'
@options.output_path = "flip_pages/rotate180-pages.pdf"
# Provide exact page numbers starting from 1 via Pages collection
@options.pages = [1, 7]
@options.mode = "Rotate180"
# Rotate pages in PDF file
@result = @pages_api.rotate(GroupDocsMergerCloud::RotateRequest.new(@options))
puts("Successfully rotated PDF specific pages using Rest API.")

Learn how to rotate PDF pages in Ruby using Cloud REST API:

The following topics shall be covered in this article:

  1. PDF Pages Rotation Rest API and Ruby SDK
  2. Rotate All Pages of a PDF Document using Ruby
  3. Rotate Specific Pages of PDF file using Ruby
  4. Rotate PDF Pages by Providing Page Number using Ruby
  5. Rotate PDF Pages by Setting Range Mode using 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