Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat Feb 19, 2022 4:51 pm

I'd like to vertically align text within a textbox. This works with Microsoft Word, but I'm not able to do it with Spire.Doc.

Microsoft Word seems to support two different types of "text boxes".

See the following screenshot with the green arrows for the "first type". Seems to be called "AutoForm". Sorry for the German translation of the user interface. This is the type of textbox I get when I use Spire.Doc's "AppendTextBox" method. There is no possibility to vertically align text.

textbox1.jpg


See the following screenshots with the orange arrows for the "second type". Using this type of text box, I have a different set of options for formatting, including vertical alignment:

textbox2.jpg


textbox3.jpg


Is it possible to create an item of the "second type" in Spire.Doc?
Please tell me if you need screenshots in English to understand my issue.

andi@xenoage.com
 
Posts: 2
Joined: Thu Sep 15, 2016 3:18 pm

Mon Feb 21, 2022 3:35 am

Hello,

Thanks for your inquiry.
Please use the following code to achieve your needs. If there is any question, please feel free to contact us.
Code: Select all
Document doc = new Document();
 Section section = doc.AddSection();
 TextBox tb = section.AddParagraph().AppendTextBox(100,150);
 tb.Format.HorizontalAlignment = ShapeHorizontalAlignment.Left;
 //Set the vertical center of the text in the text box.
 tb.Format.TextAnchor = ShapeVerticalAlignment.Center;
 tb.Format.LineColor = Color.Gray;
 tb.Format.LineStyle = TextBoxLineStyle.Simple;
 tb.Format.FillColor = Color.Red;
 Paragraph para = tb.Body.AddParagraph();
 TextRange txtrg = para.AppendText("Textbox , Which I'd like to create.");
 txtrg.CharacterFormat.FontName = "Lucida Sans Unicode";
 txtrg.CharacterFormat.FontSize = 14;
 txtrg.CharacterFormat.TextColor = Color.White;
 para.Format.HorizontalAlignment = HorizontalAlignment.Left;
 doc.SaveToFile("output.docx",FileFormat.Docx2013);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1648
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc