Skip to content

Instantly share code, notes, and snippets.

@b-Tomas
Created August 17, 2025 22:09
Show Gist options
  • Save b-Tomas/9b2bca29781d44680f0119e27465c95c to your computer and use it in GitHub Desktop.
Save b-Tomas/9b2bca29781d44680f0119e27465c95c to your computer and use it in GitHub Desktop.
PPTX to PDF
import os
import subprocess
import sys
"""
This script converts all .pptx files in a specified folder to .pdf format
using LibreOffice.
Functions:
convert_pptx_to_pdf(input_folder):
Iterates through all .pptx files in the given folder and converts them
to .pdf format using LibreOffice in headless mode.
Usage:
Run the script directly to convert .pptx files in the specified
`input_folder` to .pdf files.
Ensure that LibreOffice is installed and accessible via the `soffice`
command.
Arguments:
input_folder (str): The path to the folder containing .pptx files to be
converted.
Dependencies:
- os: For file and directory operations.
- subprocess: To execute the LibreOffice command-line tool.
- libreoffice: Must be installed on the system to perform the conversion.
Note:
- LibreOffice must be installed and added to the system's PATH for this
script to work.
- The script uses the `--headless` mode of LibreOffice to perform the
conversion without a GUI.
"""
def convert_pptx_to_pdf(input_folder):
# Iterate through all .pptx files in the folder
for filename in os.listdir(input_folder):
if filename.endswith(".pptx"):
pptx_path = os.path.join(input_folder, filename)
# Use LibreOffice to convert .pptx to .pdf
subprocess.run(
[
"soffice",
"--headless",
"--convert-to",
"pdf",
"--outdir",
input_folder,
pptx_path,
],
check=True,
)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python convert_pptx_to_pdf.py <input_folder>")
sys.exit(1)
input_folder = sys.argv[1]
convert_pptx_to_pdf(input_folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment