I have the following 2 methods in my code to pass RTF data to my document.
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.
Node afterNode = insertAfterNode;
NodeImporter importer = new NodeImporter(srcSection.Document, afterNode.Document, importMode);
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 =srcNode as Paragraph;
if (para!=null && para.IsEndOfSection && !para.HasChildNodes)
break;
Node newNode = importer.ImportNode(srcNode, true);
if (insertBeforeNodeOption && i == 0)
{
dstStory.InsertBefore(newNode, insertAfterNode);
i++;
}
else
dstStory.InsertAfter(newNode, insertAfterNode);
insertAfterNode = newNode;
}
}
}
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
switch (e.FieldName)
{
case “MealBasisNote”:
case “Description”:
case “GuestNote”:
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;
if (mbuilder.Document.Styles[e.TableName] != null)
style = mbuilder.Document.Styles[e.TableName];
InsertDocument(pa, rtf.FirstSection, ImportFormatMode.KeepSourceFormatting, style, false);
mbuilder.MoveToMergeField(e.FieldName);
}
break;
}
}
The code is meant to keep source formatting and it does work randomly, the other rtf it gives the wrong fonts
i have attached two rtf files
correct font , has the rtf displaying the correct font Cambria
and wrong font , the rtf displays times roman instead of Calibri. The rtf clear shows the font and which font is used on the paragraph.
Regards
Travelogic
Hi Phillip,
Thanks for the response
My issue is centred on the following code:
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);
when I save my doc rtf and having inputted the rtf i mentioned as wrong rtf the doc returns attached rtf.docx.
Inorder for you to test use below .
string wrongRtf = "{\rtf1\deff0{\fonttbl{\f0 Times New Roman;}{\f1 Calibri;}}{\colortbl\red0\green0\blue0 ;\red0\green0\blue255 ;}{*\listoverridetable}{\stylesheet {\ql\cf0 Normal;}{*\cs1\f1\fs20\cf0 Default Paragraph Font;}{*\cs2\sbasedon1\cf0 Line Number;}{*\cs3\ul\cf1\ulc1 Hyperlink;}}\sectd\pard\plain\ql{\f1\fs20\cf0 The }{\f1\fs20\cf0 suite }{\f1\fs20\cf0 also includes private transfers.}\f1\fs20\par}"
MemoryStream stream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(wrongRtf));
LoadOptions options = new LoadOptions(LoadFormat.Rtf, null, null);
Document rtf = new Document(stream, options);
Try saving document rtf and you will see that it will be times new roman instead of calibri, what could be causing that ?
Hi Phillip,
Hi there
Any news on this .
Regards
Travelogic
Hi Travelogic,
The issues you have found earlier (filed as WORDSNET-8542) have been fixed in this .NET update and this Java update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.