var ppt = application.Presentations.Open(file, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
var index = 0;
var fileName = Path.GetFileNameWithoutExtension(file);
foreach (Slide slid in ppt.Slides)
{
++index;
slid.Export(Path.Combine(outputPath, string.Format("{0}{1}.jpg", fileName, index)), "jpg", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
}
ppt.Close();
application.Quit();
GC.Collect();
}</pre></div>
void ConvertPptToJpg(string file, string outputPath)
{
Type t = Type.GetTypeFromProgID("PowerPoint.Application");
object o = Activator.CreateInstance(t);
object p = t.InvokeMember(
"Presentations",
BindingFlags.Public | BindingFlags.GetProperty,
null, o, null, null);
Type t2 = p.GetType();
object ppt = t2.InvokeMember("Open",
BindingFlags.Public | BindingFlags.InvokeMethod,
null, p, new object[] { file, 0, 0, 0 }, null);
object slides = t2.InvokeMember(
"Slides",
BindingFlags.Public | BindingFlags.GetProperty,
null, ppt, null, null);
var index = 0;
var fileName = Path.GetFileNameWithoutExtension(file);
foreach (object slid in (slides as IEnumerable))
{
++index;
var slidType = slid.GetType();
slidType.InvokeMember("Export",
BindingFlags.Public | BindingFlags.InvokeMethod,
null, slid, new object[] { Path.Combine(outputPath, string.Format("{0}{1}.jpg", fileName, index)), "jpg", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height }, null);
NAR(slid);
}
NAR(p);
p = null;
NAR(slides);
slides = null;
t2.InvokeMember("Close",
BindingFlags.Public | BindingFlags.InvokeMethod,
null, ppt, null, null);
NAR(ppt);
ppt = null;
t.InvokeMember(
"Quit",
BindingFlags.Public | BindingFlags.InvokeMethod,
null, o, null, null);
NAR(o);
o = null;
GC.Collect();
}</pre></div>