我不能将PPT转换为XPS或PNG为PDF文件。PPT和PDF到XPS或PNG与C#
解决此问题的两种方法是:
第一种方法:使用COM组件Microsoft。例如:
:Microsoft.Office.Interop.PowerPoint,Microsoft.Office.Core,...。
我的代码:
private static void PPT2XPS()
{
Microsoft.Office.Interop.PowerPoint.Application powerpoint;
Microsoft.Office.Interop.PowerPoint.Presentation presentation;
Microsoft.Office.Interop.PowerPoint.Presentations presentations;
powerpoint = new Microsoft.Office.Interop.PowerPoint.Application();
presentations = powerpoint.Presentations;
presentation = presentations.Open(@"d:\test.ppt", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
Microsoft.Office.Interop.PowerPoint.Slides slides = presentation.Slides;
for (int i = 1; i <= slides.Count; i++)
{
Microsoft.Office.Interop.PowerPoint.Slide slide = slides[i];
String slideName = slide.Name;
releaseCOM(slide);
slide.Export(@"d:\test\" + i.ToString() + ".xps", "");
}
}
private static void releaseCOM(object o)
{
try
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(o);
}
catch { }
finally
{
o = null;
}
}
第二种方式:发送文件到
“Microsoft XPS文档作家” 打印机使用进程。
我的代码:
Process P = new Process();
ProcessStartInfo psInfo = new ProcessStartInfo();
psInfo.FileName = @"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe";
string option = @"/t";
string xps = "Microsoft XPS Document Writer";
string targetFile = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar +
Path.GetFileNameWithoutExtension(filename) + @".xps";
string Myargs = String.Format("{0} \"{1}\" \"{2}\" {0} \"{3}\"", option, filename, xps, targetFile);
psInfo.CreateNoWindow = true;
psInfo.Arguments = Myargs;
psInfo.UseShellExecute = false;
psInfo.ErrorDialog = false;
P.StartInfo = psInfo;
P.Start();
P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
第三条道路:使用API的Windows和发送二进制文件。 这是这样的样品:
我的问题:
第一种方式:已从与其基础RCW分开COM对象不能用于
第二种方式:不能隐藏窗口和关闭窗口
第三种方式:无法创建XPS文件。 di.OutPutFile创建不良的[bad?]文件。