1

i would like convert pps(x) or ppt(x) to PDF using C# and Microsoft.Office.Interop.PowerPoint. To do this, I use a method performing the following coding:

Microsoft.Office.Interop.PowerPoint.Presentation presentation = null; Microsoft.Office.Interop.PowerPoint.Application application = null; try { application = new Microsoft.Office.Interop.PowerPoint.Application(); presentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); presentation.SaveAs(targetPath, PpSaveAsFileType.ppSaveAsPDF, Microsoft.Office.Core.MsoTriState.msoTrue); result = true; } catch (Exception ex) { Console.WriteLine(ex.Message); result = false; } finally { if (presentation != null) { presentation.Close(); presentation = null; } if (application != null) { application.Quit(); application = null; } } return result; 

When the method is invoked for the first time, the ppsx is saved as pdf successfully. But when the method is invoked for another time, the following exception is raised on application = new Microsoft.Office.Interop.PowerPoint.Application();

The exception message is: Creating an instance of the COM component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} from the IClassFactory failed due to the following error: 800706b5 The interface is unknown. (Exception from HRESULT: 0x800706B5). Right before this exception is raised the console shows another exception "System.Runtime.InteropServices.COMException" in mscorlib.dll.

When navigation into the interface Microsoft.Office.Interop.PowerPoint.Application via F12, the GUID of this interface is 91493442-5A91-11CF-8700-00AA0060263B. So it is slightly different to the GUID inside the exception's message.

I would like to ask you, how to fix this issue?

PS: Microsoft Office 2010 is installed on this Notebook (running on Microsoft Win 7)

Thank you and best regards

3
  • This is just a wild guess, but easy to check: When you have the preview pane in Windows explorer open and a PPT/PPTX file selected and visible in the preview pane, there's a hidden instance of POWERPNT.EXE open. This mechanism seems fragile and tends to leave the instance of the EXE behind, which can cause problems for automation, etc. PPT is a single instance app; when you ask for a new instance, you'll get the running instance, if there is one. You might get the running (but hidden) one when you wanted a new one. Check the processes list for instances of the exe before/after your code Commented Feb 6, 2013 at 16:05
  • First we need to know if your using Windows 7 32-bit or Windows 7 64-bit. We also need to know if Office 2010 64-bit or Office 2010 32-bit is being used. The error indicates your program cannot even use the reference in question which points to classic problem of a 64-bit process trying to load a 32-bit assembly. Commented Feb 6, 2013 at 16:24
  • 1
    Since you've tagged this ASP.Net you should know that using Office automation from a server process is not supported. Commented Feb 6, 2013 at 23:36

3 Answers 3

1

The following (arguably stupidsilly) workaround did the trick for me:

try { app = new Application(); } catch (COMException) { app = new Application(); } 

Edited: Thanks Jesse :)

Sign up to request clarification or add additional context in comments.

1 Comment

If it's a workaround, it's definitely not stupid. Maybe you should call it silly. =)
0

try closing the presentation and application before returning the value.

presentation.Close(); application.Quit(); 

otherwise the document and application remain opened and can't be accessed

Comments

0

You can try this code for converting any ppt file to pdf with interop and it works without any exception.Even there will not stay open COM object on the background processes.

Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application(); app.Visible = MsoTriState.msoTrue; Presentations presentations = app.Presentations; Presentation presentation = presentations.Open(fileLocation, ReadOnly: MsoTriState.msoCTrue); presentation.ExportAsFixedFormat(outLocation, PpFixedFormatType.ppFixedFormatTypePDF); Marshal.ReleaseComObject(presentations); presentation.Close(); Marshal.ReleaseComObject(presentation); app.Quit(); Marshal.ReleaseComObject(app); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.