Johny5
Johny5

Reputation: 11

Why does saving a pptx to pdf result in an empty page?

powerpoint = win32com.client.Dispatch('PowerPoint.Application')
powerpoint.Visible = True
pdf = powerpoint.Presentation.Open("test2.pptx")
pdf.SaveAs("test2", FileFormat = 32)
pdf.Close()
powerpoint.Quit()

I'm trying to use this code, to convert a pptx to PDF. The "test2.pptx" is in the same folder and it's not an empty presentation. I think something wrong with the .Open line because when I run the code it opens an empty presentation.

Upvotes: 0

Views: 273

Answers (1)

Johny5
Johny5

Reputation: 11

I've managed to solve the problem, here is the working code for it:

import win32com.client
import os

x = os.path.realpath("test2.pptx")
y = os.getcwd() + "\\test02.pdf"

powerpoint = win32com.client.gencache.EnsureDispatch('PowerPoint.Application')
powerpoint.Visible = True
pdf = powerpoint.Presentations.Open(x)
pdf.SaveAs(y, FileFormat = 32)
pdf.Close()
powerpoint.Quit()

Upvotes: 1

Related Questions