We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to change Field styling?

I can’t seems to figure out how to change the styling of the field (merge field to be specific)


Please see attachment for example.

Hi Minh,


Thanks for your inquiry. Please try using the following code:

public class FieldMergingCallback : IFieldMergingCallback

{

private DocumentBuilder _documentBuilder;

public void FieldMerging(FieldMergingArgs args)

{

Node currentNode = args.Field.Start;

bool isContinue = true;

while (currentNode != null && isContinue)

{

if (currentNode.NodeType.Equals(NodeType.FieldEnd))

isContinue = false;

if (currentNode.NodeType.Equals(NodeType.Run))

((Run)currentNode).Font.HighlightColor = Color.Blue;

Node nextNode = currentNode.NextPreOrder(currentNode.Document);

currentNode = nextNode;

}

//if (_documentBuilder == null)

// _documentBuilder = new DocumentBuilder(args.Document);

//if (!string.IsNullOrWhiteSpace(args.FieldValue as string))

//{

// _documentBuilder.MoveToMergeField(args.FieldName, false, false);

// _documentBuilder.Font.HighlightColor = Color.Yellow;

// //how to highlight field?

//}

//else

//{

// _documentBuilder.MoveToMergeField(args.FieldName, false, false);

// _documentBuilder.Font.HighlightColor = Color.Red;

// //how to highlight field?

//}

}

public void ImageFieldMerging(ImageFieldMergingArgs args)

{

}

}


Hope, this helps.

Best regards,