Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Solstice-Health/python-pptx

 
 

Repository files navigation

python-pptx (Solstice Health Fork)

Forked from scanny/python-pptx

This is a fork of the original python-pptx library by Steve Canny, enhanced with additional features for Solstice Health's internal use.

About This Fork

This repository is a maintained fork of the excellent python-pptx library created by Steve Canny. We are grateful for the original work and continue to respect the MIT license under which it was released.

Original Project: https://github.com/scanny/python-pptx

Original Documentation: https://python-pptx.readthedocs.org/en/latest/

Modifications in This Fork

This fork includes the following enhancements beyond the original python-pptx:

  • Slide Insertion at Specific Index: Added Slides.insert_slide(index, source_slide, duplicate=False) method to insert slides at any position in the presentation, not just append to the end. Set duplicate=True to clone the source slide (shapes, media, etc.) instead of creating a blank slide.
  • Text Style Extraction: Added Slide.extract_text_styles() helper that captures fonts, colors, and paragraph hierarchy for title/text placeholders and other text shapes. Useful for building “format painter” workflows or analytics.

All modifications maintain backward compatibility with the original library.

About python-pptx

python-pptx is a Python library for creating, reading, and updating PowerPoint (.pptx) files.

A typical use would be generating a PowerPoint presentation from dynamic content such as a database query, analytics output, or a JSON payload, perhaps in response to an HTTP request and downloading the generated PPTX file in response. It runs on any Python capable platform, including macOS and Linux, and does not require the PowerPoint application to be installed or licensed.

It can also be used to analyze PowerPoint files from a corpus, perhaps to extract search indexing text and images.

It can also be used to simply automate the production of a slide or two that would be tedious to get right by hand, which is how this all got started.

Installation

This fork can be installed directly from GitHub:

pip install git+https://github.com/Solstice-Health/python-pptx.git

Documentation

For general python-pptx documentation, please refer to the original documentation.

For fork-specific features, see the examples below.

Example Usage (Fork-Specific Feature)

Inserting a slide at a specific position:

from pptx import Presentation

prs = Presentation('existing.pptx')

# Get a reference slide (to copy its layout)
source_slide = prs.slides[0]

# Insert a new slide at position 1 (after the first slide)
new_slide = prs.slides.insert_slide(1, source_slide)
clone_slide = prs.slides.insert_slide(2, source_slide, duplicate=True)

# The new slide inherits the layout from source_slide
# and can be modified as needed
new_slide.shapes.title.text = "Inserted Slide"

prs.save('output.pptx')

Using negative indices (Python-style):

# Insert before the last slide
prs.slides.insert_slide(-1, source_slide)

# Insert at the beginning
prs.slides.insert_slide(0, source_slide)

Extracting text styles from a slide:

format_info = source_slide.extract_text_styles()

# Grab title font info
title = format_info["title"]
title_font = title["paragraphs"][0]["runs"][0]["font"]
print(title_font["name"], title_font["size"], title_font["color"]["rgb"])

# Iterate all text-bearing shapes
for shape in format_info["shapes"]:
    print(shape["name"], len(shape["paragraphs"]))

Sample output structure (pretty-printed for clarity):

{
    "title": {
        "shape_id": 2,
        "name": "Title 1",
        "placeholder_type": "TITLE",
        "paragraphs": [
            {
                "alignment": "CENTER",
                "level": 0,
                "font": {"name": "Calibri", "size": 32.0},
                "runs": [
                    {
                        "text": "Quarterly Update",
                        "font": {
                            "name": "Arial",
                            "size": 42.0,
                            "bold": true,
                            "fill_type": "SOLID",
                            "color": {"type": "RGB", "rgb": "123456"}
                        }
                    }
                ]
            }
        ]
    },
    "placeholders": {
        "TITLE": [...],
        "BODY": [...]
    },
    "shapes": [
        {"shape_id": 2, "name": "Title 1", "paragraphs": [...]},
        {"shape_id": 4, "name": "Content Placeholder 3", "paragraphs": [...]},
        {
            "shape_id": 6,
            "name": "Grouped Text Box",
            "group_path": [{"shape_id": 5, "name": "Group 13"}],
            "paragraphs": [...]
        }
    ]
}

Contributing

This is a private fork maintained by Solstice Health for internal use. If you're interested in contributing to the original project, please visit the upstream repository.

License

This fork maintains the MIT License of the original project. See the LICENSE file for complete details, including both the original copyright by Steve Canny and additional copyright by Solstice Health for modifications.

Both the original work and modifications are available under the same permissive MIT License terms.

Credits

Acknowledgments

We are deeply grateful to Steve Canny and all contributors to the original python-pptx project. This library has been invaluable, and we're committed to maintaining compliance with the MIT License and giving proper attribution.

For more information about python-pptx, browse the examples with screenshots to get a quick idea of what you can do with this library.

About

Create Open XML PowerPoint documents in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 94.4%
  • Gherkin 5.5%
  • Makefile 0.1%