问题
In FieldMergingCallback.FieldMerging and I set font to all Runs in Node =>
public void FieldMerging(FieldMergingArgs args)
{
if (args.FieldValue.ToString().Length > 100)
{
var node = args.Field.Start.ParentNode.ParentNode;
if (node is Shape)
{
var runlist = node.GetChildNodes(NodeType.Run, true);
foreach (Run run in runlist)
{
run.Font.Size = 6;
}
}
}
}
But in result pdf is:
Why is the font smaller than the third word?
回答1:
Before performing mail merge, you can use the following code to apply same formatting to all Run nodes inside a merge field.
Document doc = new Document("D:\\temp\\input.docx");
foreach (Field field in doc.Range.Fields)
{
if (field.Type.Equals(Aspose.Words.Fields.FieldType.FieldMergeField))
{
Node currentNode = field.Start;
bool isContinue = true;
while (currentNode != null && isContinue)
{
if (currentNode.NodeType.Equals(NodeType.FieldEnd))
{
FieldEnd end = (FieldEnd)currentNode;
if (end == field.End)
isContinue = false;
}
if (currentNode.NodeType.Equals(NodeType.Run))
{
Run run = ((Run)currentNode);
run.Font.Size = 6;
}
Node nextNode = currentNode.NextPreOrder(currentNode.Document);
currentNode = nextNode;
}
}
}
doc.Save("D:\\Temp\\18.6.docx");
Hope, this helps. I work with Aspose as Developer Evangelist.
来源:https://stackoverflow.com/questions/51043422/aspose-word-mailmerge-set-font-in-paragraph