Last active
May 12, 2020 17:37
-
-
Save ThibaudLamothe/22df6c1e9230509c272f41ad091408b9 to your computer and use it in GitHub Desktop.
Replacing texts into a powerpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# parameters | |
input_file = 'original.pptx' | |
output_file = 'translated.pptx' | |
# Opening presentation | |
prs = Presentation(input_file) | |
# List of all texts [text1, text2, ....] | |
corpus = extract_text_frames_from(prs) | |
# Dictionnary : {text1:translation1, text2:translation2, ...} | |
corpus_translated = get_translation(corpus) | |
# Replacing all values | |
for text_frame in all_presentation_text_frames: | |
for paragraph in text_frame.paragraphs: | |
old_text = paragraph.text | |
new_text = corpus_translated[old_text] | |
paragraph.text = new_text | |
# Saving results | |
prs.save(output_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment