Skip to content

Instantly share code, notes, and snippets.

@jossef
Created November 2, 2021 11:41
Show Gist options
  • Select an option

  • Save jossef/34299361853c1c2746418648731fc34f to your computer and use it in GitHub Desktop.

Select an option

Save jossef/34299361853c1c2746418648731fc34f to your computer and use it in GitHub Desktop.
pdf to pptx as raster images (figma export workaround)
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)
@jossef
Copy link
Author

jossef commented Nov 2, 2021

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.

  • Is this storage efficient? no. but frankly, who cares when storage nowadays is so cheap
  • Are slides in the .pptx editable? no
  • Solves my hassle? definitely yes

Enjoy my dudes. enjoy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment