Free Support Forum - aspose.com

Font changing

Good day.

I have two problems with Aspose.Word:

1. I use template with Tahoma font. After mail merging and storing the result I have Times New Roman font instead. When I use Arial font instead Tahoma, everything works OK - I have Arial in the result.

2. I tryed to solve the problem above by setting Tahoma font to all document, but I have not found the way to do it. As I understand, the only way to set a range’s font is using DocumentBuilder class. But I already have a document. How can I change a range’s font in the document - result of merging? Can I open an existing document and create a new one changing the font using enumeration of sections, paragraphs or something else? Or maybe there is more comfortable way?

Thank you,
Serge.

Please send the document to me to word@aspose.com. So far we have this working fine in our tests.

I’ll prepare an example project (with Dataset) and send to you the doc tomorrow. But what about the second question? I think I’ll need posibility to change font in the next tasks.

Serge.

I just need the document in this case, don’t need code or data.

It is not really possible to change font of existing text in the document. Range class provides limited functionality at the moment while DocumentBuilder is used mainly to insert new text and formatting. We are working on adding more content manipulation features like this, but at this stage I cannot tell when it will be possible to release it.

Sent. Subject is "Tahoma template example"

Serge.

Hi Serge,

It works okay for me. I open your file, mail merge and save and all text remains Tahoma.

Please make sure you are using latest version of Aspose.Word. If that does not help, let me know where exactly Tahoma gets reset or send me a copy of problem document.

romank wrote:
It works okay for me.


Hi Roman,

Sorry, I was not correct. I prepare a compex report, create few documents using mail mergin and then combine the documents using this method:


private void MergeFiles(ArrayList files, string targetFileName)

{

Document document;

Document resultDocument = new Document();

resultDocument.Sections.Clear();

foreach (string fileName in files)

{
document = new Document(fileName);

foreach (Section section in document.Sections)

resultDocument.Sections.Add(section.Clone());

}

resultDocument.Save(targetFileName);

}



I have just checked an intermediate document. Yes, it contains correct font, sorry. But the result of combining still contains Times New Roman when I use Tahoma in the templates and Arian when I use Arial in templates.

Regards,
Serge

Well, if copying between documents is involved, then I can explain what happens.

You have Normal style in one document with Tahoma font and you have Normal style in another document with Times New Roman font. When you copy text from one document to another the style from the original document does not replace or change the style in the destination document. Hence your text becomes Times New Roman as per the Normal style in this document.

To workaround the problem you can either:

1. Change Normal style in the source document to be back to use default Times New Roman font and apply Tahoma font to all text using direct formatting (select text and select Tahoma). Direct formatting on text will be copied to the new document too and you will retain Tahoma.

2. Change Normal style in the destination document to have Tahoma font if this is what you use across all your documents.

romank wrote:
2. Change Normal style in the destination document to have Tahoma font if this is what you use across all your documents.


This helps.

Thank you very much, Roman.