Some fonts are replaced with Calibri in the final doc

Hi,
I am setting the embedtruetypefonts = true while creating the Word document from the dotx template. But some fonts are replaced with Calibri in the final doc. Can you please help me on this?

Thanks
Jithin V P

@jithin.p Could you please attach your problematic input and output documents here for testing? We will check the issue and provide you more information.

Hi,
Thanks for the reply. Due to data policy, I am not allowed to share the documents. But I can describe the issue with attached screenshots. The source file extension is “dotx” and destination file extension is “docx”. Below are the code from ASPOSE that i used to generate the docx file.

Document body = outputDoc;

body.FirstSection.Remove();
body.FirstSection.PageSetup.RestartPageNumbering = true;
body.FirstSection.PageSetup.PageStartingNumber = 1;


CoverOutPut.LastSection.Remove();

ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.KeepSourceNumbering = true;
importFormatOptions.IgnoreHeaderFooter = false;

Document finaleDocument = new Document(templatePath + "NewDocument.docx");
body.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
CoverOutPut.AppendDocument(body, ImportFormatMode.KeepSourceFormatting, importFormatOptions);
CoverOutPut.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
//  CoverOutPut.FirstSection.Remove();

finaleDocument.AppendDocument(CoverOutPut, ImportFormatMode.KeepSourceFormatting, importFormatOptions);
finaleDocument.FieldOptions.FieldUpdateCultureSource = FieldUpdateCultureSource.FieldCode;
finaleDocument.MailMerge.CleanupOptions = Aspose.Words.MailMerging.MailMergeCleanupOptions.RemoveUnusedRegions |
Aspose.Words.MailMerging.MailMergeCleanupOptions.RemoveUnusedFields |
Aspose.Words.MailMerging.MailMergeCleanupOptions.RemoveStaticFields |
Aspose.Words.MailMerging.MailMergeCleanupOptions.RemoveEmptyParagraphs |
Aspose.Words.MailMerging.MailMergeCleanupOptions.RemoveContainingFields;
cloneBuildinPropeerties(body, finaleDocument);

finaleDocument.RemoveMacros();
finaleDocument.RemoveSmartTags();
//finaleDocument.RemoveUnusedResources();
finaleDocument.Cleanup();
finaleDocument.UpdateFields();

finaleDocument.FirstSection.Remove();
OoxmlSaveOptions opt = new OoxmlSaveOptions(SaveFormat.Docx);
opt.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;
if (create_folder == true)
{
    if (!Directory.Exists(dataDirectory + folder_name))
        Directory.CreateDirectory(dataDirectory + folder_name);
    dataDirectory = dataDirectory + folder_name + "\\";
}

//69493 Jithin
if (embedFontsLocal == "1")
{
    finaleDocument.FontInfos.EmbedTrueTypeFonts = true;
    finaleDocument.FontInfos.EmbedSystemFonts = true;
    finaleDocument.FontInfos.SaveSubsetFonts = true;
}
else
    finaleDocument.FontInfos.EmbedTrueTypeFonts = false;
//69493 Jithin

finaleDocument.Save(dataDirectory + fileNameSave, opt);

dataDirectory = dataDirectory + "/" + fileNameSave;

Source

Dest

@jithin.p Unfortunately, without actual documents we cannot test the scenario and reproduce the problem on our side. It is safe to attach documents in the forum, only you as a topic starter and Aspose staff can access the attachments.

Hi,

Attached are the documents.

Input_1.docx (9.1 MB)

Output_1.docx (211.7 KB)

Thanks
Jithin V P

@jithin.p Thank you for additional information. The problem is not reproducible with the following simple code:

Document doc = new Document(@"C:\Temp\Input_1.docx");
doc.MailMerge.Execute(new string[] { "TODAY" }, new object[] { "Test Value" });
doc.Save(@"C:\Temp\out.docx");

As I can see Input_1.docx has embedded fonts. In your code you are appending documents to another document. Most likely the target document does not have the embedded fonts. But even in this case the problem is not reproducible on my side:

Document doc = new Document(@"C:\Temp\Input_1.docx");
doc.MailMerge.Execute(new string[] { "TODAY" }, new object[] { "Test Value" });

Document dst = new Document();
dst.RemoveAllChildren();
dst.AppendDocument(doc, ImportFormatMode.KeepSourceFormatting);

dst.Save(@"C:\Temp\out.docx");

Could you please create a simple console application that will allow us to reproduce the problem on our side?

Hi,
In your code you are appending documents to another document. Most likely the target document does not have the embedded fonts.
You are correct. While appending the document, it is losing the fonts. So what do I need to do apart from embedtruetypefonts to preserve the style?

@jithin.p Could you please create a simple console application that will allow us to reproduce the problem on our side? We will check the issue and provide you more information.

Hi,
The issue is happening while appending the document. So I changed the code ImportFormatMode. KeepSourceFormatting to ImportFormatMode. KeepDifferentStyles. It fixed the issue that I mentioned in the last post. But I found another issue in the same document, like the Calibri in the source document is changed to Calibri Light in the same font family in the final document. It is also happening while appending the document. Do you have any suggestions to fix this issue? Please help me? It will be greatful.

Thanks
Jithin V P

@jithin.p Could you please attach your problematic documents and code that will allow us to reproduce the problem on our side? Unfortunately, it is impossible to analyze the issue without ability to reproduce it on our side.

Hi,
Attached are the documents, and below is the code that you used to reproduce the issue. Please check.
Code

Document temp = new Document(@"Input_1.docx");
Document OutPut = new Document(@"Output_1.docx");
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.KeepSourceNumbering = true;
importFormatOptions.IgnoreHeaderFooter = false;

temp.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
OutPut.AppendDocument(temp, ImportFormatMode.KeepDifferentStyles, importFormatOptions);
OutPut.Save(@"FinalOutPut.docx");

Input_1.docx (9.1 MB)

Output_1.docx (23.3 KB)

Thanks
Jithin V P

@jithin.p
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28600

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi,
We are using the paid version of ASPOSE in our company. So can you please fix this ASAP? Because it is an issue reported by our client.

Thanks
Jithin V P

@jithin.p We will keep you updated and let you know once the issue is resolved or we have more information for you. Meanwhile, you can try using KeepSourceFormatting import format mode. In this case the font is not changed.

Hi,
I changed the KeeepSourceFormating ro KeepDifferentStyles to fix the issue “Some fonts are replaced with Calibri in the final doc - #3 by jithin.p”.

Thanks
Jithin V P

1 Like

@jithin.p We will keep you updated and let you know once the issue is resolved.