If Interop.Word is run under IIS, custom font is not embedded in result DOCX file after saving

253 Views Asked by At

I have a quite simple code which is saving MS Word documents using Microsoft.Office.Interop.Word which uses MS Word with COM.

Object fileName = docPathDocX;
Object tr = true;
Document document = _application.Documents.Open(ref fileName);
document.SaveAs(FileName: docPathDocXEmbedFonts, EmbedTrueTypeFonts: tr);

Also I use in a .docx documents a custom .ttf font which is installed for all Windows users. When I run this code under Visual Studio all work perfect. I have .docx document with embedded custom font. On the other hand, when this code is run under IIS (MVC application) the custom font is not embedded although other system fonts are embed.

I suspect the reason could be lack of IIS user rights, but my efforts in this area haven't bring any results yet.

1

There are 1 best solutions below

2
On

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

Read more about that in the Considerations for server-side Automation of Office article.

If you deal with open XML documents only you may consider using the Open XML SDK 2.5 for Office instead.