Speaker notes are hidden notes that can be added to slides to help recall some important or key information. Speaker notes are only visible to the presenter, so adding speaker notes in PowerPoint will not affect the overall visual effectiveness of the document. In this article, you will learn how to programmatically add, read or delete speaker notes in a PowerPoint presentation using Spire.Presentation for C++.
- Add Speaker Notes in PowerPoint in C++
- Read Speaker Notes in PowerPoint in C++
- Delete Speaker Notes in PowerPoint in C++
Install Spire.Presentation for C++
There are two ways to integrate Spire.Presentation for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.Presentation for C++ in a C++ Application
Add Speaker Notes in PowerPoint in C++
There are a number of benefits to using speaker notes in a PowerPoint presentation, such as it can help you stay on point and also appear more confident during a presentation. The following are the steps to add speaker notes to a specified slide.
- Create a Presentation instance and load a PowerPoint document using Presentation->LoadFromFile() method.
- Get a specified slide using Presentation->GetSlides()->GetItem(slideIndex) method.
- Add a notes slide to the slide using ISlide->AddNotesSlide() method.
- Create a TextParagraph instance.
- Set text for the paragraph using TextParagraph->SetText() method, and then append the paragraph to the notes slide using NotesSlide->GetNotesTextFrame()->GetParagraphs()->Append() method.
- Save the result document using Presentation->SaveToFile() method.
- C++
#include "Spire.Presentation.o.h" using namespace std; using namespace Spire::Presentation; int main() { //Specify the input and output file paths std::wstring inputFile = L"Data\\Template.pptx"; std::wstring outputFile = L"SpeakerNotes.pptx"; //Create a Presentation instance Presentation* ppt = new Presentation(); //Load a sample PowerPoint document from disk ppt->LoadFromFile(inputFile.c_str()); //Get the second slide ISlide* slide = ppt->GetSlides()->GetItem(1); //Add a notes slide NotesSlide* notesSlide = slide->AddNotesSlide(); //Add paragraphs to the notes slide and set the content of the speaker notes TextParagraph* paragraph = new TextParagraph(); paragraph->SetText(L"Tips for making effective presentations:"); notesSlide->GetNotesTextFrame()->GetParagraphs()->Append(paragraph); paragraph = new TextParagraph(); paragraph->SetText(L"Use the slide master feature to create a consistent and simple design template."); notesSlide->GetNotesTextFrame()->GetParagraphs()->Append(paragraph); paragraph = new TextParagraph(); paragraph->SetText(L"Simplify and limit the number of words on each screen."); notesSlide->GetNotesTextFrame()->GetParagraphs()->Append(paragraph); paragraph = new TextParagraph(); paragraph->SetText(L"Use contrasting colors for text and background."); notesSlide->GetNotesTextFrame()->GetParagraphs()->Append(paragraph); //Set the bullet type and bullet style for specific paragraphs on the notes slide for (int i = 1; i < notesSlide->GetNotesTextFrame()->GetParagraphs()->GetCount(); i++) { notesSlide->GetNotesTextFrame()->GetParagraphs()->GetItem(i)->SetBulletType(TextBulletType::Numbered); notesSlide->GetNotesTextFrame()->GetParagraphs()->GetItem(i)->SetBulletStyle(NumberedBulletStyle::BulletArabicPeriod); } //Save the result file ppt->SaveToFile(outputFile.c_str(), FileFormat::Pptx2013); delete ppt; }
Read Speaker Notes in PowerPoint in C++
To get speaker notes from a notes slide, Spire.Presentation for C++ offers the NotesSlide->GetNotesTextFrame()->GetText() method. The following are the detailed steps.
- Create a Presentation instance and load a PowerPoint document using Presentation->LoadFromFile() method.
- Get a specified slide using Presentation->GetSlides()->GetItem(slideIndex) method.
- Get the notes slide from the slide using ISlide->GetNotesSlide() method.
- Get the speaker notes from the notes slide using NotesSlide->GetNotesTextFrame()->GetText() method, and then save them to a .txt file.
- C++
#include "Spire.Presentation.o.h" using namespace std; using namespace Spire::Presentation; int main() { //Specify the input and output file paths std::wstring inputFile = L"SpeakerNotes.pptx"; std::wstring outputFile = L"GetSpeakerNotes.txt"; //Create a Presentation instance Presentation* presentation = new Presentation(); //Load a sample PowerPoint document presentation->LoadFromFile(inputFile.c_str()); //Get the second slide ISlide* slide = presentation->GetSlides()->GetItem(1); //Get the notes slide from the second slide NotesSlide* notesSlide = slide->GetNotesSlide(); //Get the speaker notes and save to txt file wofstream desFile(outputFile, ios::out); desFile << notesSlide->GetNotesTextFrame()->GetText() << endl; desFile.close(); delete presentation; }
Delete Speaker Notes in PowerPoint in C++
With Spire.Presentation for C++, you are also allowed to remove all speaker notes at once or just remove a specified speaker note from the notes slide. The following are the detailed steps.
- Create a Presentation instance and load a PowerPoint document using Presentation->LoadFromFile() method.
- Get a specified slide using Presentation->GetSlides()->GetItem(slideIndex) method.
- Get the notes slide from the slide using ISlide->GetNotesSlide() method.
- Remove all speaker notes from the notes slide using NotesSlide->GetNotesTextFrame()->GetParagraphs()->Clear() method or remove a specific speaker note from the notes slide using NotesSlide->GetNotesTextFrame()->GetParagraphs()->RemoveAt(paragraphIndex) method.
- Save the result document using Presentation->SaveToFile() method.
- C++
#include "Spire.Presentation.o.h" using namespace std; using namespace Spire::Presentation; int main() { //Specify the input and output file paths std::wstring inputFile = L"SpeakerNotes.pptx"; std::wstring outputFile = L"RemoveSpeakerNotes.pptx"; //Create a Presentation instance Presentation* presentation = new Presentation(); //Load a sample PowerPoint document presentation->LoadFromFile(inputFile.c_str()); //Get the second slide ISlide* slide = presentation->GetSlides()->GetItem(1); //Get the notes slide from the second slide NotesSlide* notesSlide = slide->GetNotesSlide(); //Remove all the speaker notes from notes slide notesSlide->GetNotesTextFrame()->GetParagraphs()->Clear(); //Remove a specific speak note from notes slide //notesSlide->GetNotesTextFrame()->GetParagraphs()->RemoveAt(1); //Save the result file presentation->SaveToFile(outputFile.c_str(), FileFormat::Pptx2013); delete presentation; }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.