├── requirements.txt ├── ReadMe.md └── convert.py /requirements.txt: -------------------------------------------------------------------------------- 1 | lxml==4.2.1 2 | pdf2image==0.1.14 3 | Pillow==5.1.0 4 | python-pptx==0.6.10 5 | XlsxWriter==1.0.5 6 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | # PDF to Powerpoint Converter 2 | 3 | This script converts PDF files into Powerpoint, but does each slide as an image. This ensures there are no font issues or other problems, and the slides look the same in Powerpoint as they did in PDF. 4 | 5 | ## Why?! 6 | 7 | Many AV setups mean that if you are using PDF slides you cannot have 'next slide' on a confidence display whilst you speak. Having come up against this at multiple conferences, I decided I'd convert my decks (which I was making in Keynote) from PDF to Powerpoint. Most converters try to keep the text as text but often introduces many inconsistencies. 8 | 9 | ## Usage 10 | 11 | Running: 12 | 13 | `python convert.py example.pdf` 14 | 15 | Will produce `example.pptx` in the same folder. 16 | 17 | ## Dependencies 18 | 19 | In addition to the python packages in requirements.txt, `poppler` is also required in order for this script to work. On Mac OS you can install this with `brew install poppler`. 20 | -------------------------------------------------------------------------------- /convert.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | from PIL import Image 4 | from pdf2image import convert_from_path 5 | from pptx import Presentation 6 | from pptx.util import Inches 7 | from io import BytesIO 8 | 9 | pdf_file = sys.argv[1] 10 | print() 11 | print("Converting file: " + pdf_file) 12 | print() 13 | 14 | # Prep presentation 15 | prs = Presentation() 16 | blank_slide_layout = prs.slide_layouts[6] 17 | 18 | # Create working folder 19 | base_name = pdf_file.split(".pdf")[0] 20 | 21 | # Convert PDF to list of images 22 | print("Starting conversion...") 23 | slideimgs = convert_from_path(pdf_file, 300, fmt='ppm', thread_count=2) 24 | print("...complete.") 25 | print() 26 | 27 | # Loop over slides 28 | for i, slideimg in enumerate(slideimgs): 29 | if i % 10 == 0: 30 | print("Saving slide: " + str(i)) 31 | 32 | imagefile = BytesIO() 33 | slideimg.save(imagefile, format='tiff') 34 | imagedata = imagefile.getvalue() 35 | imagefile.seek(0) 36 | width, height = slideimg.size 37 | 38 | # Set slide dimensions 39 | prs.slide_height = height * 9525 40 | prs.slide_width = width * 9525 41 | 42 | # Add slide 43 | slide = prs.slides.add_slide(blank_slide_layout) 44 | pic = slide.shapes.add_picture(imagefile, 0, 0, width=width * 9525, height=height * 9525) 45 | 46 | # Save Powerpoint 47 | print() 48 | print("Saving file: " + base_name + ".pptx") 49 | prs.save(base_name + '.pptx') 50 | print("Conversion complete. :)") 51 | print() --------------------------------------------------------------------------------