""" * Version: 0.1.0.0.0 * Purposes: * Convert PPTX to PDF on windows. * System parameters: * sys_parameter 1: name_to_ppt """ import os import sys from win32com.client import gencache def get_file_path(): arg=sys.argv[1] ppt_path = os.path.abspath((str.strip(' .\stage\ ') + str(arg)) + '.pptx') file_path = os.path.split(os.path.abspath(ppt_path))[0] print(file_path) print(ppt_path) return file_path, ppt_path def ppt2pdf(filename, results): name = os.path.basename(filename).split('.')[0] + '.pdf' outfile = os.path.join(results, name) # if os.path.isfile(exportfile): # print(name, "Already exists") # return p2f = gencache.EnsureDispatch("PowerPoint.Application") try: ppt = p2f.Presentations.Open(filename, False, False, False) except Exception as e: print(os.path.split(filename)[1], "error:%s" % e) ppt.ExportAsFixedFormat(outfile, 2, PrintRange=None) print('Save PDF file') p2f.Quit() def main(): file_path, ppt_pat = get_file_path() results = os.path.join(file_path) if not os.path.exists(results): os.mkdir(os.path.join(results)) ppt2pdf(ppt_pat, results) if __name__ == "__main__": main()