If you are interested, here’s C# code to get the active Word document and export it as PDF. Warning! The code will close Word without saving after the export. Don’t run the workflow if you have an important and unsaved document.
// Remember to install the Microsoft.Office.Interop.Word package.
// Attach to a running Word instance, save the active document as PDF and close Word.
// Warning: It will overwrite the PDF file if it already exists
try {
Microsoft.Office.Interop.Word.Application wordApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application") as Microsoft.Office.Interop.Word.Application;
wordApp.ActiveDocument.ExportAsFixedFormat(in_PdfPath, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
//Close document
wordApp.ActiveDocument.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges,
Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat, false);
// Close application
wordApp.Quit();
out_Success = true;
}
catch (Exception e)
{
// Either no Word instance running or the export to PDF failed.
System.Console.WriteLine("Error: " + e.ToString());
out_Success = false;
}
WordExportAsPDF.xaml (6.3 KB)