Print PowerPoint document from a C# application

Posted on 2010-01-04
Last Modified: 2013-12-17
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;

      oPresentation = oPowerPoint.Presentations.Open(myFilePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoTrue);

      oPresentation.PrintOut(-1, -1, "", 1, MsoTriState.msoCTrue);

      oPresentation = null;
      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(oPresentation) > 0) ;
      oPresentation = null;

      while (Marshal.ReleaseComObject(oPowerPoint) > 0) ;
      oPowerPoint = null;

Next, I added explicit garbage collection at the end:


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?
Question by:AlphaGuys
    LVL 23

    Expert Comment

    by:Roshan Davis
    Can you try any of the documented events listed in the following link?

    Author Comment

    I don't think PowerPoint has any useful events like that. The link describes Word events only. PowerPoint does have a PresentationPrint event, but that's fired before the file is printed.
    LVL 35

    Accepted Solution

    Check that Check the oPowerPoint.Options.PrintBackground 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.

    Author Comment

    That does answer my question. Setting PrintInBackground to false and using my code to close PowerPoint after printing does successfully print without leaving PowerPoint open on the desktop.

    But I've still got a problem dealing with PowerPoint files. I've opened up a separate question that describes another issue I have. I'd love any input you can give my on that one, too.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

     Regular Expressions Microsoft Word has sophisticated search tools that can search for patterns. For example if you wanted to search for all UK phone numbers that followed a pattern of five digits, a space and then six digits you can easily do th…
    Setting the Scene Animations in PowerPoint are a great tool to convey messages when used carefuly with the content of your slides. There are plenty of animation effects and options, including a Repeat feature for individual animation effects. …
    This video teaches viewers how to add transitions to their Slideshows and how to set up timing for the transitions.
    This video teaches viewers how to fit pictures into slides, crop and remove backgrounds, and alter photos to look more professional.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now