Skip to main content

PowerPoint slide copier utility with deep copying of shapes, images, and formatting

Project description

pptx-slide-copier

PowerPoint slide copier utility - Deep copy slides between presentations while preserving all formatting, images, and layouts.

Features

  • Deep copy slides from one PowerPoint presentation to another
  • Preserves all formatting, fonts, colors, and styles
  • Copies images with correct relationship IDs
  • Matches slide layouts via slide masters (supports custom layouts)
  • Compatible with python-pptx 1.0.2+ API
  • Handles themes and layout preservation

Installation

pip install pptx-slide-copier

For development:

git clone https://github.com/SpringMT/pptx-slide-copier.git
cd pptx-slide-copier
pip install -e ".[dev]"

Quick Start

from pptx import Presentation
from pptx_slide_copier import SlideCopier

# Open source and target presentations
source_prs = Presentation("source.pptx")
target_prs = Presentation("target.pptx")

# Copy slide 0 from source to target
copied_slide = SlideCopier.copy_slide(source_prs, 0, target_prs)

# Save the target presentation
target_prs.save("output.pptx")

Usage

Basic Slide Copying

from pptx import Presentation
from pptx_slide_copier import SlideCopier

# Load presentations
source = Presentation("template.pptx")
target = Presentation()  # Create new presentation

# Copy first slide (index 0)
SlideCopier.copy_slide(source, 0, target)

# Copy multiple slides
for i in range(3):
    SlideCopier.copy_slide(source, i, target)

target.save("output.pptx")

Copying to Presentation Based on Template

For best results (to preserve themes and layouts), create the target presentation from the same template:

from pptx import Presentation
from pptx_slide_copier import SlideCopier

# Load template
template = Presentation("template.pptx")

# Create target from same template to preserve theme
target = Presentation("template.pptx")

# Remove all slides from target
while len(target.slides) > 0:
    rId = target.slides._sldIdLst[0].rId
    target.part.drop_rel(rId)
    del target.slides._sldIdLst[0]

# Now copy slides
SlideCopier.copy_slide(template, 0, target)

target.save("output.pptx")

How It Works

Deep Copying at XML Level

The library uses deepcopy at the XML element level to ensure all shape properties, formatting, and attributes are preserved:

from copy import deepcopy
new_element = deepcopy(shape.element)
dest_slide.shapes._spTree.insert_element_before(new_element, "p:extLst")

Image Relationship Mapping

Images are copied with proper relationship ID mapping to ensure they display correctly:

  1. Copy image data from source slide
  2. Add image to target presentation
  3. Map old relationship IDs to new ones
  4. Update XML references in copied shapes

Layout Matching

Slide layouts are matched via slide masters to support custom layouts:

  1. Find source slide's layout and master
  2. Match master by name in target presentation
  3. Find matching layout within the matched master
  4. Fall back to index-based matching if name match fails

Technical Details

  • python-pptx 1.0.2+ compatibility: Handles both old and new API for get_or_add_image_part()
  • XML namespaces: Correctly handles presentationml, drawingml, and relationship namespaces
  • Theme preservation: Works best when target presentation is created from same template
  • Error handling: Gracefully continues if individual shapes or images fail to copy

Testing

pytest

With coverage:

pytest --cov=pptx_slide_copier --cov-report=html

License

MIT

Author

SpringMT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pptx_slide_copier-0.1.2.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pptx_slide_copier-0.1.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pptx_slide_copier-0.1.2.tar.gz.

File metadata

  • Download URL: pptx_slide_copier-0.1.2.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for pptx_slide_copier-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8a2b1819fbd08e28e0846c9daca7031bed64ea59e8ecb75a879b8f3522238e66
MD5 aed47fb9a87bfda5bf380848ff724f35
BLAKE2b-256 570698e07801e2d3705423c16bd79dbc94c4c900ec9a54c43b95e423608008a0

See more details on using hashes here.

File details

Details for the file pptx_slide_copier-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pptx_slide_copier-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a6756a9d1855fbdce4d8c9e4bd8750c0f2e66f75b1680477f5c461a0035f0f70
MD5 bf27b06b5db9ffc3c577238b25c25c9d
BLAKE2b-256 82bf3866773c1149acfcf760e85589fc509aa0e38218d95a7b2a721cbf1ac4cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page