Spaces:
Sleeping
Sleeping
Upload pptx2pdf_web_en.py
Browse files- pptx2pdf_web_en.py +11 -2
pptx2pdf_web_en.py
CHANGED
@@ -2,14 +2,23 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import shutil
|
4 |
import subprocess
|
|
|
5 |
import tempfile
|
6 |
from zipfile import ZipFile
|
7 |
|
8 |
def convert_pptx_to_pdf(pptx_path, output_dir):
|
9 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
pdf_path = os.path.join(output_dir, os.path.splitext(os.path.basename(pptx_path))[0] + ".pdf")
|
11 |
result = subprocess.run([
|
12 |
-
|
13 |
pptx_path
|
14 |
], cwd=output_dir, capture_output=True, text=True)
|
15 |
if result.returncode != 0 or not os.path.exists(pdf_path):
|
|
|
2 |
import os
|
3 |
import shutil
|
4 |
import subprocess
|
5 |
+
import sys
|
6 |
import tempfile
|
7 |
from zipfile import ZipFile
|
8 |
|
9 |
def convert_pptx_to_pdf(pptx_path, output_dir):
|
10 |
+
# Determine executable path based on OS
|
11 |
+
if sys.platform.startswith('win'):
|
12 |
+
exe_path = os.path.join('.', 'PptxToPDF.exe')
|
13 |
+
else:
|
14 |
+
exe_path = os.path.join('.', 'PptxToPDF')
|
15 |
+
# Ensure the executable has execute permissions (Linux/Mac)
|
16 |
+
if not os.access(exe_path, os.X_OK):
|
17 |
+
import stat
|
18 |
+
os.chmod(exe_path, os.stat(exe_path).st_mode | stat.S_IEXEC)
|
19 |
pdf_path = os.path.join(output_dir, os.path.splitext(os.path.basename(pptx_path))[0] + ".pdf")
|
20 |
result = subprocess.run([
|
21 |
+
exe_path,
|
22 |
pptx_path
|
23 |
], cwd=output_dir, capture_output=True, text=True)
|
24 |
if result.returncode != 0 or not os.path.exists(pdf_path):
|