Skip to main content

Convert PowerPoint files to PDF

Project description

PowerPoint to PDF Converter

This is a Python script that converts PowerPoint files (.ppt, .pptx) to PDF format. It uses the comtypes library to interact with Microsoft PowerPoint.

Prerequisites

  • Python 3.6 or above

Dependancies

  • comtypes library

Usage

Run the script with the following arguments i.e pptxtopdf --input_dir "C:\Users\Example\Downloads\input":

  • --input_file: Path to the folder containing the PowerPoint files to convert.
  • --input_dir: Path to the folder containing the PowerPoint files to convert.
  • --output_dir: [Optional] Path to the folder where the converted PDF files will be saved. If not provided, it defaults to the same directory as the input file or directory.

Example from command line

pptxtopdf --input_dir ./input --output_dir ./output

This command will convert all the PowerPoint files in the ./input folder and save the converted PDF files in the ./output folder.

Example in script

from pptxtopdf import convert

input_dir = r"C:\Users\Example\ExampleDirectory"
output_dir = r"C:\Users\Example\ExampleDirectory"

convert(input_dir, output_dir)

Functionality

The script performs the following steps:

  1. Validates the input folder path and checks if it exists.
  2. Creates the output folder if it does not already exist.
  3. Lists all the files in the input folder.
  4. Iterates over each file and checks if it has a PowerPoint extension.
  5. Creates a PowerPoint application object using comtypes.
  6. Opens the PowerPoint slides.
  7. Retrieves the base file name.
  8. Constructs the output file path with the PDF extension.
  9. Checks if the output file already exists and skips the conversion if it does.
  10. Saves the slides as a PDF file.
  11. Closes the slide deck.
  12. Quits PowerPoint.
  13. Keeps track of the successful conversions and errors.
  14. Prints a summary of the conversion process at the end.

Note: The script runs without a user interface (WithWindow=False) to perform the conversions silently.

Error Handling

If any error occurs during the conversion process, the script will catch the exception and print an error message specifying the file that caused the error.

License

This script is released under the MIT License. Feel free to modify and use it according to your needs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pptxtopdf-0.0.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pptxtopdf-0.0.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file pptxtopdf-0.0.2.tar.gz.

File metadata

  • Download URL: pptxtopdf-0.0.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pptxtopdf-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6463703de7a3ee221879819ea829d9bf11812188debdad9a80eccc4c6273f2f6
MD5 7de5e708909dfcc878bd2881c1116ac2
BLAKE2b-256 904699f4ad0ba9d69b5e700676344d62ded49ff16cead01edca9e6860911981c

See more details on using hashes here.

File details

Details for the file pptxtopdf-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pptxtopdf-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pptxtopdf-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d0cb06785d018891126e4070a563bf0eea0993235019b003700f26b9cde047bf
MD5 f004660ebc96c757e1b151f0bcd4e31a
BLAKE2b-256 b1539a321e51f9d1acb0932b416092b908e0c5702292e0c9eac44e0fb1084b60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page