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

Free Support Forum - aspose.com

RTF wrong font showing on rendering document

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 your inquiry. I have opened the wrong font.txt in MS Word and it shows the Calibri. I have attached the RTF document with this post. MS Word 2010 detect the font as Calibri. Please see the attached image for detail.

If you still face problem, please attach your input template document along with RTF document here for testing? I will investigate the issue on my side and provide you more information.

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,


Thanks for sharing the detail. I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-8542 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi there

Any news on this .

Regards
Travelogic

Hi Travelogic,


Thanks for your inquiry.

I have verified the status of your issue from our issue tracking system and like to share with you that your issue is under analysis phase. I am afraid, I cannot provide you any reliable estimate at the moment. Once your issue is analyzed, we will then be able to provide you an estimate.

Thank you for your patience and understanding.

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.