Default font for RTF document

Hi,

I’m creating a new Document object using the Document(Stream, LoadOptions) constructor. The stream I pass as an argument contains plain text. I save it as an RTF and I noticed the result document uses the “Courier New” font. I want a different font used and I’ve read on the forum, at least for Java, that setting the Normal style for the created Document should do the trick. However, in my case it appears to be read-only.

1) Is there a simpler way to change the font of the entire document than using a FontChanger as a DocumentVisitor?
2) How is the default font chosen for the document, if I don’t specify it in any way?


Thanks,
Or


Related forum messages:
- Default font in created RTF document

Hi there,


Thanks
for your inquiry.
ors:

1) Is there a simpler way to change the font of the entire document than using a FontChanger as a DocumentVisitor?

There is no other way to change the font of TXT file. Once you have loaded your text file into Aspose.Words DOM, you can change the font of entire document by using FontChanger, DocumentVisitor or changing the style of each paragraph. Please check the following code example.
ors:

2) How is the default font chosen for the document, if I don’t specify it in any way?

Please note that Aspose.Words mimics the same
behavior as MS Word do. If you open your text file in MS Word, you will get the same output.

Moreover, please read supported features of plain text (txt) import/export from here:
http://www.aspose.com/docs/display/wordsnet/Load+in+the+Plain+Text+Format
http://www.aspose.com/docs/display/wordsnet/Save+in+the+Plain+Text+Format

Hope this answers your query. Please let us know if you have any more queries.

LoadOptions opt = new LoadOptions();

opt.LoadFormat = LoadFormat.Text;

Document doc = new Document(MyDir + "text.txt", opt);

foreach (Run run in doc.GetChildNodes(NodeType.Run, true))

{

run.Font.Name = "Arial";

}

doc.Save(MyDir + "out.rtf");

LoadOptions opt = new LoadOptions();

opt.LoadFormat = LoadFormat.Text;

Document doc = new Document(MyDir + "text.txt", opt);

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))

{

foreach (Run run in para.Runs)

{

run.Font.ClearFormatting();

}

para.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

}

doc.Save(MyDir + “out.rtf”);