Automate the export of PowerPoint files to Images

Web or software developers may find themselves trying to automate the export operation of a PowerPoint file to image or HTML for different reasons, either if you want to setup a PowerPoint sharing platform on the Internet or if you have an Intranet in your organization and you are managing an IT department and need to deliver PowerPoint presentations to the accounting department or top managers.

There are some tips that may be a good starting point for web developers or software developers trying to code something that takes a PowerPoint .ppt or .pptx file and outputs a sequence of images or HTML pages.

The answer seems to be in .NET and Microsoft Office interoperability and you can achieve some interesting conversion automation in PowerPoint or .NET programmatically.

Let’s see here some resources that may be helpful to achieve this goal.

Aspose.Slides for .NET

Aspose.Slides for .NET is a paid component that you can buy. The license may be very expensive but well, that’s depend on the ROI (Return on Investment) that you consider. There are different licenses for developers or sites. For example Developer Small Business, Developer OEM, Site OEM and Site Small Business. The prices ranges from $799 to $9588.

Aspose.Slides for .NET is a PowerPoint management component that enables .NET applications to read, write and manipulate PowerPoint documents without even using Microsoft PowerPoint. The compennt is the first and only .NET component that provides functionality to manage PowerPoint documents within your own applications. As with all Aspose .NET components, Aspose.Slides is written in managed C# lightning fast.

Here is the diagram explaining how this works:

product diagram PowerPoint

Common uses of this library includes:

  • Create new slides or clone existing slides from templates
  • Create shapes on slides
  • Add text to shapes
  • Handle text and shape formatting
  • Apply or remove protection on shapes
  • Scan text from presentations
  • Render slides to images
  • Export presentations to PDF
  • Add images to presentations
  • Embed Excel charts as OLE objects in slides
  • Generate presentations from database

You can learn more in Aspose.Slides for .NET

Tips for Exporting Slides from PowerPoint in C#

The previous component may be quite expensive for hobbyists or if you just need a simple solution. This can be a good Aspose alternative for developers who want to implement this snippet in C#.

John Dyer explained here some tips for exporting slides from PowerPoint in C#.

using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
ApplicationClass pptApplication = new ApplicationClass();
Presentation pptPresentation = pptApplication.Presentations.Open("myfile.ppt",
MsoTriState.msoFalse,MsoTriState.msoFalse, MsoTriState.msoFalse);
pptPresentation.Slides.Item[1].Export("slide.jpg", "jpg", 320, 240);

 

In this example we can see that John used the Microsoft.Office.Core namespace and then created a new object ApplicationClass() in .NET to open a .ppt file. This way he can export then the slide to JPG.

What he suggests to do is replace the JPG format by PNG so you don’t lose quality. Then you can compress the image again to generate a JPG with a desired compression/quality level.

Convert PowerPoint to images programmatically

In this question asked in Stackoverflow @mavnn answered with an elegant solution in Python.


import os
import comtypes.client

def export_presentation(path_to_ppt, path_to_folder):
    if not (os.path.isfile(path_to_ppt) and os.path.isdir(path_to_folder)):
        raise "Please give valid paths!"

    powerpoint = comtypes.client.CreateObject("Powerpoint.Application")

    # Needed for script to work, though I don't see any reason why...
    powerpoint.Visible = True

    powerpoint.Open(path_to_ppt)

    # Or some other image types
    powerpoint.ActivePresentation.Export(path_to_folder, "JPG")

    powerpoint.Presentations[1].Close()
    powerpoint.Quit()

He argued with this example in Python the PowerPoint files should be trivial to convert to an image.

Conclusions

Depending on the budget you have to spend and the features that you need, you may consider to purchase a full component or just try to connect your .NET application with the Microsoft Office components to export the slides.

There are many other solutions around in the Internet so if you faced this situation in the past you are welcome to send us your comments.

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Loading...