Microsoft
Software
Hardware
Network
Question : Print PowerPoint document from a C# application
I want to print PowerPoint documents from my C# .NET application.
First, I tried to simply reference the Automation interop libraries like this:
public void PrintFile(string myFilePath)
{
Application oPowerPoint = new Application();
Presentation oPresentation = null;
oPowerPoint.Activate();
oPresentation = oPowerPoint.Presentations.
Open(myFil
ePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoTrue);
oPresentation.PrintOut(-1,
-1, "", 1, MsoTriState.msoCTrue);
oPresentation.Close();
oPresentation = null;
oPowerPoint.Quit();
oPowerPoint = null;
}
But that leaves an instance of PowerPoint open on the desktop which I dont want. I added ReleaseComObject calls before nulling out my references to the Presentation and PowerPoint objects, but that didnt have any affect.
while (Marshal.ReleaseComObject(
oPresentat
ion) > 0) ;
oPresentation = null;
while (Marshal.ReleaseComObject(
oPowerPoin
t) > 0) ;
oPowerPoint = null;
Next, I added explicit garbage collection at the end:
GC.Collect();
GC.WaitForPendingFinalizer
s();
This closes the PowerPoint application, but it does it too soon! The application is closed before the print job is sent to the printer, so the print job is not completed.
How can I use PowerPoint to print presentations from my C# .Net code without leaving PowerPoint visible on the desktop?
Answer : Print PowerPoint document from a C# application
Check that Check the oPowerPoint.Options.PrintB
ackground is set to false. This will cause your code to wait until printout sucessufully finish to print your document.
The default is true which is causing you this issue.
Random Solutions
I am copying 40 diferent databases to a directory that these databases already exists. How do I prevent the system message "This Directory already exist" "Overwright" "Yes" "No" from appearing each ti
Connecting to a Oracle DB using MS SQL Opendatasource
Server Down
SQL Query, Union All Question
WSUS for IT outsoursing clients (one WSUS for few companies)
GPO for desktop icons in Windows Server 2008 R2
Use a countdown display in a batch .bat file
Select multiple Access records question.
Concatenate or merger in MS Access query
Excel paysheet