Merge tag name mentioned in the builderSupportingPage2Doc.MoveToMergeField(mergetagname) line does not contain any value when the PDF is generated

I want to display the first page in a document which has 4 merge tags. I have used the code block below to do that. However, the merge tag name mentioned in the builderSupportingPage2Doc.MoveToMergeField(mergetagname) line does not contain any value when the PDF is generated. Please mention the solution for this issue. Also, is there a way by which I can display only the second or third page that is requested by the user.

Document SupportingPage_2Doc = new Document(documentTemplatePath + Constants.SupportingPage2);

if (!string.IsNullOrEmpty(pageNumber) && (pageNumber != Constants.AllPages))
{
    DocumentBuilder builderSupportingPage2Doc = new DocumentBuilder(SupportingPage_2Doc);
    builderSupportingPage2Doc.MoveToMergeField(pageNumber);
    Section secSupportingPage2 = builderSupportingPage2Doc.CurrentSection;

    SectionCollection sectionCollectionSupportingPage2 = SupportingPage_2Doc.Sections;

    foreach (Section section in sectionCollectionSupportingPage2)
    {
        if (section != secSupportingPage2)
        {
            section.Remove();
        }
    }
}

document.AppendDocument(SupportingPage_2Doc, ImportFormatMode.KeepSourceFormatting);

Hi Sanjay,

Thanks for your inquiry. The problem occurs when you move the cursor to a position where MERGEFIELD is located by using DocumentBuilder.MoveToMergeField method, it actually removes the MERGEFIELD itself. Please use the following code to get the current section of the MERGEFIELD:

foreach (FieldStart fieldStart in doc.GetChildNodes(NodeType.FieldStart, true))
    if (fieldStart.FieldType.Equals(FieldType.FieldMergeField))
        Section currSec = fieldStart.GetAncestor(NodeType.Section) as Section;

I hope, this helps.

Best regards,