Skip to main content
Skip table of contents

Rotating text without shifting its location

📌 Overview

This article explains how to rotate text without shifting its location on the page. When using FMatrix.rotate() the point of rotation is always the top left of the page, which leads to a shift in the object’s location. Below are some screenshots that demonstrate this effect when rotating some text.

Original

Boxes added

Green box moved

a9639738-db6c-41ea-b4ed-dd8a17abb564.png
Screenshot 2025-06-10 161430.png

Boxes are added to demonstrate how the rotation is applied

image-20250610-152459.png

When the green (rotated) box is moved you can see that the top left corner of the box was still in the top left corner of the page.

(question) Issue Description

A customer reported that when they rotated some text it would also be shifted from its original location. They wanted to know how to calculate the translation needed to counteract this shift so that the top left corner of the text would not move.

Note: there is no way to prepare the group for rotating by moving it to the top left corner of the page. This is because FMatrix stores rotations and translations separately and always applies translations last.

💡 Solution

To calculate how to shift the group back to it’s original position on the page you must use the following formula.

Screenshot 2025-06-06 100825.png

⌨️ Sample Code

Here is a code snippet in C# that uses the above formula to return text in an ILayout back to its original position after rotating to achieve the desired result below.

Screenshot 2025-06-10 161443.png

C#
//get the position of the text on the page
var layoutNode = layout.layout(paragraphs);
var bounds = layoutNode.getBounds();
  
//create an FMatrix and add the rotation
var rotate = new FMatrix();   
var angle = text.Rotation * (Math.PI / 180.0);
rotate.rotate(angle);

//use the formula to add the translation back to the original position on the page
rotate.setDX(bounds.x*(1-Math.Cos(angle)) + bounds.y*Math.Sin(angle));
rotate.setDY(bounds.y*(1-Math.Cos(angle)) - bounds.x*Math.Sin(angle));

//create a group with the transformations and add the layout to it 
var group = IDOMGroup.create(mako, rotate);
group.appendChild(layoutNode);

//add the group to the fixedPage
fixedPage.appendChild(group);

☑️ Conclusion

Rotating text without shifting its location is a common requirement for maintaining the visual integrity of a document. By applying the provided formula and utilizing the sample C# code, users can effectively manage text rotation while keeping the text in its original position

📚 Additional Resources

If you need additional help, see our API documentation for detailed information on class/method usage, or raise a support ticket via our customer portal.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.