Spaces:
Sleeping
Sleeping
File size: 1,585 Bytes
80a3675 | 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 38 39 40 41 42 43 44 45 46 47 48 | #!/usr/bin/env python3
"""PDF to PowerPoint converter."""
import argparse, json, sys
from pathlib import Path
def convert(input_path, output_path):
from PyPDF2 import PdfReader
from pptx import Presentation
from pptx.util import Inches, Pt
reader = PdfReader(input_path)
prs = Presentation()
prs.slide_width = Inches(10)
prs.slide_height = Inches(7.5)
for i, page in enumerate(reader.pages):
text = page.extract_text() or ''
slide_layout = prs.slide_layouts[5] # blank layout
slide = prs.slides.add_slide(slide_layout)
txBox = slide.shapes.add_textbox(Inches(0.5), Inches(0.5), Inches(9), Inches(6.5))
tf = txBox.text_frame
tf.word_wrap = True
p = tf.paragraphs[0]
p.text = text
p.font.size = Pt(10)
if not output_path:
output_path = str(Path(input_path).with_suffix('.pptx'))
prs.save(output_path)
return output_path
def main():
parser = argparse.ArgumentParser(description='Convert PDF to PowerPoint')
parser.add_argument('--input', required=True)
parser.add_argument('--output', required=True)
args = parser.parse_args()
try:
result = convert(args.input, args.output)
print(json.dumps({"success": True, "output": result, "message": "PDF converted to PowerPoint successfully"}))
except Exception as e:
print(json.dumps({"success": False, "output": "", "message": str(e)}))
sys.exit(1)
if __name__ == '__main__':
main()
|