officefileapi-405531-presentation-api-organize-notes.md
The DevExpress Presentation API library allows you to add, edit, and remove slide notes. Notes are visible to the presenter only. You can also customize the Notes Page layout and print slides with their notes, headers, and footers.
You can specify shared visual parameters for all notes or change settings for individual notes. You can also specify headers and footers for the Notes Page layout.
Create a Notes Master (note master layout) to enable notes in a presentation. The NotesMaster object is a shared layout that contains visual parameters (location on a slide, text format settings, background, and so on) for headers, footers, and notes in the Notes Page view.
The following code snippet creates a new note master layout with default settings (includes note and slide number placeholders):
using DevExpress.Docs.Presentation;
//...
using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\Presentation.pptx"))) {
if (presentation.NotesMaster == null) {
presentation.NotesMaster = new NotesMaster(name: "notesMaster");
}
}
Imports DevExpress.Docs.Presentation
'...
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
If presentation.NotesMaster Is Nothing Then
presentation.NotesMaster = New NotesMaster(name:= "notesMaster")
End If
End Using
Create a new NotesSlide object and set it as the Slide.Notes property value. Use the NotesSlide.TextArea.Text property to specify note text.
The new note inherits its visual parameters from the Presentation.NotesMaster object.
The following code snippet adds a note to the first slide:
using DevExpress.Docs.Presentation;
//...
using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\Presentation.pptx"))) {
Slide slide = presentation.Slides[0];
slide.Notes = new NotesSlide(presentation.NotesMaster);
slide.Notes.TextArea.Text = "test note";
}
Imports DevExpress.Docs.Presentation
'...
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
Dim slide As Slide = presentation.Slides(0)
slide.Notes = New NotesSlide(presentation.NotesMaster)
slide.Notes.TextArea.Text = "test note"
End Using
The Presentation.NotesMaster property obtains note master layout. The following properties obtain placeholder shapes:
You can change the text formatting, shape settings, and background of all elements that use this Notes Master.
Note
A shape’s default character formatting settings may not produce consistent results across different presentation viewers. To ensure consistent appearance, specify character formatting settings explicitly in code.
The following code snippet changes note master layout settings:
using DevExpress.Docs;
using DevExpress.Docs.Presentation;
using System.Drawing;
//...
using (var presentation = new Presentation(File.ReadAllBytes (@"C:\Documents\Presentation.pptx")))
{
var notesMaster = presentation.NotesMaster;
// Specify header, footer, and date and time:
notesMaster.ActualHeaderPlaceholder.TextArea.Text = "DevExpress Test Presentation";
notesMaster.ActualFooterPlaceholder.TextArea.Text = "Created by DevExpress Presentation API";
notesMaster.ActualDateTimePlaceholder.TextArea.Text = DateTime.Now.ToString();
// Change notes master background:
SolidFill fill = new SolidFill(Color.LightCyan);
notesMaster.Background = new CustomSlideBackground(fill);
// Change default text formatting settings:
ParagraphProperties pp = new ParagraphProperties();
pp.TextProperties = new TextProperties() { HighlightColor = new OfficeColor(Color.Red) };
notesMaster.TextStyle.ParagraphProperties = pp;
notesMaster.TextStyle.Level1ParagraphProperties = pp;
presentation.SaveDocument(new FileStream("C://Documents//presentation-updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite));
}
Imports DevExpress.Docs
Imports DevExpress.Docs.Presentation
Imports System.Drawing
'...
Using presentation = New Presentation("C:\Documents\Presentation.pptx")
Dim notesMaster = presentation.NotesMaster
' Specify header, footer, and date and time:
notesMaster.ActualHeaderPlaceholder.TextArea.Text = "DevExpress Test Presentation"
notesMaster.ActualFooterPlaceholder.TextArea.Text = "Created by DevExpress Presentation API"
notesMaster.ActualDateTimePlaceholder.TextArea.Text = Date.Now.ToString()
' Change notes master background:
Dim fill As New SolidFill(Color.LightCyan)
notesMaster.Background = New CustomSlideBackground(fill)
' Change default text formatting settings:
Dim pp As ParagraphProperties = New ParagraphProperties()
pp.TextProperties = New TextProperties() With {
.HighlightColor = New OfficeColor(Color.Red)
}
notesMaster.TextStyle.ParagraphProperties = pp
notesMaster.TextStyle.Level1ParagraphProperties = pp
presentation.SaveDocument(New FileStream("C://Documents//presentation-updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite))
End Using
The Slide.Notes property allows you to obtain slide notes. The following settings are available:
NotesSlide.TextArea.TextPropertiesGets or sets text formatting settings.TextAreaBase.TextGets or sets the note text.ActualNotesPlaceholderObtains the note placeholder shape.
The following code snippet obtains and changes note settings:
using DevExpress.Docs;
using DevExpress.Docs.Presentation;
using System.Drawing;
//...
using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\Presentation.pptx"))) {
Slide slide = presentation.Slides[0];
var note = slide.Notes;
note.TextArea.Text = "updated text";
// Create paragraph properties
ParagraphProperties textParagraphProperties = new ParagraphProperties() {
TextProperties = new TextProperties() { HighlightColor = new OfficeColor(Color.Red) }
};
// Apply text properties to the note
note.TextArea.ParagraphProperties = textParagraphProperties;
note.TextArea.Level1ParagraphProperties = textParagraphProperties;
presentation.SaveDocument(new FileStream("C://Documents//presentation_updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite));
}
Imports DevExpress.Docs
Imports DevExpress.Docs.Presentation
Imports System.Drawing
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
Dim slide As Slide = presentation.Slides(0)
Dim note = slide.Notes
note.TextArea.Text = "updated text"
' Create paragraph properties
Dim textParagraphProperties As ParagraphProperties = New ParagraphProperties() With {
.TextProperties = New TextProperties() With {
.HighlightColor = New OfficeColor(Color.Red)
}
}
' Apply text properties to the note
note.TextArea.ParagraphProperties = textParagraphProperties
note.TextArea.Level1ParagraphProperties = textParagraphProperties
' Save the updated presentation
Using fs As New FileStream("C:\Documents\presentation_updated.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite)
presentation.SaveDocument(fs)
End Using
End Using
Check whether the slide contains notes and set the Slide.Notes property to null to remove a note.
The following code snippet removes all notes:
using DevExpress.Docs.Presentation;
//...
using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\presentation.pptx")))
{
foreach (var note in presentation.Slides.Where(i => i.Notes != null).ToList())
{
int index = presentation.Slides.IndexOf(note);
presentation.Slides[index].Notes = null;
}
presentation.SaveDocument(new FileStream("C:\\Documents\\PresentationNoNotes.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite));
}
Imports DevExpress.Docs.Presentation
'...
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\presentation.pptx"))
For Each note In presentation.Slides.Where(Function(i) i.Notes IsNot Nothing).ToList()
Dim index As Integer = presentation.Slides.IndexOf(note)
presentation.Slides(index).Notes = Nothing
Next note
presentation.SaveDocument(New FileStream("C:\Documents\PresentationNoNotes.pptx", FileMode.OpenOrCreate, FileAccess.ReadWrite))
End Using