zoukankan      html  css  js  c++  java
  • Word 转 PDF

    1. 配置 Com+;

    2. 配置 IIS;

    3. 从网上捡 代码;

    配置 Com+ 权限

    在“开始”-”运行“输入 命令”comexp.msc -32“ 打开Component Services,  然后依次左侧菜单 Component Services --> Computers --> My Computer --> DCOM Config ;

    找到 Microsoft Word 97- 2003 文档, 按右键打开属性窗口; 

      1,设置Security, 添加用户访问本地权限。

      2,设置Identity ,改为交互用户。

    配置 IIS。 在线程池里,配置项目的高级属性, Identity 的值改为 LocalSystem

    从网上捡一段word 转Pdf 代码 (忘了记录地址,要跟作者说声抱歉。)

    需要引用DLL: Microsoft.Office.Interop.Word.dll

            /// <summary>
            /// Word转换Pdf
            /// </summary>
            /// <param name="sourcePath"></param>
            /// <param name="targetPath"></param>
            /// <param name="exportFormat"></param>
            /// <returns></returns>
            public static bool Convert(string sourcePath, string targetPath, Microsoft.Office.Interop.Word.WdExportFormat exportFormat)
            {
                bool result;
                object paramMissing = Type.Missing;
                Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
                Microsoft.Office.Interop.Word.Document wordDocument = null;
                try
                {
                    object paramSourceDocPath = sourcePath;
                    string paramExportFilePath = targetPath;
    
                    Microsoft.Office.Interop.Word.WdExportFormat paramExportFormat = exportFormat;
                    bool paramOpenAfterExport = false;
                    Microsoft.Office.Interop.Word.WdExportOptimizeFor paramExportOptimizeFor =
                            Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
                    Microsoft.Office.Interop.Word.WdExportRange paramExportRange = Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument;
                    int paramStartPage = 0;
                    int paramEndPage = 0;
                    Microsoft.Office.Interop.Word.WdExportItem paramExportItem = Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent;
                    bool paramIncludeDocProps = true;
                    bool paramKeepIRM = true;
                    Microsoft.Office.Interop.Word.WdExportCreateBookmarks paramCreateBookmarks =
                            Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
                    bool paramDocStructureTags = true;
                    bool paramBitmapMissingFonts = true;
                    bool paramUseISO19005_1 = false;
    
                    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);
    
                    if (wordDocument != null)
                        wordDocument.ExportAsFixedFormat(paramExportFilePath,
                                paramExportFormat, paramOpenAfterExport,
                                paramExportOptimizeFor, paramExportRange, paramStartPage,
                                paramEndPage, paramExportItem, paramIncludeDocProps,
                                paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                                paramBitmapMissingFonts, paramUseISO19005_1,
                                ref paramMissing);
                    result = true;
                }
                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;
                    }
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                return result;
            }

    搞定,,BTW:  一个15K 的word文件,转成pdf后,,瞬间肥胖,达245K

  • 相关阅读:
    数据仓库的直白概述
    Google准实时数据仓库Mesa(一)
    活动预告丨易盾CTO朱浩齐将出席2018 AIIA大会,分享《人工智能在内容安全的应用实践》
    3招搞定APP注册作弊
    【0门槛】PR稿的自我修养
    Hive中文注释乱码解决方案(2)
    Hive中文注释乱码解决方案
    网易考拉Android客户端网络模块设计
    有运气摇号来不及挑选?网易有数帮你科学选房
    selenium下拉框踩坑埋坑
  • 原文地址:https://www.cnblogs.com/Qiozi/p/7879573.html
Copyright © 2011-2022 走看看