How to enter Superscript in a Bookmark

Is it possible to set bookmark text with a portion of the text being superscript? I’m guessing not, but I’d love to be wrong in this instance.

On a similar note how do I merge superscript as part of a single field in a mail merge?

Hi Keith,

Thanks for your inquiry.

Keith:
Is it possible to set bookmark text with a portion of the text being superscript? I’m guessing not, but I’d love to be wrong in this instance.

Sure, you can set the Font.Superscript property to true. The text of the Run will be formatted as superscript. Please try running the following code snippet:

DocumentBuilder builder = new DocumentBuilder();
builder.StartBookmark("bm");
builder.Write("Some text inside Bookmark");
builder.Font.Superscript = true;
builder.Write("superscripted text");
builder.Font.Superscript = false;
builder.Write(" again normal text");
builder.EndBookmark("bm");
builder.Document.Save(@"C:\Temp\out.docx");

I hope, this helps.

Best Regards,

Hi Keith,

*Keith:

> On a similar note how do I merge superscript as part of a single field in a mail merge ? *

I have attached sample input/output documents. The following code demonstrates the usage of IFieldMergingCallback.FieldMerging method to achieve what you’re looking for:

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.FieldMergingCallback = new HandleMergeImageField();
doc.MailMerge.Execute(new string[]
{
    "mf"
}, new object[]
{
    "Some field value superscripeted"
});
doc.Save(@"C:\Temp\out.docx");

private class HandleMergeImageField: IFieldMergingCallback
{
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)
    {
        if (args.FieldName.Equals("mf"))
        {
            DocumentBuilder builder = new DocumentBuilder(args.Document);
            builder.MoveToMergeField(args.DocumentFieldName);
            builder.Write((string) args.FieldValue);
            builder.Font.Superscript = true;
            builder.Write("1");
            args.Text = string.Empty;
        }
    }
    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
    {
        // Do nothing.
    }
}

I hope, this helps.

Best Regards,

Awesome, thanks!!

Hi Keith,

Thanks for your inquiry. Please let us know any time you have any further queries. We’re always glad to help you.

Best Regards,