Hi,
I want to draw a horizontal line in Word at particular location on document. Like i have 15 form fields in my document. i want to insert a line above 12th formfield. I am using following code, but it is not working, it draw the line at top of the document. How to set line at particular location.
Document doc1 = new Document(DocName);
DocumentBuilder builder = new DocumentBuilder(doc1);
var frmfields = doc1.GetChildNodes(NodeType.FormField, true);
for (int i = 0; i < frmfields.Count; i++)
{
FormField frmfield = (FormField)frmfields[i];
if (i == 12)
{
var Line = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.Line);
Line.Width = 500;
Line.StrokeColor = Color.Red;
builder.MoveToMergeField(frmfield.Name, true, true);
builder.InsertNode(Line);
}
}
doc1.Save(SavePath);
Thanks
Hi Shivam,
Thanks for your inquiry. Please use following code example to achieve your requirements.
Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
var frmfields = doc.GetChildNodes(NodeType.FormField, true);
for (int i = 0; i < frmfields.Count; i++)
{
FormField frmfield = (FormField)frmfields[i];
if (i == 12)
{
var Line = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.Line);
Line.Width = 500;
Line.StrokeColor = Color.Red;
builder.MoveTo(frmfield.ParentParagraph);
builder.InsertNode(Line);
}
}
doc.Save(MyDir + "17.4.docx");
You may insert top border of paragraph to get the desired output. Please check following code example. Hope this helps you.
Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
var frmfields = doc.GetChildNodes(NodeType.FormField, true);
for (int i = 0; i < frmfields.Count; i++)
{
FormField frmfield = (FormField)frmfields[i];
if (i == 12)
{
Paragraph para = frmfield.ParentParagraph;
para.ParagraphFormat.Borders.Top.LineStyle = LineStyle.Single;
para.ParagraphFormat.Borders.Top.Color = Color.Red;
}
}
doc.Save(MyDir + "17.4.docx");