MCPcopy Create free account
hub / github.com/OpenDCAI/Paper2Any / convert_pptx_to_pdf

Function convert_pptx_to_pdf

script/run_ppt2polish_cli.py:159–206  ·  view source on GitHub ↗

Convert PPTX to PDF using LibreOffice Returns: Path to the generated PDF file

(pptx_path: Path, output_dir: Path)

Source from the content-addressed store, hash-verified

157
158
159def convert_pptx_to_pdf(pptx_path: Path, output_dir: Path) -> Path:
160 """
161 Convert PPTX to PDF using LibreOffice
162
163 Returns:
164 Path to the generated PDF file
165 """
166 pdf_path = output_dir / "temp_slides.pdf"
167
168 log.info("Converting PPTX to PDF...")
169 log.info("Input: %s", pptx_path)
170 log.info("Output: %s", pdf_path)
171
172 try:
173 # Try using LibreOffice command line
174 cmd = [
175 "libreoffice",
176 "--headless",
177 "--convert-to", "pdf",
178 "--outdir", str(output_dir),
179 str(pptx_path)
180 ]
181
182 result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
183
184 if result.returncode != 0:
185 raise RuntimeError(f"LibreOffice conversion failed: {result.stderr}")
186
187 # LibreOffice creates PDF with same name as input
188 generated_pdf = output_dir / f"{pptx_path.stem}.pdf"
189 if generated_pdf.exists():
190 generated_pdf.rename(pdf_path)
191
192 if not pdf_path.exists():
193 raise FileNotFoundError(f"PDF file not created: {pdf_path}")
194
195 log.info("PDF created: %s", pdf_path)
196 return pdf_path
197
198 except FileNotFoundError:
199 raise RuntimeError(
200 "LibreOffice not found. Please install LibreOffice:\n"
201 " Ubuntu/Debian: sudo apt-get install libreoffice\n"
202 " macOS: brew install --cask libreoffice\n"
203 " Or use: sudo apt-get install unoconv"
204 )
205 except subprocess.TimeoutExpired:
206 raise RuntimeError("PPTX to PDF conversion timed out (>5 minutes)")
207
208
209def convert_pdf_to_images(pdf_path: Path, output_dir: Path) -> list[str]:

Callers 1

mainFunction · 0.85

Calls 1

runMethod · 0.45

Tested by

no test coverage detected