Word offers a variety of page layout and formatting options that affect how content appears on the page. You can customize the page orientation(portrait, landscape). How to change page orientation in word for one page or multiple pages is quick and easy using our Cloud API. In this how to change page orientation in Word document using Ruby tutorial I will show you how to change the orientation of one page to landscape on PC or MAC. Additionally, we will see how to change the landscape orientation to portrait in Ruby application.
The following topics shall be covered in this article:
- API for Changing Word Page Orientation to Landscape or Portrait
- Change Orientation of Word Pages to Landscape in Ruby
- Change Orientation of Word Document to Portrait in Ruby
API for Changing Word Page Orientation to Landscape or Portrait
GroupDocs.Merger API client allows you to set Portrait page orientation or Landscape page orientation for specific or for all Word document pages. Additionally, the API allows moving pages, swap pages, remove pages, splitting of documents, extraction of pages, and rotation of document pages in Ruby applications. We will use Ruby GroupDocs.Merger to change the page orientation of Word DOC/DOCX files in Ruby. For the details and other features of the API, you can visit the documentation guidelines.
You can install GroupDocs.Merger API to your Ruby project using the following command in the console:
gem install groupdocs_merger_cloud
Please also get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, add below code in your application as demonstrated below:
Now, let’s see how to change from portrait to landscape in google docs.
Change Orientation of Word Pages to Landscape in Ruby
Let’s begin with a simple way how to change landscape in google docs programmatically. Here are the steps about how to turn one page landscape in word using Ruby:
- Firstly, Create an instance PagesApi
- Then, create OrientationOptions instance
- Next, create an instance of FileInfo
- Set the input file path and output file path
- Provide comma separated page numbers to change orientation
- Set orientation mode to Landscape
- Next, create an instance of OrientationRequest
- Finally, change pages orientation by calling the PagesApi.orientation() method with OrientationRequest options
The following Ruby code changes the portrait orientation of some pages of a Word document to the landscape.
The above code sample will change from portrait to landscape in word. You can also use above code for how to make one page landscape in word.
Change Orientation of Word Document to Portrait in Ruby
Similarly, you can make any set of pages of the word document in portrait orientation. The following steps allow changing the orientation of Word page to portrait using Ruby:
- Firstly, Create an instance PagesApi
- Then, create OrientationOptions instance
- Next, create an instance of FileInfo
- Set the input file path and output file path
- Provide comma separated page numbers to change orientation
- Set orientation mode to Portrait
- Next, create an instance of OrientationRequest
- Finally, change pages orientation by calling the PagesApi.orientation() method with OrientationRequest options
The following Ruby code changes the landscape orientation of some pages of a Word document to portrait.
The above code sample will change the orientation of google docs pages from landscape to portrait. This code exmaple can also be used to change orientation of one page in word.
Summing up
In this article, we have learned how to change page orientation in google docs of multiple pages and simliarly how to change one page orientation in word using Ruby. We saw the source code example that change page orientation in word of the selected pages of portrait to landscape word document. Moreover, we also changed the landscape orientation of the selected pages to portrait in Ruby. You can try building your own application for how to make a single page landscape in google docs that can toggle the orientation word pages online.
Ask a question
For more details about the GroupDocs.Merger API, please visit the documentation. For queries about how to change page orientation in word, feel free to ask us via the Forum