word保存为pdf文件
方法一: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文件相关推荐
- 计算机一级保存文件,计算机等级一级技巧:Word文档保存为PDF文件
全国计算机等级考试(National Computer Rank Examination,简称NCRE)是由国家教育部考试中心主办,面向社会,用于考查应试人员计算机操作.理论应用知识与技能的全国性计算 ...
- 神奇的pdfkit工具——将字符串保存为pdf文件
神奇的pdfkit工具--将字符串保存为pdf文件 1.安装工具包 pip install pdfkit 2.上干货 import pdfkitdef create_pdf(str_data, to_ ...
- Typora基础用法:pandoc安装,导入导出word文档,pdf文件。设置图片目录
点击观看B站视频 Typora基础用法:pandoc安装,导入导出word文档,pdf文件.设置图片目录. 一. pandoc安装 首次安装完typora,是没法导入的,需要安装pandoc 选择[请 ...
- java excel转pdf linux,从JAVA直接读取EXCEL、WORD并生成PDF文件
从JAVA直接读取EXCEL.WORD并生成PDF文件 1.操作EXCEL和WORD文件 使用JAVA从EXCEL.WORD文件中读写数据,可以使用http://jexcelapi.sourcefor ...
- 计算机证书图片无法保存,win7电脑JPG文件怎么保存为PDF文件
很多时候我们需要将win7下的各种文本文件转换为PDF格式的文件,那么win7电脑JPG文件怎么保存为PDF文件呢?学习啦小编分享了win7电脑JPG文件保存为PDF文件的方法,希望对大家有所帮助. ...
- 帮我用python flask框架写一个可以上传英文pdf然后通过调取百度翻译api翻译为中文然后保存为pdf文件的代码...
下面是一个简单的代码示例,可以帮助您使用 Python Flask 框架实现上传英文 PDF,并通过调用百度翻译 API 将其翻译为中文,然后保存为 PDF 文件: from flask import ...
- 怎样把word转换成pdf文件
由于工作的需要,经常需要将word文档转换成PDF文件传递文件,使word文件更能呈现书籍原始的样子,阅读起来显得那么真实,好用,那怎样把word转换成pdf文件的呢,就让小编来告诉你解决方法把! 第 ...
- word保存提示“由于文件许可错误,word无法完成保存”的解决办法
word保存提示"由于文件许可错误,word无法完成保存" **问题:**我使用的是win10操作系统,在某次更新之后出现了word无法保存的问题,错误信息如下图 **解决办法:* ...
- 如何把word保存为pdf并加密
当我们在网络上传输文件时,如果怕文件被泄露,最好的办法就是把我们需要传输的word文件保存为pdf格式并加密.然后把密码记下即可.具体步骤如下: 1.如果是word,将该文件另存为: 2.选择合适的存 ...
最新文章
- oralce 角色 权限
- 产品经理入门——PM
- gui linux 桌面应用,吃掉Linux开发者,WSL支持GUI应用
- Linux Centos7 以及window 10 Kali2020.4 安装 nvm node npm cnpm yarn
- 2021牛客暑期多校训练营8 J-Tree(思维dp+rmq)
- SQL Server执行计划
- SQL SERVER 2016 AlwaysOn 无域集群+负载均衡搭建与简测
- Matlab Tricks(十三)—— 提取矩阵的对角线元素
- AFTN和SITA报文简介
- Google收购YouTube一周年:开挖的视频金矿
- 思维导图之----javascript正则表达式知识树
- CDlinux使用与安装
- 淘宝6.18叠猫猫赚猫币自动生成
- php执行fastlane,Fastlane使用说明 自动化打包
- redis setex和set 的区别
- Java银行储户后台系统
- LOTO 示波器软件功能——文件存储和回读功能
- c51单片机光电门测反应时间(实战小项目)
- postgres-----pgrouting
- 【福利】乳摇动画初探