Easy code and solution using Microsoft.Office.Interop.Word
to converd WORD in PDF
using Word = Microsoft.Office.Interop.Word;
private void convertDOCtoPDF()
{
object misValue = System.Reflection.Missing.Value;
String PATH_APP_PDF = @"c:\..\MY_WORD_DOCUMENT.pdf"
var WORD = new Word.Application();
Word.Document doc = WORD.Documents.Open(@"c:\..\MY_WORD_DOCUMENT.docx");
doc.Activate();
doc.SaveAs2(@PATH_APP_PDF, Word.WdSaveFormat.wdFormatPDF, misValue, misValue, misValue,
misValue, misValue, misValue, misValue, misValue, misValue, misValue);
doc.Close();
WORD.Quit();
releaseObject(doc);
releaseObject(WORD);
}
Add this procedure to release memory:
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
//TODO
}
finally
{
GC.Collect();
}
}