PrintOut method fails in Powerpoint

M

Mangesh

Hi ,
I am implementing a Powerpoint 2007 addin using VSTO 2005 SE.
I am trying to print to file the active presentation, with the following
code.

try
{
// Retrieve a reference to the active presentation:
PowerPoint.Presentation presentation =
Globals.ThisAddIn.Application.ActivePresentation;

// Retrieve a reference to the PowerPoint printing
options:
PowerPoint.PrintOptions options =
presentation.PrintOptions;
options.FrameSlides =
Microsoft.Office.Core.MsoTriState.msoCTrue;
if (Config.bPrintInBw)
{
options.PrintColorType =
PowerPoint.PpPrintColorType.ppPrintPureBlackAndWhite;
}
else
{
options.PrintColorType =
PowerPoint.PpPrintColorType.ppPrintColor;
}
options.PrintInBackground =
Microsoft.Office.Core.MsoTriState.msoFalse;

presentation.PrintOut(1, presentation.Slides.Count,
fileName,
1,
Microsoft.Office.Core.MsoTriState.msoFalse);

}
catch (Exception e)
{
if (Config.bDebugging)
{
LogFile.WriteLog(e.Message);
}
}

However I am getting an exception as below.
Error HRESULT E_FAIL has been returned from a call to a COM component
Powerpoint application, does not throw this exception everytime but once in
3-4 consecutive attempts.

If I set the options.PrintInBackground to True, then there is no exception,
and printing to file works fine.

However I do not wish to print in background, as the code that follows
depends on the successful creation of the file. Please suggest what should be
done to prevent this exception.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top