Spaces:
Sleeping
Sleeping
| #!/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() | |