How to rotate a paragraph?

I have a web site where the users upload photos and create photobooks. Also, they can add text at absolute positions, rotations, and alignments. The text can have new lines.

I've been using the iText Library to automatize the creation of the Photobooks Hight Quality PDFs that are printed latter on.

Adding the user uploaded images to the PDFs was really simple, the problem comes when I try to add the text.

In theory what I would need to do, is to define a paragraph of some defined width and height, set the users text, font, font style, alignment (center, left, right, justify), and finaly set the rotation.

For what I've read about Itext, I could create a Paragraph, set the user properties, and use a ColumnText object to set the absolute position, width and height. However it's not possible to set the rotation of anything bigger than single line.

I cant use table cells either, because the rotation method only allow degrees that are multiples of 90.

Is there a way to add a paragraph with some rotation (say 20 degrees) without having to add the text line by line using the ColumnText.showTextAligned() method and all math that involves?

Posted on StackOverflow on Mar 14, 2013 by BernalCarlos

With iText 7 you need only one step to solve your problem:


The result looks like:

Rotate paragraph

Rotate paragraph

Click this link if you want to see how to answer this question in iText 5.

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now