Fields

Fields are placeholders, such as page reference numbers, replaced by their corresponding values when the document is rendered for display or print.

Following example demonstrates how to create fields of different field types and with various field arguments and switches.

Fields Screenshot
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = new DocumentModel();

        document.Sections.Add(
            new Section(document,
                new Paragraph(document, "Press Alt + F9 to see field codes!"),
                new Paragraph(document,
                    new Run(document, "Date: "),
                    // { DATE }
                    new Field(document, FieldType.Date),
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Date (formatted): "),
                    // { DATE \@ "dddd, MMMM dd, yyyy"  \* MERGEFORMAT }
                    new Field(document, FieldType.Date, "\\@ \"dddd, MMMM dd, yyyy\"  \\* MERGEFORMAT"),
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Date & Time (formatted): "),
                    // { DATE  \@ "M/d/yyyy h:mm:ss am/pm"  \* MERGEFORMAT }
                    new Field(document, FieldType.Date, " \\@ \"M/d/yyyy h:mm:ss am/pm\"  \\* MERGEFORMAT"))));

        document.Save("Fields.%OutputFileType%");
    }
}
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = New DocumentModel

        ' 1st field: { DATE }
        ' 2nd field: { DATE \@ "dddd, MMMM dd, yyyy"  \* MERGEFORMAT }
        ' 3rd field: { DATE  \@ "M/d/yyyy h:mm:ss am/pm"  \* MERGEFORMAT }
        document.Sections.Add(
            New Section(document,
                New Paragraph(document, "Press Alt + F9 to see field codes!"),
                New Paragraph(document,
                    New Run(document, "Date: "),
                    New Field(document, FieldType.[Date]),
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Date (formatted): "),
                    New Field(document, FieldType.Date, "\@ ""dddd, MMMM dd, yyyy""  \* MERGEFORMAT"),
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Date & Time (formatted): "),
                    New Field(document, FieldType.Date, " \@ ""M/d/yyyy h:mm:ss am/pm""  \* MERGEFORMAT"))))

        document.Save("Fields.%OutputFileType%")

    End Sub

End Module

Check next example or download examples from GitHub.