Rotate Text in PDF in Java

Various PDF libraries offer you the feature of rotating text in PDF files using Java. However, you don’t get high-speed processing, high-quality output, and an easy-to-code solution at the same time. This article provides you with one of the best and easiest methods to rotate text in PDF using Java following a few simple steps. Also, it covers a couple of ways to rotate PDF text that you can adopt according to your needs. So let’s being and see how to apply rotation on text in a PDF file using Java.

Java Library to Rotate Text in PDF

To rotate text in PDF files, we will use Aspose.PDF for Java. It is a powerful library that provides basic as well as advanced PDF manipulation features. You can download the library or install it using the following Maven configurations.

Repository:

    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>

Dependency:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>22.12</version>
</dependency>

How to Rotate Text in PDF in Java

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

Java: Rotate Text in PDF using TextFragment

The following are the steps to rotate a text fragment in a PDF using Java.

Java Code to Rotate Text in PDF

The following code sample shows how to rotate text in a PDF in Java.

Output

PDF Text Rotation using TextFragment in Java

Apply Text Rotation in PDF using TextParagraph

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 with Java.

Output

PDF Text Rotation using TextParagraph in Java

Free Java Library to Rotate Text in PDF

You can get a free temporary license and rotate text in PDF files without any limitations.

Explore Java PDF Library

You can explore more about Java PDF library using the documentation. In case you would have any questions or queries, you can contact us via our forum.

Conclusion

In this article, you have learned how to rotate text in PDF using Java. We have covered how to rotate text using TextFragment and TextParagraph classes. You can simply install the library and use the provided code samples in your Java application.

See Also