-
Notifications
You must be signed in to change notification settings - Fork 8
/
PptToPDF.cs
55 lines (46 loc) · 1.69 KB
/
PptToPDF.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*************************************************************************************
* CLR版本: 4.0.30319.42000
* 类 名 称: PptToPDF
* 机器名称: 9GX1UOWROPIAEJ4
* 命名空间: OfficeToPDF
* 文 件 名: PptToPDF
* 创建时间: 2020/12/05 11:51:27
* 作 者: Richard Liu
* 说 明:。。。。。
* 修改时间: 2020/12/05 11:51:27
* 修 改 人: Richard Liu
*************************************************************************************/
using System;
using System.IO;
using PowerPoint;
namespace OfficeToPDF
{
class PptToPDF : IDisposable
{
dynamic wps;
public PptToPDF()
{
Type type = Type.GetTypeFromProgID("KWPP.Application");
wps = Activator.CreateInstance(type);
}
public void ToPdf(string wpsFilename, string pdfFilename = null)
{
if (wpsFilename == null) { throw new ArgumentNullException("wpsFilename"); }
if (pdfFilename == null)
{
pdfFilename = Path.ChangeExtension(wpsFilename, "pdf");
}
//忽略警告提示
wps.DisplayAlerts = false;
Console.WriteLine(string.Format(@"正在转换 [{0}] -> [{1}]", wpsFilename, pdfFilename));
//object missing = Type.Missing;
dynamic ppt = wps.Presentations.Open(wpsFilename, MsoTriState.msoCTrue, MsoTriState.msoCTrue, MsoTriState.msoCTrue);
ppt.SaveAs(pdfFilename, PpSaveAsFileType.ppSaveAsPDF, MsoTriState.msoTrue);
ppt.Close();
}
public void Dispose()
{
if (wps != null) { wps.Quit(); }
}
}
}