I cannot convert PPT to XPS or PNG to PDF file.
Two ways for this problem is:
First Way: Using COM Component Microsoft. For Example
:Microsoft.Office.Interop.PowerPoint,Microsoft.Office.Core , … .
My Code :
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;
}
}
Second Way: Sending file to
“Microsoft XPS Document Writer” printer With Process.
My Code :
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;
Third Way: Using API Windows And Sending Binary File .
This is sample for this way :
My Problem :
First Way: COM object that has been separated from its underlying RCW cannot be used
Second Way: Cannot Hidden Window and Close Window
Third Way: Cannot Create XPS File . di.OutPutFile Create ill [bad?] file.
Owner this Answer : Emmanuel N
You can do it like this or this for pdf/word. You can also use 2007 Microsoft Office Add-in: Microsoft Save as PDF or XPS, like this