Convert PPT to PDF in Python

Convert PPTX PPT to PDF in Python

PDF is a popular and widely used file format having cross-platform support. The layout of PDF documents appears to be the same in heterogeneous environments. Thus, PDF becomes handy when you need to share your documents across multiple platforms. PowerPoint to PDF is among the common document conversions these days. To automate this conversion, we will show you how to convert PPT or PPTX files to PDF format in Python. Moreover, we will demonstrate how to customize the PPTX to PDF conversion using different options.

TIP: You want to try out Aspose FREE PowerPoint to PDF Converter.

Python PPT to PDF Converter Library

To convert the PowerPoint files to PDF format, we will use Aspose.Slides for Python via .NET. It is a powerful library that lets you automate the presentation manipulation operations from within your Python applications. Using the library, you can create, edit and convert the presentations seamlessly. You can install the library from PyPI using the following pip command.

> pip install aspose.slides

Read more about the system requirements to use this library.

Convert a PPT to PDF in Python

The conversion of PPT files to PDF can be performed in a couple of steps. Just load the presentation file and save it as a PDF document. The following are the steps to convert a PPT file to PDF in Python.

  • Load the PPT/PPTX presentation using Presentation class.
  • Convert PPT to PDF using Presentation.save(string, export.SaveFormat.PDF) method.

The following code sample shows how to convert a PowerPoint PPTX to PDF in Python.

The following screenshot shows the input PPTX file that we used in this article.

PowerPoint PPTX Presentation
PPTX Presentation

The following is the screenshot of the converted PDF file.

PPTX to PDF Conversion
PPTX Converted to PDF

You would have noticed that the third slide in the PPTX presentation is marked as hidden. Therefore, it is not included in the converted PDF file. However, in certain cases, you may have to include hidden slides in PPTX to PDF conversion. So let’s see how to achieve that.

Include Hidden Slides – Python PPTX to PDF

To customize the PowerPoint to PDF conversion, Aspose.Slides for Python via .NET provides PdfOptions class. The following are the steps to include hidden slides in PowerPoint to PDF conversion in Python.

  • Load the PPTX presentation using Presentation class.
  • Create an object of PdfOptions class.
  • Set PdfOptions.show_hidden_slides property to True.
  • Convert PPTX to PDF using Presentation.save(string, export.SaveFormat.PDF, PdfOptions) method.

The following Python code sample shows how to include hidden slides in PPTX to PDF conversion.

Convert Selected Slides of PPT to PDF in Python

Often, you may need to convert specific slides only to PDF instead of rendering the whole presentation. To achieve that, you can pass an array of slide numbers to the Presentation.save() method. The following are the steps to convert specific slides in a PPTX to PDF.

  • Load the PPTX presentation using Presentation class.
  • Create an array containing slide numbers, e.g. slides_numbers=[ 1, 3 ].
  • Convert PPTX to PDF using Presentation.save(string, slides_numbers, export.SaveFormat.PDF) method.

The following code sample converts the specific slides of a presentation to PDF in Python.

Set PDF Compliance in PPT to PDF Conversion

You can also specify a particular compliance level for the converted PDF document using the PdfOptions.compliance property. The following are the steps to achieve that.

  • Load the PPTX presentation using Presentation class.
  • Create an object of PdfOptions class.
  • Set PdfOptions.compliance property using export.PdfCompliance enum.
  • Convert PPTX to PDF using Presentation.save(string, export.SaveFormat.PDF, PdfOptions) method.

The following code sample shows how to specify compliance level in PPTX to PDF conversion in Python.

Convert PPT to Password-protected PDF in Python

To ensure the security of the document, PDF supports password protection. Aspose.Slides for Python via .NET also allows you to set a password and specify access permissions for the converted PDF document. The following are the steps to convert a PowerPoint presentation to a password-protected PDF.

  • Load the PPTX presentation using Presentation class.
  • Create an object of PdfOptions class.
  • Set password using PdfOptions.password property.
  • Set access permissions using PdfOptions.access_permissions property.
  • Convert PPTX to PDF using Presentation.save(string, export.SaveFormat.PDF, PdfOptions) method.

The following code sample converts a PowerPoint PPTX file to a password-protected PDF.

Get a Free License

You can use Aspose.Slides for Python via .NET for free by getting a temporary license.

Conclusion

In this article, you have learned how to convert PPT or PPTX files to PDF in Python. Furthermore, you have seen how to customize the PowerPoint to PDF conversion using different options in Python. The code samples have demonstrated how to include hidden slides, convert specific slides, specify PDF compliance, and set a password and access permissions for converted PDF. You can explore more about the Python presentation manipulation library using the documentation. In case you would have any questions, feel free to let us know via our forum.

See Also