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:55 pm

Microsoft Word supports opacity/transparency for the fill of a shape, e.g. a textbox.
See the following screenshot (sorry for the German UI):

opacity.jpg


However, I can not find a property in Spire.Doc's classes to access this value. I could find "FillColor", but including an alpha component there also has no effect.
How can it be set?

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

Mon Feb 21, 2022 3:38 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;
tb.Format.TextAnchor = ShapeVerticalAlignment.Center;
tb.Format.LineColor = Color.Gray;
tb.Format.LineStyle = TextBoxLineStyle.Simple;
// Set the text box fill color.
tb.Format.FillEfects.Gradient.Color = Color.Red;
// Set the transparency of the text box fill color.
tb.Format.FillEfects.Gradient.Opacity = 0.37;
Paragraph para = tb.Body.AddParagraph();
TextRange txtrg = para.AppendText("Textbox  How Spire.Doc create it.");
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: 1643
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc