//// <summary>
/// 把ppt文件转换成pdf文件2
/// </summary>
/// <param name="sourcePath">需要转换的文件路径和文件名称</param>
/// <param name="targetPath">转换完成后的文件的路径和文件名名称</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool PPTConvertToPDF(string sourcePath, string targetPath)
{
bool result;
PowerPoint.PpSaveAsFileType ppSaveAsFileType = PowerPoint.PpSaveAsFileType.ppSaveAsPDF;//转换成pdf
object missing = Type.Missing;
Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
PowerPoint.Presentation persentation = null;
try
{
application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
if (persentation != null)
{
persentation.SaveAs(targetPath, ppSaveAsFileType, MsoTriState.msoTrue);
}
result = true;
}
catch
{
result = false;
}
finally
{
if (persentation != null)
{
persentation.Close();
persentation = null;
}
if (application != null)
{
application.Quit();
application = null;
}
}
return result;
} //string mac = Interaction.InputBox("请输入MAC", "输入MAC", "", 100, 100);
//// <summary>
/// 把Word文件转换成pdf文件2
/// </summary>
/// <param name="sourcePath">需要转换的文件路径和文件名称</param>
/// <param name="targetPath">转换完成后的文件的路径和文件名名称</param>
/// <returns>成功返回true,失败返回false</returns>
public bool WordToPdf(object sourcePath, string targetPath)
{
bool result = false;
WdExportFormat wdExportFormatPDF = WdExportFormat.wdExportFormatPDF;
object missing = Type.Missing;
Microsoft.Office.Interop.Word.ApplicationClass applicationClass = null;
Microsoft.Office.Interop.Word.Document document = null;
try
{
applicationClass = new Microsoft.Office.Interop.Word.ApplicationClass();
document = applicationClass.Documents.Open(ref sourcePath, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
if (document != null)
{
document.ExportAsFixedFormat(targetPath, wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForPrint, WdExportRange.wdExportAllDocument, , , WdExportItem.wdExportDocumentContent, true, true, WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, false, ref missing);
}
result = true;
}
catch
{
result = false;
}
finally
{
if (document != null)
{
document.Close(ref missing, ref missing, ref missing);
document = null;
}
if (applicationClass != null)
{
applicationClass.Quit(ref missing, ref missing, ref missing);
applicationClass = null;
}
}
return result;
}
/// <summary>
/// 打开pdf文件方法
/// </summary>
/// <param name="p"></param>
/// <param name="inFilePath">文件路径及文件名</param>
public static void Priview(System.Web.UI.Page p, string inFilePath)
{
p.Response.ContentType = "Application/pdf"; string fileName = inFilePath.Substring(inFilePath.LastIndexOf('\\') + );
p.Response.AddHeader("content-disposition", "filename=" + fileName);
p.Response.WriteFile(inFilePath);
p.Response.End();
}

C# Work PPT to PDF的更多相关文章

  1. 无限制使用ppt转pdf功能

    https://smallpdf.com/cn是一个pdf处理网站,十分好用,可是非注册用户有很多限制,比如用两次ppt转pdf就要等待: 于是就想如何让服务器认为我没有用过这个功能呢,感觉应该是用c ...

  2. [Asp.net]常见word,excel,ppt,pdf在线预览方案,有图有真相,总有一款适合你!

    引言 之前项目需要,查找了office文档在线预览的解决方案,顺便记录一下,方便以后查询. 方案一 直接在浏览器中打开Office文档在页面上的链接.会弹出如下窗口: 优点:主流浏览器都支持. 缺点: ...

  3. Spire.Office for .NET(Word、Excel、PPT、PDF等)

    使用Spire.Office for .NET(Word.Excel.PPT.PDF等)的初步感受 前言 本文大部分内容来自http://www.codeproject.com/Articles/71 ...

  4. word,excel,ppt转Pdf,Pdf转Swf,通过flexpaper+swftools实现在线预览

    其实这是我好几年前的项目,现在再用这种方式我也不建议了,毕竟未来flash慢慢会淘汰,此方式也是因为目测大部分人都装了flash,才这么做的,但是页面展示效果也不好.其实还是考虑收费的控件,毕竟收费的 ...

  5. [Python Study Notes]批量将ppt转换为pdf v1.0

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  6. Jacob工具类使用文件互转服务 word转html html转excel word转pdf excel转pdf ppt转pdf

    前提条件  必须安装MS office 1.jdk使用jdk1.8 2.jacob.dll放在..\jdk1.8\jre\bin目录下 3.eclipse的jre版本要和jdk一致,window-&g ...

  7. java通过url在线预览Word、excel、ppt、pdf、txt文档

    java通过url在线预览Word.excel.ppt.pdf.txt文档中的内容[只获得其中的文字] 在页面上显示各种文档中的内容.在servlet中的逻辑 word: BufferedInputS ...

  8. Aspose office (Excel,Word,PPT),PDF 在线预览

    前文: 做个备份,拿的是试用版的 Aspose,功能见标题 代码: /// <summary> /// Aspose office (Excel,Word,PPT),PDF 在线预览 // ...

  9. word/excel/ppt 2 PDF

    PHP 实现 word/excel/ppt 转换为 PDF 一般最常见的就是利用OpenOffice来转换,来看看实现的核心代码: class PDFConverter { private $com; ...

  10. Spring boot使用Aspose.Slides操作ppt转PDF、转图片

    最近要将ppt转为PDF和图片,Apache poi ,jacob都试了下 Apache poi 转图片乱码,处理了,还会存在部分乱码 jacob对系统依赖比较大,必须是windows还得安装MS O ...

随机推荐

  1. Linux 用户切换、修改用户名、修改密码

    一.用户切换 "$":普通用户提示符 "#":root用户提示符 1.普通用户到root: 方式一:命令:su然后输入root密码 此种方式只是切换了root身 ...

  2. javaSocket笔记

    1.查看电脑当前开放链接的端口号 使用netstat命令 netstat -nao 可以查看PID进程号 netstat -nab 获取进程的详细信息 2.类创建的不同对象,引用是不同的.也就是说同一 ...

  3. Windows安装MongoDB

    一.简介 MongoDB 是一个基于分布式 文件存储的NoSQL数据库 由C++语言编写,运行稳定,性能高 旨在为 WEB 应用提供可扩展的高性能数据存储解决方案 查看官方网站 MongoDB特点 模 ...

  4. linux系统(CentOS7)虚拟机上安装oracle 11g,解决oracle图形界面卡住无法点击next问题

    https://www.cnblogs.com/nichoc/p/6416475.html

  5. [转] AES,SHA1,DES,RSA,MD5区别

    AES:更快,兼容设备,安全级别高: SHA1:公钥后处理回传 DES:本地数据,安全级别低 RSA:非对称加密,有公钥和私钥 MD5:防篡改 相关: 公开密钥加密(英语:public-key cry ...

  6. Nginx代理实现内网主机访问公网服务

    通过Nginx代理实现内网主机访问公网和接口服务 1.需求: m2.test.com为公司测试环境的微信测试域名,因为要调用微信服务接口需要访问外网,现通过Nginx代理现实此功能. 2.环境如下: ...

  7. CentOS7下Django环境的搭建安装python3.6.5,virtualenv django1.11.14

    1.帖子1https://blog.csdn.net/a249900679/article/details/51527200 2.virtualenv https://www.cnblogs.com/ ...

  8. (一)cygwin和vim——hello world!

    好吧,我现在初出茅庐,一无所有,只有一台win xp.做什么呢?要不要试试Unix命令行编程的感觉,想到就做.Just try! 1.首先安装cygwin,最好是选择离线安装包. 2.默认选择安装所有 ...

  9. vue 中如何对公共css、 js 方法进行单文件统一管理,全局调用

    1.前言 最近,为公司开发交付的一个后台管理系统项目,我使用了 Vue 框架进行开发实践. 模块化.组件化.工程化的开发体验非常好.良好的 api,优雅的设计,对于工程师非常友好. 但是由于模块比较多 ...

  10. excel怎么样批量将unix时间戳转化为北京时间

    https://jingyan.baidu.com/article/63acb44afb1e2561fcc17e3f.html 1.单元格属性改变日期 2.使用公式: =(A2+8*3600)/864 ...