Changes that validate libreoffice export
This commit is contained in:
parent
fad3f36436
commit
9da8ad446f
1 changed files with 18 additions and 13 deletions
|
|
@ -8,21 +8,26 @@ from image_processor.utils import get_page_images_from_pdf
|
|||
|
||||
def get_pdf_from_pptx(pptx_path: str, temp_dir: str) -> str:
|
||||
base_name = os.path.splitext(os.path.basename(pptx_path))[0]
|
||||
print(base_name)
|
||||
|
||||
result = subprocess.run(
|
||||
f'{os.getenv("LIBREOFFICE")} --convert-to pdf "{pptx_path}" --outdir "{temp_dir}"',
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
print("LibreOffice stdout:", result.stdout)
|
||||
print("LibreOffice stderr:", result.stderr)
|
||||
|
||||
pdf_filename = f"{base_name}.pdf"
|
||||
|
||||
pdf_path = os.path.join(temp_dir, pdf_filename)
|
||||
|
||||
retry_count = 0
|
||||
while not os.path.exists(pdf_path):
|
||||
result = subprocess.run(
|
||||
f'{os.getenv("LIBREOFFICE")} --convert-to pdf "{pptx_path}" --outdir "{temp_dir}"',
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
print("LibreOffice stdout:", result.stdout)
|
||||
print("LibreOffice stderr:", result.stderr)
|
||||
|
||||
retry_count += 1
|
||||
if retry_count > 3:
|
||||
raise Exception("Failed to convert PPTX to PDF")
|
||||
|
||||
pdf_path = os.path.join(temp_dir, pdf_filename)
|
||||
print(pdf_path)
|
||||
|
||||
return pdf_path
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue