一、基于Office的解决方案
1.获取指定文件夹下的所有word文件
static void Main(string[] args) { try { Console.WriteLine("------------开始---------------"); string path = @"XXXXXXXXXXXXXXXXXX";//word所在的文件夹 string SaveFile = @"XXXXXXXXXXXXXXXXXX";//保存路径 DirectoryInfo di = new DirectoryInfo(path); Console.Write("请输入指定名称(不输入获取所有文件):"); string filename = Console.ReadLine(); //找到该目录下的文件 FileInfo[] FileList; if (!string.IsNullOrEmpty(filename)) { FileList = di.GetFiles(filename); } else { FileList = di.GetFiles(); } int Success = 0; int Fail = 0; foreach (FileInfo item in FileList) { string Filescr = SaveFile + item.Name; bool bFlagPdf = Common.FileWordToPdf.ConvertToPdf(item.FullName, Filescr); if (bFlagPdf == true) { Success++; Console.WriteLine(item.Name + " ----- 转换成功"); } else { Fail++; Console.WriteLine(item.Name + " ----- 转换失败"); } } Console.WriteLine("------------本轮协议生成结束,结果如下:---------------"); Console.WriteLine("需生PDF共:" + FileList.Length + "份"); Console.WriteLine("成功PDF共:" + Success + "份协议"); Console.WriteLine("失败PDF共:" + Fail + "份协议"); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.ToSt.........