Rotate Text inside PDF Documents in C#

Rotate Text inside PDF Documents in C#

PDF has become a ruling document format in the digital world. Its cross-platform support has made it a widely adopted format for generating and sharing documents, such as research articles, invoices, etc. While generating a PDF programmatically, you often need to change the position and orientation of the text according to the layout of the document. In this article, we will demonstrate how to rotate text inside PDF documents programmatically in C# .NET.

C# .NET API to Rotate Text in PDF

Aspose.PDF for .NET is a C# class library that provides basic as well as advanced PDF manipulation features for .NET applications. Using the API, you can generate PDF documents with simple or complex layouts seamlessly. We will use this API to rotate text inside PDF documents. You can either download the API’s DLL or install it using NuGet.

PM> Install-Package Aspose.PDF

Rotate Text inside PDF in C#

There are multiple ways to rotate a text inside a PDF document. You can either rotate a text fragment or the complete paragraph. Let’s see how each of these text rotations works.

PDF Text Rotation using TextFragment in C#

The following are the steps to rotate a text fragment in a PDF document using C#.

The following code sample shows how to rotate text in a PDF document in C#.

Output

PDF Text Rotation using TextFragment in C#

PDF Text Rotation using TextParagraph in C#

You can also apply rotation to the text while creating a new paragraph. This can be achieved using TextParagraph class. The following are the steps to apply text rotation using TextParagraph class.

The following code sample shows how to rotate text inside a paragraph in PDF programmatically.

Output

PDF Text Rotation using TextParagraph in C#

Get a Free API License

You can try Aspose.PDF for .NET for free by getting a temporary license.

Conclusion

PDF automation is widely adopted to create and manipulate PDF documents from within the web or desktop applications. In this article, you have learned how to rotate text in PDF programmatically using C#. We have explicitly covered how to rotate text using TextFragment and TextParagraph classes. Besides, you can explore other features using the documentation of Aspose.PDF for .NET. In case you would have any questions or queries, you can contact us via our forum.

See Also