I have two methods as below
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
switch (e.FieldName)
{
case "Description":
if (!(e.FieldValue == null || e.FieldValue == DBNull.Value || e.FieldValue.ToString() == String.Empty))
{
mbuilder.MoveToMergeField(e.FieldName, false, false);
MemoryStream stream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(e.FieldValue.ToString()));
LoadOptions options = new LoadOptions(LoadFormat.Rtf, null, null);
Document rtf = new Document(stream, options);
Paragraph pa = mbuilder.CurrentParagraph;
Style style = null;
style = mbuilder.Document.Styles[e.TableName];
InsertDocument(pa, rtf.FirstSection, ImportFormatMode.UseDestinationStyles, style, false);
mbuilder.MoveToMergeField(e.FieldName);
}
}
}
and
static void InsertDocument(Node insertAfterNode, Section srcSection, ImportFormatMode importMode, Style style, bool insertBeforeNodeOption)
{
// We will be inserting into the parent of the destination paragraph.
int i = 0;
CompositeNode dstStory = insertAfterNode.ParentNode;
// This object will be translating styles and lists during the import.
srcSection.Document.Styles["Normal"].Font.Name = insertAfterNode.Document.Styles["Normal"].Font.Name;
NodeImporter importer = new NodeImporter(srcSection.Document, insertAfterNode.Document, importMode);
// Loop through all sections in the source document.
//foreach (Section src in srcSection)
//{
// //src.
//}
{
// Loop through all block level nodes (paragraphs and tables) in the body of the section.
foreach (Node srcNode in srcSection.Body)
{
// Let’s skip the node if it is a last empty paragraph in a section.
if (srcNode.NodeType.Equals(NodeType.Paragraph))
{
Paragraph para = (Paragraph)srcNode;
//if (style != null)
// para.ParagraphFormat.Style = style;
if (para.IsEndOfSection && !para.HasChildNodes)
continue;
}
//foreach (Style styl in srcNode.Document.Styles)
//{
// if (style!= null)
// {
// styl.Font.Name = "Calibri";
// }
//}
// This creates a clone of the node, suitable for insertion into the destination document.
Node newNode = importer.ImportNode(srcNode, true);
if (style != null)
{
if (newNode.NodeType.Equals(NodeType.Paragraph))
{
Paragraph pp = (Paragraph)newNode;
pp.ParagraphFormat.Style = style;
}
}
// Insert new node after the reference node.
// dstStory.AppendChild(newNode);
if (insertBeforeNodeOption && i == 0)
{
dstStory.InsertBefore(newNode, insertAfterNode);
i++;
}
else
dstStory.InsertAfter(newNode, insertAfterNode);
insertAfterNode = newNode;
}
}
}
I have set my destination document to arial and works for most except for the rtf data it keeps the format of the rtf but i have used UseDestinationStyles. When I look in the style that am passing i see the paragraFormat has layers of styles and the first layer show my font set to arial and the subsequent layers have a different font calibri , and I would like to know how these layer fonts are set
I.e ParagraphFormat.Style.Font.StyleName is Arial but
ParagraphFormat.Style.Font.Style.Font.StyleName is calibri
ParagraphFormat.Style.Font.Style.Style.Font.Style.Font is calibri
Any help will be greatly appreciated