• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

关于Asp.Net调用Office组件将Word文件转换为Pdf文件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1、首先安装 Microsoft Office 2007加载项:Microsoft Save as PDF-简体中文版:下载地址:

http://download.microsoft.com/download/3/8/8/388812b2-0d3f-474e-a7ef-b095d3d0d3cd/SaveAsPDF.exe

        public int ConvertWordToPdfByPlugin(string sourceFilePath, string destFilePath)
        {
            int result = 0;
            object paramMissing = Type.Missing;
            Word.ApplicationClass wordApplication = new Word.ApplicationClass();
            Word.Document wordDocument = null;
            try
            {
                object paramSourceFilePath = sourceFilePath;
                Word.WdExportFormat paramExportFormat = Word.WdExportFormat.wdExportFormatPDF;
                wordDocument = wordApplication.Documents.Open(
                                        ref paramSourceFilePath, 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);
                if (wordDocument != null)
                {
                    Word.WdExportOptimizeFor paramExportOptimizeFor =
                        Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
                    Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;
                    Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;
                    Word.WdExportCreateBookmarks paramCreateBookmarks =
                        Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
                    wordDocument.ExportAsFixedFormat(destFilePath,
                        paramExportFormat, false,
                        paramExportOptimizeFor, paramExportRange, 0,
                        0, paramExportItem, true,
                        true, paramCreateBookmarks, true,
                        true, false,
                        ref paramMissing);
                }
                else
                {
                    ScriptUtil.Alert("读取源word文件出错!");
                }
            }
            catch (Exception ex)
            {
                LogUtil.WriteLog(ex);
                result = 1;
            }
            finally
            {
                if (wordDocument != null)
                {
                    wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
                    wordDocument = null;
                }
                if (wordApplication != null)
                {
                    wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
                    wordApplication = null;
                }
            }

            return result;
        }

  


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ASP.NETCore导入导出Excelxlsx文件发布时间:2022-07-10
下一篇:
asp.netMVC4.0将数据导出excel表格发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap