/// <summary>
    /// 保存word到pdf或xps
    /// </summary>
    public class FileSaveAs
    {
        /// <summary>
        /// 目标文件格式(pdf或xps)
        /// </summary>
        public enum TarFileFormat
        {
            PDF,//PDF格式
            XPS//XPS格式
        }

        #region 保存word到pdf或xps
        /// <summary>
        /// 保存word到pdf或xps
        /// </summary>
        /// <param name="paramSourceDocPath">word文件路径(例如:"C:\\SourceWord.doc")</param>
        /// <param name="paramExportFilePath">目标文件的路径(例如:"C:\\TargetFile.pdf")</param>
        /// <param name="fileFormat">文件格式</param>
        private static void WordSave(object paramSourceDocPath, string paramExportFilePath, TarFileFormat fileFormat)
        {
            Word.Application wordApplication = new Word.Application();
            Word.Document wordDocument = new Word.Document();
            object paramMissing = Type.Missing;
            Word.WdExportFormat paramExportFormat = Word.WdExportFormat.wdExportFormatPDF;
            bool paramOpenAfterExport = false;
            Word.WdExportOptimizeFor paramExportOptimizeFor = Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
            Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;
            int paramStartPage = 0;
            int paramEndPage = 0;
            Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;
            bool paramIncludeDocProps = true;
            bool paramKeepIRM = true;
            Word.WdExportCreateBookmarks paramCreateBookmarks = Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
            bool paramDocStructureTags = true;
            bool paramBitmapMissingFonts = true;
            bool paramUseISO19005_1 = false;

            //格式
            switch (fileFormat)
            {
                case TarFileFormat.PDF:
                    {
                        paramExportFormat = Word.WdExportFormat.wdExportFormatPDF;
                    }
                    break;
                case TarFileFormat.XPS:
                    {
                        paramExportFormat = Word.WdExportFormat.wdExportFormatXPS;
                    }
                    break;
                default:
                    {
                        paramExportFormat = Word.WdExportFormat.wdExportFormatPDF;
                    }
                    break;
            }

            try
            {
                // Open the source document.
                wordDocument = wordApplication.Documents.Open(
                    ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing);

                // Export it in the specified format.
                if (wordDocument != null)
                    wordDocument.ExportAsFixedFormat(paramExportFilePath,
                        paramExportFormat, paramOpenAfterExport,
                        paramExportOptimizeFor, paramExportRange, paramStartPage,
                        paramEndPage, paramExportItem, paramIncludeDocProps,
                        paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                        paramBitmapMissingFonts, paramUseISO19005_1,
                        ref paramMissing);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                // Close and release the Document object.
                if (wordDocument != null)
                {
                    wordDocument.Close(ref paramMissing, ref paramMissing,
                        ref paramMissing);
                    wordDocument = null;
                }

                // Quit Word and release the ApplicationClass object.
                if (wordApplication != null)
                {
                    wordApplication.Quit(ref paramMissing, ref paramMissing,
                        ref paramMissing);
                    wordApplication = null;
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }

        /// <summary>
        /// 保存word到pdf或xps
        /// </summary>
        /// <param name="paramSourceDocPath">word文件路径(例如:"C:\\SourceWord.doc")</param>
        /// <param name="paramExportFilePath">目标文件的路径(例如:"C:\\TargetFile.pdf")</param>
        /// <param name="fileFormat">文件格式</param>
        /// <returns>true,成功;false,失败</returns>
        public static bool WordSaveAs(object paramSourceDocPath, string paramExportFilePath, TarFileFormat fileFormat)
        {
            bool isSuccess = false;
            try
            {
                WordSave(paramSourceDocPath, paramExportFilePath, fileFormat);
                isSuccess = true;
            }
            catch (System.Exception ex)
            {
                //save error;
            }

            return isSuccess;
        }
        #endregion
    }