Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ppt file to pptx in Python

Is there any way to convert .ppt files to .pptx files.

Objective: I need to extract text from table (with Column Names as Name, address, contact number, email, etc) from .ppt files. For this I followed this approach:

I converted .ppt file to pdf and then extracted the data from pdf using PDFminer. The text extracted from pdf is not separated by any delimiter. Due to this it is very difficult to distinguish names and other fields in the table.

Probable solution I am working on:

  1. Convert .ppt files to .pptx
  2. Parse xml of .pptx file to get the formatted text

I am stuck at first step of converting the file format from .ppt to .pptx. I couldn't find any solution for converting .ppt file format to .pptx formt in python.

like image 908
mayautobot Avatar asked Aug 14 '17 08:08

mayautobot


2 Answers

I have created this code hope this works for you :

    import win32com.client
    PptApp = win32com.client.Dispatch("Powerpoint.Application")
    PptApp.Visible = True
    PPtPresentation = PptApp.Presentations.Open(r'D:\ppt\sample.ppt')
    PPtPresentation.SaveAs(r'D:\ppt\final.pptx', 24)
    PPtPresentation.close()
    PptApp.Quit()
like image 114
piyush kumar Avatar answered Oct 11 '22 08:10

piyush kumar


For MacOS Homebrew users: install Apache Tika (brew install tika)

The command-line interface works like this:

tika --text something.ppt > something.txt

And to use it inside python script:

import os
os.system("tika --text temp.ppt > temp.txt")

You will be able to do it and that is the only solution I have so far.

like image 31
fsfr23 Avatar answered Oct 11 '22 08:10

fsfr23