• 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

  • 相关阅读:
    在Unix上使用管道压缩exp导出文件
    自制CPU的黑暗历程一
    Error C1189: #error: Please use the /MD switch for _AFXDLL builds
    Redis乐观锁解决高并发抢红包的问题
    PHP分页类
    汇编基础——使用nasm和bochs学习汇编
    数据同步工具DBsync
    完成端口的一些教程
    sdf
    (转)C#(WIN FORM)两个窗体间LISTVIEW值的修改
  • 原文地址:https://www.cnblogs.com/Qiozi/p/7879573.html
Copyright © 2020-2023  润新知