If you are facing below issue while converting pdf to ppt in python
Traceback (most recent call last):
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
com_error: (-2147417848, 'The object invoked has disconnected from its clients.', None, None)
There is below fix for this issue.
Earlier code was calling convert method and passing files to method
convert(files,pathout)
def convert(files, outputdir,formatType = 32):
powerpoint = win32com.client.Dispatch("Powerpoint.Application")
powerpoint.Visible = 1
for filename in files:
# convert(filename,pathout)
print(filename)
print(outputdir)
newname = os.path.splitext(filename)[0] + ".pdf"
newname = os.path.split(newname)[1]
print(newname)
newname = os.path.join(outputdir,newname)
deck = powerpoint.Presentations.Open(filename)
deck.SaveAs(newname, formatType)
deck.Close()
powerpoint.Quit()
For fix what needs to be done is call convert method with one file i.e. have outer for loop which will iterate files and pass one file to convert method like below.
for filename in files:
convert(filename,pathout)
def convert(filename, outputdir,formatType = 32):
powerpoint = win32com.client.Dispatch("Powerpoint.Application")
powerpoint.Visible = 1
#for filename in files:
# convert(filename,pathout)
print(filename)
print(outputdir)
newname = os.path.splitext(filename)[0] + ".pdf"
newname = os.path.split(newname)[1]
print(newname)
newname = os.path.join(outputdir,newname)
deck = powerpoint.Presentations.Open(filename)
deck.SaveAs(newname, formatType)
deck.Close()
powerpoint.Quit()
For me issue was resolved with this change.
Traceback (most recent call last):
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
com_error: (-2147417848, 'The object invoked has disconnected from its clients.', None, None)
There is below fix for this issue.
Earlier code was calling convert method and passing files to method
convert(files,pathout)
def convert(files, outputdir,formatType = 32):
powerpoint = win32com.client.Dispatch("Powerpoint.Application")
powerpoint.Visible = 1
for filename in files:
# convert(filename,pathout)
print(filename)
print(outputdir)
newname = os.path.splitext(filename)[0] + ".pdf"
newname = os.path.split(newname)[1]
print(newname)
newname = os.path.join(outputdir,newname)
deck = powerpoint.Presentations.Open(filename)
deck.SaveAs(newname, formatType)
deck.Close()
powerpoint.Quit()
For fix what needs to be done is call convert method with one file i.e. have outer for loop which will iterate files and pass one file to convert method like below.
for filename in files:
convert(filename,pathout)
def convert(filename, outputdir,formatType = 32):
powerpoint = win32com.client.Dispatch("Powerpoint.Application")
powerpoint.Visible = 1
#for filename in files:
# convert(filename,pathout)
print(filename)
print(outputdir)
newname = os.path.splitext(filename)[0] + ".pdf"
newname = os.path.split(newname)[1]
print(newname)
newname = os.path.join(outputdir,newname)
deck = powerpoint.Presentations.Open(filename)
deck.SaveAs(newname, formatType)
deck.Close()
powerpoint.Quit()
For me issue was resolved with this change.
After reading this blog i very strong in this topics and this blog really helpful to all Big data hadoop online training India
ReplyDelete