使用 Notes 幻灯片

幻灯片可以有与之相关的注释。这些可能最常在注释窗格中遇到,在 PowerPoint “Normal” 视图的幻灯片下方,它可能会说 “Click to add notes”。

每当幻灯片出现在主面板上时,这里添加的注释就会出现。它们也出现在 Presenter ViewNotes Page 视图中,都可以从菜单中获得。

Notes可以包含富文本,通常是项目符号、粗体、不同字体大小和颜色等。Notes Page 视图拥有比 Normal 视图中的注释窗格更强大的工具来编辑注释文本。

在 API 和底层 XML 中,包含文本的对象称为 Notes Slide。这是因为在内部,Notes 幻灯片实际上是幻灯片的专门化实例。它包含形状,其中许多是占位符,并允许插入新的形状,如图片(可能是一个标志)、自动形状、表格和图表。因此,处理笔记幻灯片就像处理普通幻灯片一样。

每张幻灯片可以有零张或一张 notes 幻灯片。第一次使用笔记幻灯片时,就创建了笔记幻灯片,通常可以在幻灯片中添加笔记文本。一旦创建,它就会保留,即使所有的文本都被删除了。

Note 母板

新的笔记幻灯片是用 笔记母版 作为模板创建的。演示文稿在 PowerPoint 中创建时没有笔记主。一个是在第一次需要时根据powerpoint内部预置的默认值创建的,通常是在第一张幻灯片创建时。也可以通过进入 Notes 母版 视图来创建,并且几乎可以肯定是通过编辑在那里找到的 母版 视图来创建的(不过还没有尝试过)。一场演讲最多只能有笔记母版。

The notes master governs the look and feel of notes pages, which can be viewed on-screen but are really designed for printing out. So if you want your notes page print-outs to look different from the default, you can make a lot of customizations by editing the notes master. You access the notes master editor using View > Master > Notes Master on the menu (on my version at least). Notes slides created using python-pptx will have the look and feel of the notes master in the presentation file you opened to create the presentation.

On creation, certain placeholders (slide image, notes, slide number) are copied from the notes master onto the new notes slide (if they have not been removed from the master). These “cloned” placeholders inherit position, size, and formatting from their corresponding notes master placeholder. If the position, size, or formatting of a notes slide placeholder is changed, the changed property is no long inherited (unchanged properties, however, continue to be inherited).

Notes Slide basics

Enough talk, let’s show some code. Let’s say you have a slide you’re working with and you want to see if it has a notes slide yet:

>>> slide.has_notes_slide
False

Ok, not yet. Good. Let’s add some notes:

>>> notes_slide = slide.notes_slide
>>> text_frame = notes_slide.notes_text_frame
>>> text_frame.text = 'foobar'

Alright, simple enough. Let’s look at what happened here:

  • slide.notes_slide gave us the notes slide. In this case, it first created that notes slide based on the notes master. If there was no notes master, it created that too. So a lot of things can happen behind the scenes with this call the first time you call it, but if we called it again it would just give us back the reference to the same notes slide, which it caches, once retrieved.

  • notes_slide.notes_text_frame gave us the TextFrame object that contains the actual notes. The reason it’s not just notes_slide.text_frame is that there are potentially more than one. What this is doing behind the scenes is finding the placeholder shape that contains the notes (as opposed to the slide image, header, slide number, etc.) and giving us that particular text frame.

  • A text frame in a notes slide works the same as one in a regular slide. More precisely, a text frame on a shape in a notes slide works the same as in any other shape. We used the .text property to quickly pop some text in there.

Using the text frame, you can add an arbitrary amount of text, formatted however you want.

Notes Slide Placeholders

What we haven’t explicitly seen so far is the shapes on a slide master. It’s easy to get started with that:

>>> notes_placeholder = notes_slide.notes_placeholder

This notes placeholder is just like a body placeholder we saw a couple sections back. You can change its position, size, and many other attributes, as well as get at its text via its text frame.

You can also access the other placeholders:

>>> for placeholder in notes_slide.placeholders:
...   print placeholder.placeholder_format.type
...
SLIDE_IMAGE (101)
BODY (2)
SLIDE_NUMBER (13)

and also the shapes (a superset of the placeholders):

>>> for shape in notes_slide.shapes:
...   print shape
...
<pptx.shapes.placeholder.NotesSlidePlaceholder object at 0x11091e890>
<pptx.shapes.placeholder.NotesSlidePlaceholder object at 0x11091e750>
<pptx.shapes.placeholder.NotesSlidePlaceholder object at 0x11091e990>

In the common case, the notes slide contains only placeholders. However, if you added an image, for example, to the notes slide, that would show up as well. Note that if you added that image to the notes master, perhaps a logo, it would appear on the notes slide “visually”, but would not appear as a shape in the notes slide shape collection. Rather, it is visually “inherited” from the notes master.