我有一个 asp.net 应用程序,它使用 Microsoft.Office.Interop.Word.ApplicationClass 将上传的 ms doc 转换为 pdf。它在我的本地机器上工作正常,但它在部署的 IIS 服务器上不起作用。是否有任何可执行权限是需要得到输出。
错误是:检索具有 CLSID {000209FF-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败,原因是以下错误:80070005。
我的代码如下:
public class Word2Pdf
{
private Microsoft.Office.Interop.Word.ApplicationClass MSWordDoc;
object UnknownType = Type.Missing;
public string Word2PdfCOnversion(object InputLocation, object OutputLocation)
{
string result;
try
{
//if (MSWordDoc == null)
MSWordDoc = new Microsoft.Office.Interop.Word.ApplicationClass();
MSWordDoc.Visible = false;
MSWordDoc.Documents.Open(ref InputLocation, //Input File Name Location
ref UnknownType, // Conversion Conformation
ref UnknownType, // Set ReadOnly Property
ref UnknownType, // Add to the Recent Files
ref UnknownType, // Document Password Setting
ref UnknownType, // Password Templete
ref UnknownType, // Revert
ref UnknownType, // Write Password to Document
ref UnknownType, // Write Password Template
ref UnknownType, // File Format
ref UnknownType, // Encoding File
ref UnknownType, // Visibility
ref UnknownType, // To Open or Repair
ref UnknownType, // Document Direction
ref UnknownType, // Encoding Dialog
ref UnknownType); // XML Text Transform
MSWordDoc.Application.Visible = false; // To Invisible the Word Document
MSWordDoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize; // Minimize the Opened Word File.
object SavePDFFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
MSWordDoc.ActiveDocument.SaveAs(ref OutputLocation, //Output File Location
ref SavePDFFormat, // File Format
ref UnknownType, // Comment to PDF File
ref UnknownType, // Password
ref UnknownType, // Add to Recent File
ref UnknownType, // Write Password
ref UnknownType, // ReadOnly Propert
ref UnknownType, // Original Font Embeding
ref UnknownType, // Save Picture
ref UnknownType, // Saving Form Datas
ref UnknownType, // Save as AOVE Letter
ref UnknownType, // Encoding
ref UnknownType, // Inserting Line Breakes
ref UnknownType, // Allow Substitution
ref UnknownType, // Line Ending
ref UnknownType); // Add BiDi Marks
result = "Success";
}
catch (Exception)
{
result = "Error";
}
finally
{
if (MSWordDoc == null) { }
else { MSWordDoc.Documents.Close(ref UnknownType, ref UnknownType, ref UnknownType); }
MSWordDoc.Quit(ref UnknownType, ref UnknownType, ref UnknownType);
}
return result;
}
}