Programmatically extracting slides as images from a PowerPoint presentation (.PPT)

Viewed 10291

Given a PowerPoint presentation in .ppt format, what is the best way to programmatically and using only open source software extract an image representation (in say .jpg or .png) of each slide in the presentation?

The application will run in a Linux server environment, so installing Microsoft Office or Keynote is not an option.

The functionality that I want to achieve programmatically is similar to:

  • Keynote's export functionality (File > Export... > Pictures > JPEG)
  • PowerPoint's Save As JPEG functionality (Save As > Other Formats > JPEG)
6 Answers

We can convert pptx to pdf and then pdt to JPEG images using imagemagick. Here is what works for me on Ubuntu.

First we need to install several packages:

apt update && apt install libreoffice imagemagick ghostscript

Now, convert pptx file to PDF using the following command:

soffice --headless --convert-to pdf test.pptx

The generated PDF file is named test.pdf. Then we can use imagemagick to convert PDF to jpeg image:

# you can tweak density and quality to change the quality of generated images.
convert -density 150 test.pdf -quality 80 output-%3d.jpg

In case that you encounter errors when running the above command. Edit /etc/ImageMagick-6/policy.xml and change the following line:

<policy domain="coder" rights="none" pattern="PDF" />

to

<policy domain="coder" rights="read|write" pattern="PDF" />

Ref: This answer is based on post here.

Related