Spaces:
Runtime error
Runtime error
File size: 1,219 Bytes
2ca5c5e 53fe756 2ca5c5e 53fe756 2ca5c5e 53fe756 2ca5c5e 53fe756 2ca5c5e 53fe756 |
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 |
import gradio as gr
from pptx import Presentation
from fpdf import FPDF
import tempfile
import os
def pptx_to_pdf(pptx_file):
# Create a temporary directory to store intermediate images
with tempfile.TemporaryDirectory() as tmpdirname:
pdf = FPDF()
# Load the PowerPoint file
presentation = Presentation(pptx_file.name)
for i, slide in enumerate(presentation.slides):
# Save each slide as an image
img_path = os.path.join(tmpdirname, f"slide_{i}.png")
slide.shapes[0].image.save(img_path)
# Add the image to the PDF
pdf.add_page()
pdf.image(img_path, 0, 0, 210, 297) # A4 size (210mm x 297mm)
# Save the PDF to a file
pdf_output_path = os.path.join(tmpdirname, "output.pdf")
pdf.output(pdf_output_path)
return pdf_output_path
# Create a Gradio interface
iface = gr.Interface(
fn=pptx_to_pdf,
inputs=gr.inputs.File(file_types=[".pptx"]),
outputs=gr.outputs.File(file_types=[".pdf"]),
title="PPTX to PDF Converter",
description="Upload a PowerPoint file to convert it to a PDF without watermarks."
)
# Launch the app
iface.launch()
|