C#将PPT文件转换成PDF文件
作者:chenqiangdage 时间:2022-09-08 20:33:21
这里在提供C#代码,将PPT转成PDF.直接上代码;
要引入Microsoft.Office.Interop.PowerPoint; 版本12.0.0.0;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.PowerPoint;
//Office 命名空间
namespace OfficeToPdf
{
//excel 类
class PowerPointConverter
{
//构造函数
public PowerPointConverter()
{ }
/// <summary>
/// 转换PowerPoint 成PDF文档
/// </summary>
/// <param name="_lstrInputFile">原文件路径</param>
/// <param name="_lstrOutFile">pdf文件输出路径</param>
/// <returns>true 成功</returns>
public bool ConverterToPdf(string _lstrInputFile, string _lstrOutFile)
{
Microsoft.Office.Interop.PowerPoint.Application lobjPowerPointApp = null;
Microsoft.Office.Interop.PowerPoint.Presentation lobjppt = null;
object lobjMissing = System.Reflection.Missing.Value;
object lobjSaveChanges = null;
try
{
lobjPowerPointApp = new Microsoft.Office.Interop.PowerPoint.Application();
lobjppt = lobjPowerPointApp.Presentations.Open(_lstrInputFile, MSCore.MsoTriState.msoTrue, MSCore.MsoTriState.msoFalse, MSCore.MsoTriState.msoFalse);
lobjppt.SaveAs(_lstrOutFile, PpSaveAsFileType.ppSaveAsPDF, MSCore.MsoTriState.msoCTrue);
}
catch (Exception ex)
{
//其他日志操作;
return false;
}
finally
{
if (lobjppt != null)
{
lobjppt.Close();
Marshal.ReleaseComObject(lobjppt);
lobjppt = null;
}
if (lobjPowerPointApp != null)
{
lobjPowerPointApp.Quit();
Marshal.ReleaseComObject(lobjPowerPointApp);
lobjPowerPointApp = null;
}
//主动激活垃圾回收器,主要是避免超大批量转文档时,内存占用过多,而垃圾回收器并不是时刻都在运行!
GC.Collect();
GC.WaitForPendingFinalizers();
}
return true;
}
}
}
来源:https://blog.csdn.net/chenqiangdage/article/details/20487167
标签:c#,ppt,pdf
0
投稿
猜你喜欢
Spring Boot Admin 进行项目监控管理的方法
2021-09-01 23:39:19
Java 的 FileFilter文件过滤与readline读行操作实例代码
2022-04-09 07:22:53
Python和Java的语法对比分析语法简洁上python的确完美胜出
2023-08-10 17:06:54
springboot使用Mybatis-plus分页插件的案例详解
2023-10-27 13:47:43
Java Bean 作用域及它的几种类型介绍
2022-12-02 20:39:42
Java线程池高频面试题总结
2023-10-22 02:12:34
Android10 启动之SystemServer源码分析
2021-08-15 05:38:13
浅谈关于spring profile的误解
2021-07-25 05:48:43
java多线程Thread的实现方法代码详解
2022-01-03 01:02:28
详解SpringBoot的事务管理
2022-01-15 13:39:26
gradle使用maven-publish发布jar包上传到私有maven配置
2022-11-22 07:07:54
详解Mybatis的二级缓存配置
2023-03-20 10:48:37
详解Spring循环依赖的解决方案
2022-05-29 13:14:57
JavaFx Tooltip悬浮提示使用及自定义代码详解
2023-05-11 15:06:05
java web项目里ehcache.xml介绍
2022-02-25 20:46:25
IDEA+maven+SpringBoot+JPA+Thymeleaf实现Crud及分页
2023-04-14 18:33:46
Java Spring AOP源码解析之事务实现原理
2023-09-10 02:39:46
C# 索引器的使用教程
2022-08-25 05:11:59
适用于WebForm Mvc的Pager分页组件C#实现
2022-05-11 22:11:34
SpringBoot集成整合JWT与Shiro流程详解
2022-09-06 06:33:23