I am attempting to rotate the orientation of the text in a textbox. This is how I do it purely in Microsoft Word:
1 - “Insert” → Textbox
2 - click on the Textbox
3 - click on “Shape Format”
4 - Click on “Text Direction” → “Rotate all text 90 degrees”
When I open the docx with Gembox.Document and look at the TextBox with a watch window, I see that there is a rotation value in in TextBoxFormat, but that property is not accessible. Is there any way to rotate text inside a textbox programmatically without rotating the textbox?
Below is a screnshot of what it looks like in Microsoft Word.
Hi,
What do you mean by “property is not accessible”?
Nevertheless, try this:
TextBox textbox = ...
textbox.Layout.Transform.Rotation = 90;
Does this solve your issue?
Regards,
Mario
Hi,
textbox.Layout.Transform.Rotation = 90;
will rotate the entire TextBox around the centerpoint vs rotation of just the text inside the textbox. I was looking for a way to rotate only the text, like how Microsoft Word does it. If it is not possible to only rotate text in a TextBox, I will code the Transform.Rotation and offset the layout to make it appear in the position I want it.
For the “property is not accessible”, I was not sure how to rotate just Text inside the TextBox, so I created what I wanted in Microsoft Word. I then opened it with var doc = DocumentModel.Load("rotated.docx");
to see what I should be doing to make it appear the way I want. I set a breakpoint and used a watch window to drill down into the DocumentModel to find the TextBox object.
When inspecting the TextBox object, the Layout does not have a Transform applied to it. The TextBoxFormat in the watch windows has a Rotation value, but when looking at the class definition for TextBoxFormat it shows only 2 properties : TextBox.TextBoxFormat.InternalMargin
and TextBox.TextBoxFormat.VerticalAlignment
. So it appears that Microsoft Word has data values that are not present in the Gembox.Document API, but correctly renders when saving to a pdf.
Below is the screenshot of what I am talking about. The stuff in blue is the Layout, and the stuff in green is for the TextBoxFormat.
Hi,
Please try again with this bugfix:
https://www.gemboxsoftware.com/document/nightlybuilds/GBD33v1461.zip
Or this NuGet package:
Install-Package GemBox.Document -Version 33.0.1461-hotfix
And try using the following:
textBox.TextBoxFormat.TextDirection = TextDirection.Rotate90;
Does this solve your issue?
Regards,
Mario
Yes, the new files did the trick. Thanks Mario!