def convert_ppt_to_images(input_file, output_folder): """ Converts a PowerPoint file (.ppt or .pptx) to images using LibreOffice. Each slide is saved as a separate image in the output folder. """ if not os.path.exists(output_folder): os.makedirs(output_folder) # Convert the PowerPoint file to images using LibreOffice command = [ 'libreoffice', '--headless', '--convert-to', 'png', '--outdir', output_folder, input_file ] try: subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(f"PPT file converted to images: {input_file}") except subprocess.CalledProcessError as e: print(f"Error converting PPT to images: {e.stderr.decode()}") return False # Rename the generated images to follow the naming convention base_name = os.path.splitext(os.path.basename(input_file))[0] for i, file_name in enumerate(sorted(os.listdir(output_folder))): if file_name.endswith('.png'): new_name = f"{base_name}_{i + 1}.png" os.rename(os.path.join(output_folder, file_name), os.path.join(output_folder, new_name)) return True