方法一:Microsoft.Office.Interop.Word另存

/// <summary>

/// 将word保存为pdf文件
        /// </summary>
        /// <param name="wordFileName">完整的文件名</param>
        /// <param name="savePath">保存的路径</param>
        /// <returns>保存后的文件名</returns>
        public string WordToPdf(string wordFileName, string savePath = null)
        {
            //宣告WORD物件
            Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
            Type wordType = word.GetType();
            string wordSaveFileName = "";
            try
            {
                Microsoft.Office.Interop.Word.Documents docs = word.Documents;
                //打開WORD檔
                Type docsType = docs.GetType();
                word.DisplayAlerts = WdAlertLevel.wdAlertsNone;
                word.Visible = false;
                object oMissing = System.Reflection.Missing.Value;
                object filepath = wordFileName;
                Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(ref filepath, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                //(Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { wordFileName, true, true });
                //將開啟檔案轉存為HTML檔 
                Type docType = doc.GetType();
                wordSaveFileName = Path.GetFileName(wordFileName).Replace(Path.GetExtension(wordFileName), ".pdf");
                string saveFile = "";
                if (String.IsNullOrEmpty(savePath))
                {
                    saveFile = wordFileName.Replace(Path.GetExtension(wordFileName), ".pdf");
                }
                else
                {
                    saveFile = savePath + "\\" + wordSaveFileName;
                }
                docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFile, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF });
                docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
            }
            finally
            {
                //退出 Word 
                wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
            }
            return wordSaveFileName;

}

方法二:Aspose.Words

Aspose.Words.Document document = new Aspose.Words.Document(fileName);

document.Save(fileName.Replace(Path.GetExtension(fileName), ".pdf"), SaveFormat.Pdf);

word保存为pdf文件相关推荐

  1. 计算机一级保存文件,计算机等级一级技巧:Word文档保存为PDF文件

    全国计算机等级考试(National Computer Rank Examination,简称NCRE)是由国家教育部考试中心主办,面向社会,用于考查应试人员计算机操作.理论应用知识与技能的全国性计算 ...

  2. 神奇的pdfkit工具——将字符串保存为pdf文件

    神奇的pdfkit工具--将字符串保存为pdf文件 1.安装工具包 pip install pdfkit 2.上干货 import pdfkitdef create_pdf(str_data, to_ ...

  3. Typora基础用法:pandoc安装,导入导出word文档,pdf文件。设置图片目录

    点击观看B站视频 Typora基础用法:pandoc安装,导入导出word文档,pdf文件.设置图片目录. 一. pandoc安装 首次安装完typora,是没法导入的,需要安装pandoc 选择[请 ...

  4. java excel转pdf linux,从JAVA直接读取EXCEL、WORD并生成PDF文件

    从JAVA直接读取EXCEL.WORD并生成PDF文件 1.操作EXCEL和WORD文件 使用JAVA从EXCEL.WORD文件中读写数据,可以使用http://jexcelapi.sourcefor ...

  5. 计算机证书图片无法保存,win7电脑JPG文件怎么保存为PDF文件

    很多时候我们需要将win7下的各种文本文件转换为PDF格式的文件,那么win7电脑JPG文件怎么保存为PDF文件呢?学习啦小编分享了win7电脑JPG文件保存为PDF文件的方法,希望对大家有所帮助. ...

  6. 帮我用python flask框架写一个可以上传英文pdf然后通过调取百度翻译api翻译为中文然后保存为pdf文件的代码...

    下面是一个简单的代码示例,可以帮助您使用 Python Flask 框架实现上传英文 PDF,并通过调用百度翻译 API 将其翻译为中文,然后保存为 PDF 文件: from flask import ...

  7. 怎样把word转换成pdf文件

    由于工作的需要,经常需要将word文档转换成PDF文件传递文件,使word文件更能呈现书籍原始的样子,阅读起来显得那么真实,好用,那怎样把word转换成pdf文件的呢,就让小编来告诉你解决方法把! 第 ...

  8. word保存提示“由于文件许可错误,word无法完成保存”的解决办法

    word保存提示"由于文件许可错误,word无法完成保存" **问题:**我使用的是win10操作系统,在某次更新之后出现了word无法保存的问题,错误信息如下图 **解决办法:* ...

  9. 如何把word保存为pdf并加密

    当我们在网络上传输文件时,如果怕文件被泄露,最好的办法就是把我们需要传输的word文件保存为pdf格式并加密.然后把密码记下即可.具体步骤如下: 1.如果是word,将该文件另存为: 2.选择合适的存 ...

最新文章

  1. oralce 角色 权限
  2. 产品经理入门——PM
  3. gui linux 桌面应用,吃掉Linux开发者,WSL支持GUI应用
  4. Linux Centos7 以及window 10 Kali2020.4 安装 nvm node npm cnpm yarn
  5. 2021牛客暑期多校训练营8 J-Tree(思维dp+rmq)
  6. SQL Server执行计划
  7. SQL SERVER 2016 AlwaysOn 无域集群+负载均衡搭建与简测
  8. Matlab Tricks(十三)—— 提取矩阵的对角线元素
  9. AFTN和SITA报文简介
  10. Google收购YouTube一周年:开挖的视频金矿
  11. 思维导图之----javascript正则表达式知识树
  12. CDlinux使用与安装
  13. 淘宝6.18叠猫猫赚猫币自动生成
  14. php执行fastlane,Fastlane使用说明 自动化打包
  15. redis setex和set 的区别
  16. Java银行储户后台系统
  17. LOTO 示波器软件功能——文件存储和回读功能
  18. c51单片机光电门测反应时间(实战小项目)
  19. postgres-----pgrouting
  20. 【福利】乳摇动画初探

热门文章

  1. 蓝桥杯2017年第八届蓝桥杯
  2. 积分有效期的设计处理方案
  3. notepad++设置中文界面
  4. 2023年苹果pro A2799b笔记本忘记登录密码如何重置开机密码?
  5. [Android 基础] -- Android 属性系统简介
  6. houdini视图切换快捷键
  7. Vuex3 / Vuex4 使用指南
  8. VIVADO cordic IP核
  9. 【XBEE手册】XBEE操作
  10. 【计量经济学】联立方程模型