I have this snippet of code that should open a docx file and I would like to save it as pdf.
Unfortunately no error is thrown but the PDF is not saved.
Any hint on how to save it?
var wordApplication = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDocument = null;
try
{
wordDocument = wordApplication.Documents.Open(docPath + ".docx");
if (wordDocument != null)
wordDocument.SaveAs2(docPath + ".pdf", Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF);
//wordDocument.ExportAsFixedFormat(docPath + ".pdf", Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
else throw new Exception("CUSTOM ERROR: Cannot Open Word Application");
}
catch (Exception ex)
{
new Exception("CUSTOM ERROR" + ex.Message);
}