Presentations — python-pptx 1.0.0 documentation (original) (raw)
A presentation is opened using the Presentation()
function, provided directly by the pptx
package:
from pptx import Presentation
This function returns a Presentation object which is the root of a graph containing the components that constitute a presentation, e.g. slides, shapes, etc. All existing presentation components are referenced by traversing the graph and new objects are added to the graph by calling a method on that object’s container. Consequently, python-pptx objects are generally not constructed directly.
Example:
load a presentation
prs = Presentation(path_to_pptx_file)
get reference to first shape in first slide
sp = prs.slides[0].shapes[0]
add a picture shape to slide
pic = sld.shapes.add_picture(path, x, y, cx, cy)
Presentation function¶
This function is the only reference that must be imported to work with presentation files. Typical use interacts with many other classes, but there is no need to construct them as they are accessed using a property or method of their containing object.
pptx.
Presentation
(pptx: str | IO[bytes] | None = None) → presentation.Presentation[source]¶
Return a Presentation object loaded from pptx, where pptx can be either a path to a .pptx
file (a string) or a file-like object. If_pptx_ is missing or None
, the built-in default presentation “template” is loaded.
Presentation objects¶
class pptx.presentation.
Presentation
[source]¶
PresentationML (PML) presentation.
Not intended to be constructed directly. Use pptx.Presentation() to open or create a presentation.
core_properties
¶
CoreProperties instance for this presentation.
Provides read/write access to the Dublin Core document properties for the presentation.
notes_master
¶
Instance of NotesMaster
for this presentation.
If the presentation does not have a notes master, one is created from a default template and returned. The same single instance is returned on each call.
save
(file: str | IO[bytes])[source]¶
Writes this presentation to file.
file can be either a file-path or a file-like object open for writing bytes.
slide_height
¶
Height of slides in this presentation, in English Metric Units (EMU).
Returns None
if no slide width is defined. Read/write.
slide_layouts
¶
SlideLayouts collection belonging to the first SlideMaster of this presentation.
A presentation can have more than one slide master and each master will have its own set of layouts. This property is a convenience for the common case where the presentation has only a single slide master.
slide_master
¶
First SlideMaster object belonging to this presentation. Typically, presentations have only a single slide master. This property provides simpler access in that common case.
SlideMasters collection of slide-masters belonging to this presentation.
slide_width
¶
Width of slides in this presentation, in English Metric Units (EMU). Returns None
if no slide width is defined. Read/write.
Slides object containing the slides in this presentation.
CoreProperties objects¶
Each Presentation object has a CoreProperties object accessed via itscore_properties
attribute that provides read/write access to the so-called core properties for the document. The core properties are author, category, comments, content_status, created, identifier, keywords, language, last_modified_by, last_printed, modified, revision, subject, title, and version.
Each property is one of three types, str
, datetime.datetime
, or int
. String properties are limited in length to 255 characters and return an empty string (‘’) if not set. Date properties are assigned and returned as datetime.datetime
objects without timezone, i.e. in UTC. Any timezone conversions are the responsibility of the client. Date properties return None
if not set.
python-pptx does not automatically set any of the document core properties other than to add a core properties part to a presentation that doesn’t have one (very uncommon). If python-pptx adds a core properties part, it contains default values for the title, last_modified_by, revision, and modified properties. Client code should change properties like revision and last_modified_by explicitly if that behavior is desired.
class pptx.opc.coreprops.
CoreProperties
¶
string – An entity primarily responsible for making the content of the resource.
category
¶
string – A categorization of the content of this package. Example values might include: Resume, Letter, Financial Forecast, Proposal, or Technical Presentation.
string – An account of the content of the resource.
content_status
¶
string – completion status of the document, e.g. ‘draft’
created
¶
datetime – time of intial creation of the document
identifier
¶
string – An unambiguous reference to the resource within a given context, e.g. ISBN.
keywords
¶
string – descriptive words or short phrases likely to be used as search terms for this document
language
¶
string – language the document is written in
last_modified_by
¶
string – name or other identifier (such as email address) of person who last modified the document
last_printed
¶
datetime – time the document was last printed
modified
¶
datetime – time the document was last modified
revision
¶
int – number of this revision, incremented by the PowerPoint® client once each time the document is saved. Note however that the revision number is not automatically incremented by python-pptx.
subject
¶
string – The topic of the content of the resource.
title
¶
string – The name given to the resource.
version
¶
string – free-form version string