Created
November 2, 2021 11:41
-
-
Save jossef/34299361853c1c2746418648731fc34f to your computer and use it in GitHub Desktop.
pdf to pptx as raster images (figma export workaround)
This file contains hidden or 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
| from pptx import Presentation | |
| import fitz | |
| import os | |
| import tempfile | |
| pdf_file_path = r'path/to/pdf/file.pdf' | |
| pptx_file_path = r'path/to/pptx/file.pptx' | |
| presentation = Presentation() | |
| blank_slide_layout = presentation.slide_layouts[6] | |
| with tempfile.TemporaryDirectory() as temp_dir_path: | |
| doc = fitz.open(pdf_file_path) | |
| for index, page in enumerate(doc): | |
| slide_pixmap = page.get_pixmap() | |
| slide_image_file_name = f"{str(index).zfill(3)}.png" | |
| slide_image_file_path = os.path.join(temp_dir_path, slide_image_file_name) | |
| slide_pixmap.save(slide_image_file_path) | |
| slide = presentation.slides.add_slide(blank_slide_layout) | |
| slide_picture = slide.shapes.add_picture(slide_image_file_path, 0, 0) | |
| presentation.slide_width = slide_picture.width | |
| presentation.slide_height = slide_picture.height | |
| presentation.save(pptx_file_path) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From time to time, some folks insist on me sending them .pptx decks instead of pdf.
I'm designing my decks on Figma, which is a great app.
Exporting .pptx is not supported by Figma. I've bumped into a Figma plugin called PitchDeck. I gave it a try yet for a pixel-perfect someone like me, it's not usable. some parts of my design go missing in the export, font's change, not acceptable.
So I made this tiny Python script, to raster .pdf file pages into images and then for each image make slide in a .pptx file.
Enjoy my dudes. enjoy.