54d7b85bed
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
import fitz
|
|
from pptx import Presentation
|
|
from pptx.util import Inches
|
|
import io
|
|
import os
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
PDF_PATH = os.path.join(HERE, "PrayInFaith.pdf")
|
|
OUT_PATH = os.path.join(HERE, "PrayInFaith.pptx")
|
|
DPI = 150
|
|
|
|
SLIDE_W = Inches(13.333) # widescreen landscape
|
|
SLIDE_H = Inches(7.5)
|
|
|
|
doc = fitz.open(PDF_PATH)
|
|
prs = Presentation()
|
|
prs.slide_width = SLIDE_W
|
|
prs.slide_height = SLIDE_H
|
|
blank_layout = prs.slide_layouts[6]
|
|
|
|
for i, page in enumerate(doc, start=1):
|
|
mat = fitz.Matrix(DPI / 72, DPI / 72)
|
|
pix = page.get_pixmap(matrix=mat, alpha=False)
|
|
img = io.BytesIO(pix.tobytes("png"))
|
|
|
|
slide = prs.slides.add_slide(blank_layout)
|
|
aspect = pix.width / pix.height
|
|
h = SLIDE_H
|
|
w = int(h * aspect)
|
|
if w > SLIDE_W:
|
|
w = SLIDE_W
|
|
h = int(w / aspect)
|
|
left = (SLIDE_W - w) // 2
|
|
top = (SLIDE_H - h) // 2
|
|
slide.shapes.add_picture(img, left, top, width=w, height=h)
|
|
print(f" Slide: page {i}")
|
|
|
|
prs.save(OUT_PATH)
|
|
print(f"\nSaved: {OUT_PATH}")
|