Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Remove unused slide layouts #5

Open
chahu opened this issue Mar 16, 2023 · 0 comments
Open

Suggestion: Remove unused slide layouts #5

chahu opened this issue Mar 16, 2023 · 0 comments

Comments

@chahu
Copy link

chahu commented Mar 16, 2023

I have a script that depends on python-pptx that removes unused slide layouts. This can amount to a huge size reduction in some cases. Would be cool if this functionality was included in this project.

See below standalone python script to get an idea:

#!/usr/bin/env python3

import argparse
import collections.abc  # Python 3.10 workaround https://github.com/scanny/python-pptx/issues/762
from pptx import Presentation

parser = argparse.ArgumentParser(description="Remove unused pptx slide layouts")
parser.add_argument("filename")
parser.add_argument("-o", "--output", required=True, help="Where to save the output")
args = parser.parse_args()

count = 0
prs = Presentation(args.filename)
for slide_layout in prs.slide_layouts:
    if not slide_layout.used_by_slides:
        print(f"Removing unused slide layout:  {slide_layout.name}")
        prs.slide_layouts.remove(slide_layout)
        count += 1

if count == 0:
    print("All slide layouts in use. Nothing to do.")
else:
    prs.save(args.output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant