Office COM Exception occurs on Office to PDF Conversion Foxit PDF Sdk

120 views Asked by At

I'm getting the following exception when trying to integrate Foxit PDF Sdk with my .net core web application.

[Office to PDF conversion error]: (For Office-to-PDF conversion only) Office COM has not been initialized successfully.

I tried the PDF conversion code in a console application then it was working fine. I have tried both .doc and .docx file types and the exception occurs on both files.

This is the conversion logic I used according to the developer guide.

using foxit.common;
using foxit.pdf;
using System.IO;

// Conver Word file to PDF file.
string word_file_path = @"E:\FilesInput\file-doc.doc";
string saved_pdf_path = @"E:\FilesOutput\file-doc.pdf";

try
{
    using (foxit.addon.conversion.Word2PDFSettingData word_convert_setting_data = new foxit.addon.conversion.Word2PDFSettingData())
    {
        foxit.addon.conversion.Convert.FromWord(word_file_path, "", saved_pdf_path, word_convert_setting_data);
    }
}
catch (Exception e)
{
    Console.WriteLine("Exception :", e);
}

Please help me understand what the issue here is. Any help is much appreciated.

Thanks

1

There are 1 answers

0
Eugene Astafiev On

The Considerations for server-side Automation of Office article states the following:

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.

If you deal with Open XML documents only consider using the Open XML SDK, read more about that in the Welcome to the Open XML SDK 2.5 for Office article. If you need to process binary formats you may consider using any third-party components designed for the server-side execution.