COM

GemBox.Presentation can be used in other programming languages through COM. Due to the COM limitations, GemBox.Presentation exposes a ComHelper class that provides overrides for some API members not supported through COM.

The example demonstrates how to load a template PPTX file and modify its contents using GemBox.Presentation. It shows how to remove certain content and how to add new content. At the end, modified presentation is saved in PDF format.

Notes

  • GemBox.Presentation assembly needs to be registered in order for this example to work. You can find more information about the COM registration here.
  • Python code requires the pywin32 extension to be installed.

Wrapper assembly

If you need to use many GemBox.Presentation classes and methods via COM Interop, consider creating a .NET wrapper assembly that does all the work within and exposes a minimal set of classes and methods to the unmanaged code. This will enable you to avoid various COM limitations and take the advantage of GemBox.Presentation's full capabilities.

Screenshot

COM Example Screenshot

See the full code below.

' Create ComHelper object and set license.
' NOTE: If you're using a Professional version you'll need to put your serial key below.
Set comHelper = CreateObject("GemBox.Presentation.ComHelper")
comHelper.ComSetLicense("FREE-LIMITED-KEY")

' Load input presentation.
Set presentation = comHelper.Load(Server.MapPath(".") & "\ComTemplate.pptx")

' Get first slide in the presentation.
Set slide = comHelper.GetCollectionItem(presentation.Slides, 0)

' Remove first drawing from the first slide.
comHelper.RemoveCollectionItemAt(slide.Content.Drawings, 0)

' Get master slide.
Set masterSlide = comHelper.GetCollectionItem(presentation.MasterSlides, 0)

' Get layout slide.
Set layoutSlide = comHelper.GetCollectionItem(masterSlide.LayoutSlides, 0)

' Add new slide to the presentation.
slide = comHelper.AddNewSlide(presentation.Slides, layoutSlide)

' Add new shape to the new slide.
Set shape = slide.Content.AddShape(ShapeGeometryType.RoundedRectangle, 2, 2, 8, 4)

' Set shape fill to solid blue color.
shape.Format.Fill.SetSolid(comHelper.CreateColor(0, 0, 255))

' Add new paragraph with text.
Set run = shape.Text.AddParagraph().AddRun("This example shows how to create a new PowerPoint slide with GemBox.Presentation in COM.")

' Set text fill to solid white color.
run.Format.Fill.SetSolid(comHelper.CreateColor(255, 255, 255))

' Get output path and save presentation as PDF file.
path = Server.MapPath(".") & "\ComExample.pdf"
presentation.Save(path)
Response.Write("Presentation saved as '" & path & "'")
// Create ComHelper object and set license. 
// NOTE: If you're using a Professional version you'll need to put your serial key below.
$comHelper = new Com("GemBox.Presentation.ComHelper");
$comHelper->ComSetLicense("FREE-LIMITED-KEY");

// Load input presentaton.
$presentation = $comHelper->Load(getcwd() . "\ComTemplate.pptx");

// Get first slide in the presentation.
$slide = comHelper->GetCollectionItem($presentation->Slides, 0);

// Remove first drawing from the first slide.
$comHelper->RemoveCollectionItemAt($slide->Content->Drawings, 0);

// Get master slide.
$masterSlide = $comHelper->GetCollectionItem($presentation->MasterSlides, 0);

// Get layout slide.
$layoutSlide = $comHelper->GetCollectionItem($masterSlide->LayoutSlides, 0);

// Add new slide to the presentation.
$slide = $comHelper->AddNewSlide($presentation->Slides, $layoutSlide);

// Add new shape to the new slide.
$shape = $slide->Content->AddShape(ShapeGeometryType->RoundedRectangle, 2, 2, 8, 4);

// Set shape fill to solid blue color.
$shape->Format->Fill->SetSolid($comHelper->CreateColor(0, 0, 255));

// Add new paragraph with text.
$run = $shape->Text->AddParagraph()->AddRun("This example shows how to create a new PowerPoint slide with GemBox.Presentation in COM.");

// Set text fill to solid white color.
$run->Format->Fill->SetSolid($comHelper->CreateColor(255, 255, 255));

// Get output path and save presentation as PDF document.
$path = getcwd() . "\ComExample.pdf";
$presentation->Save($path);
echo("Presentation saved as '" . $path . "'");
# Create ComHelper object and set license.
# NOTE: If you're using a Professional version you'll need to put your serial key below.
import win32com.client as COM
comHelper = COM.Dispatch("GemBox.Presentation.ComHelper")
comHelper.ComSetLicense("FREE-LIMITED-KEY")

# Load input presentation.
import os
presentation = comHelper.Load(os.getcwd() + "\\ComTemplate.pptx")

# Get first slide in the presentation.
slide = comHelper.GetCollectionItem(presentation.Slides, 0)

# Remove first drawing from the first slide.
comHelper.RemoveCollectionItemAt(slide.Content.Drawings, 0)

# Get master slide.
masterSlide = comHelper.GetCollectionItem(presentation.MasterSlides, 0)

# Get layout slide.
layoutSlide = comHelper.GetCollectionItem(masterSlide.LayoutSlides, 0)

# Add new slide to the presentation.
slide = comHelper.AddNewSlide(presentation.Slides, layoutSlide)

# Add new shape to the new slide.
shape = slide.Content.AddShape(ShapeGeometryType.RoundedRectangle, 2, 2, 8, 4)

# Set shape fill to solid blue color.
shape.Format.Fill.SetSolid(comHelper.CreateColor(0, 0, 255))

# Add new paragraph with text.
run = shape.Text.AddParagraph().AddRun("This example shows how to create a new PowerPoint slide with GemBox.Presentation in COM.")

# Set text fill to solid white color.
run.Format.Fill.SetSolid(comHelper.CreateColor(255, 255, 255))

# Get output path and save presentation as PDF file.
path = os.getcwd()  + "\\ComExample.pdf"
presentation.Save(path)
print("Presentation saved as '" + path + "'")

Check next sample or find out more about GemBox.Presentation and GemBox Software.