If you need to deal with a large number of PPT to PDF conversion work, one by one to open and save as PDF is a very time-consuming practice. We can utilize the powerful tools of Python programming language to automate this process, making batch conversion easy and efficient. In this article, we will introduce how to use Python to convert PowerPoint presentations (PPT, PPTX, etc.) to PDF files, so that the content of the presentation can be displayed on more devices, and to maintain a consistent content display. At the same time to share with you a free online conversion tool to convert various format files to PDF files.
The methods used in this article require the use of for Python, which can be downloaded from the official website or installed via PyPI:
pip install
Batch convert PowerPoint presentations to PDF files
After loading the PPT file, call the (fileName: str, fileFormat: FileFormat) method to convert the PPT to PDF document. The following are the detailed steps to perform this operation:
- Create an object of the Presentation class.
- Use the () method to load the presentation file.
- Use the (fileName: str, fileFormat: FileFormat) method to save the presentation as a PDF document.
Python code example:
from import * from import * # Set folder path and output folder path folder_path = "Documents/" output_folder = "Output/" # Iterate over files in a folder for file_name in (folder_path): file_path = (folder_path, file_name) # Determine if the file name ends in .pptx or .ppt if file_name.lower().endswith('.pptx') or file_name.lower().endswith('.ppt'): # Generate output paths based on filenames output_path = (output_folder, (file_name)[0] + '.pdf') # Create Presentation objects and load presentations from files presentation = Presentation() (file_path) # Save the presentation as a PDF to the specified output folder (output_folder, ) # Release the resources occupied by the Presentation object ()
Convert PPT to PDF file and set page size
During the conversion process, you can also use properties to set the slide size, which determines the page size of the resulting PDF document. The following are the detailed steps for this operation:
- Create an object of the Presentation class.
- Use the () method to load the presentation file.
- Use the properties to set the slide size to A4.
- Use the (file: str, fileFormat: FileFormat) method to save the presentation as a PDF document.
Python code example:
from import * from import * # Import the required modules # Create an object of the Presentation class presentation = Presentation() # Load presentation from file ("") # Change slide size to A4 = SlideSizeType.A4 # Convert presentation to PDF and save it ("output/", ) ()
Convert a slide to PDF
We can also be a single slide in the PPT file is converted to PDF documents. Specific steps are as follows:
- Create an object of the Presentation class.
- Use the () method to load the presentation file.
- Use the [] property to get the slide.
- Use the (file: str, fileFormat: FileFormat) method to save the slide show as a PDF document.
Python code example:
from import * from import * # Import the required modules # Create an object of the Presentation class presentation = Presentation() # Load presentation from file ("") # Get a slide slide = [1] # Save slides as PDF files ("output/", ) ()
Free Online Conversion Tools
Free for .NETIt is a free online conversion tool that supports converting various formats to PDF files, including presentations (PPT, PPTX, etc.). Just select and upload files, wait for the upload to complete and click "Download".
summarize
This article introduces the use of Python to convert PowerPoint presentations (PPT, PPTX and other format files) to PDF files, how to set the page size when converting, and how to convert single-page slides to PDF files. Meanwhile, this article also provides a free online conversion tool that supports converting various files to PDF files and downloading them for saving.
This article on the realization of this Python PPT/PPTX batch conversion to PDF article is introduced to this, more related Python PPT to PDF content, please search for my previous articles or continue to browse the following articles I hope you will support me more in the future!