Aspose.Word MailMerge set font in paragraph

Deadly 提交于 2019-12-11 10:19:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!