Я делаю это для автоматизации преобразования наших документов doc и docx в pdf:
private bool ConvertDocument(string file)
{
object missing = System.Reflection.Missing.Value;
OW.Application word = null;
OW.Document doc = null;
try
{
word = new OW.Application();
word.Visible = false;
word.ScreenUpdating = false;
Object filename = (Object)file;
doc = word.Documents.Open(ref filename, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
doc.Activate();
if (Path.GetExtension(file) == ".docx")
file = file.Replace(".docx", ".pdf");
else
file = file.Replace(".doc", ".pdf");
object fileFormat = OW.WdSaveFormat.wdFormatPDF;
doc.ExportAsFixedFormat(file, OW.WdExportFormat.wdExportFormatPDF, false, OW.WdExportOptimizeFor.wdExportOptimizeForPrint,
OW.WdExportRange.wdExportAllDocument, 1, 1, OW.WdExportItem.wdExportDocumentContent, true, true, OW.WdExportCreateBookmarks.wdExportCreateNoBookmarks,
true, true, false, ref missing);
}
catch(Exception ex)
{
return false;
}
finally
{
if (doc != null)
{
object saveChanges = OW.WdSaveOptions.wdDoNotSaveChanges;
((OW._Document)doc).Close(ref saveChanges, ref missing, ref missing);
doc = null;
}
if (word != null)
{
((OW._Application)word).Quit(ref missing, ref missing, ref missing);
word = null;
}
}
return true;
}
, где OW - это псевдоним Microsoft.Office.Interop.Word.