Every page of the document may contain different layouts. It depends on the content of the page; that which orientation suits it. As a developer, we can change the orientation of each page to the one it suits. In this article, we will learn to change the orientation of a page in a Word document using C#. Separately, we will see how to change the portrait layout to landscape and then how to change the landscape orientation to portrait with the .NET applications.
A small change has been made to this article.
.NET API for Changing Word Page Orientation
GroupDocs.Merger showcases the .NET API that enables changing the orientation of Word document pages. Additionally, the API allows moving pages, removing pages, splitting of documents, extraction, and rotation of document pages within the .NET applications. We will use this GroupDocs.Merger for .NET to change the page orientation 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
Change Orientation of a Word Page to Landscape using C#
Let’s begin with a simple way how to programmatically make a page landscape in a Word document. The following steps allow changing the page orientation of a Word document to landscape using C#:
- Load the Word document using Merger.
- Prepare the orientation options and set the mode to landscape.
- Change the orientation using ChangeOrientation().
- Save the updated document using the appropriate Save().
The following C# code changes the portrait orientation of some pages of a Word document to the landscape.
Change Orientation of a Word Page to Portrait using C#
Similarly, you can make any set of pages of the Word document in portrait orientation. The following steps allow changing the orientation of a Word document page to portrait using C#:
- Load the Word document using Merger.
- Prepare the orientation options and set the mode to portrait.
- Use ChangeOrientation() method to change the orientation.
- Use the appropriate Save() method to save the updated document.
The following C# code changes the portrait orientation of some pages of a Word document to portrait.
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 the page orientation of Word documents using C# within .NET applications. We saw the source code example that changed the portrait orientation of the selected pages of a DOCX file to the landscape. Similarly, we changed the landscape orientation of the selected pages to portrait using the C# example. You can try building your own application that can toggle the orientation Word pages online.
For more details about the API, visit the documentation. For queries, contact us via the forum.