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

  • 相关阅读:
    刷题向》关于一道比较优秀的递推型DP(openjudge9275)(EASY+)
    刷题向》一道简单的思路题BZOJ1800(EASY+)
    算法描述》关于二分的两三事
    值得一做》关于一道暴搜BZOJ1024(EASY+)
    写一个C语言的链表记录一下
    qt 创建第一个工程
    windows好用的便签
    .pro文件部分命令详解
    QT 子文件的建立(pri)
    QTAction Editor的简单使用(简洁明了)
  • 原文地址:https://www.cnblogs.com/Qiozi/p/7879573.html
Copyright © 2011-2022 走看看