DungLT
August 26, 2019, 10:04am
1
Hi,
I’m using Aspose Word 17.9 and I created a TextBox, but I can’t set vertical align for it.
This is my code:
Document doc = new Document();
doc.CompatibilityOptions.DoNotVertAlignInTxbx = false;
doc.CompatibilityOptions.OptimizeFor(Aspose.Words.Settings.MsWordVersion.Word2013);
Shape _tb = new Shape(doc, ShapeType.TextBox);
_tb.Width = ConvertUtil.PixelToPoint(200);
_tb.Height = ConvertUtil.PixelToPoint(60);
_tb.FillColor = Color.Transparent;
_tb.AppendChild(new Paragraph(doc));
_tb.FirstParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
_tb.TextBox.InternalMarginBottom = 0f;
_tb.TextBox.InternalMarginLeft = 0f;
_tb.TextBox.InternalMarginRight = 0f;
_tb.TextBox.InternalMarginTop = 0f;
_tb.VerticalAlignment = VerticalAlignment.Center;
_tb.Stroked = false;
var _run = new Run(doc, "ABC");
_tb.FirstParagraph.AppendChild(_run);
_tb.FirstParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
var _par = new Paragraph(doc);
_par.AppendChild(_tb);
doc.FirstSection.Body.AppendChild(_par);
doc.Save("a.docx");
Process.Start("a.docx");
@DungLT ,
Please also ZIP and upload your expected Word document showing the desired output here for our reference. You can create expected document by using MS Word. Please also list the steps that you performed in MS Word to create this document. We will then investigate the scenario on our end and provide you code to achieve the same by using Aspose.Words.
DungLT
August 27, 2019, 1:18am
3
Hi, this is my Word document genarated by Aspose:
demo.zip (5.0 KB)
In MS Word:
Insert -> Shape -> TextBox -> Put sample Text -> Text Align -> Middle.
Thank and Best Regard.
@DungLT ,
Please see these input/output Word documents (textbox.zip (21.0 KB)) and try running the following code:
Document doc = new Document("E:\\temp\\textbox.docx");
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
Shape textBoxShape = shapes[0] as Shape;
if (textBoxShape != null)
{
textBoxShape.TextBox.VerticalAnchor = TextBoxAnchor.Middle;
}
doc.Save("E:\\Temp\\19.8.docx");
Hope, this helps.
1 Like
DungLT
August 29, 2019, 4:09am
5
Hi, @awais.hafeez
I’m using ver 17.9 and it not have VerticalAnchor prop
@DungLT ,
Please upgrade to the latest version of Aspose.Words for .NET i.e. 19.8 from the following link:
Download DLLs containing C# class library for Word® document generation, editing, merging, conversion, rendering, printing, report generation via .NET API.