0%

Convert PDF to Power Points Format

If you do not have a PDF reader but still wish to convert PDF to pptx format( for example, when you are making a presentation in an old classroom ), you can utilize this method. This approach enables PDF to slide conversion through Python, avoiding format issues but sacrificing the original LaTeX’s built-in navigation and other functions.

If you are not concerned about layout problems and still desire to utilize these functions (such as the navigation bar and hyper-links), there are numerous free online tools available for selection.

environments

1
2
pip install PyMuPDF
pip install python-pptx

code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import fitz  # PyMuPDF
from pptx import Presentation
from pptx.util import Inches
import os
import re

def pdf_to_ppt(pdf_path, ppt_path):
doc = fitz.open(pdf_path)
ppt = Presentation()

zoom_x = 20.0
zoom_y = 20.0
mat = fitz.Matrix(zoom_x, zoom_y)

for page in doc:

pix = page.get_pixmap(matrix=mat, alpha=False)

img_path = f"page_{page.number}.png"
pix.save(img_path)

slide = ppt.slides.add_slide(ppt.slide_layouts[6])
slide.shapes.add_picture(img_path, Inches(0), Inches(0), width=ppt.slide_width)
ppt.save(ppt_path)

directory = os.getcwd()

pattern = re.compile(r"^page_\d+\.png$")
for filename in os.listdir(directory):
if pattern.match(filename):
file_path = os.path.join(directory, filename)
os.remove(file_path)
print(f"Deleted {file_path}")


pdf_to_ppt("slide.pdf", "output.pptx")

demo

These 2 demos, input.pdf and output.pdf, can be found in my repository