Hi,
I have requirement to replace merge field with content of another document.
I am doing this is using below code.
using (Document newDoc = new Document(filePath))
{
Section parentSection = null;
int index = 0;
foreach (var item in args.CurrentMergeField.Document.Sections)
{
if ((item as Section).Paragraphs.IndexOf(args.CurrentMergeField.OwnerParagraph) >= 0)
{
parentSection = item as Section;
index = (item as Section).Paragraphs.IndexOf(args.CurrentMergeField.OwnerParagraph);
break;
}
}
foreach (Section section in newDoc.Sections)
{
foreach (Paragraph paragraph in section.Paragraphs)
{
parentSection.AddParagraph();
parentSection.Paragraphs.Insert(index + 1, paragraph.Clone() as IParagraph);
index++;
}
}
}
However because of this multiple blank pages getting added to document.
Could you please look into this? and provide a workable solution.