Skip to content

Instantly share code, notes, and snippets.

@imesut
Created May 22, 2020 00:31
Show Gist options
  • Save imesut/add4c438e77429fef3cc94676e31a954 to your computer and use it in GitHub Desktop.
Save imesut/add4c438e77429fef3cc94676e31a954 to your computer and use it in GitHub Desktop.
Generate PDFs with custom field from pptx → odp
import zipfile, os
codes = ["insert", "codes", "here"]
prevcode = "XXXXXXX"
count = 1
for code in codes:
with open("template/content.xml", "r") as codefileR:
newcontent = codefileR.read().replace(prevcode, code)
with open("template/content.xml", "w") as codefileW:
codefileW.write(newcontent)
generatedfile = zipfile.ZipFile(str(count) + '.odp', 'w')
for root, dirs, files in os.walk("template/"):
for file in files:
generatedfile.write(os.path.join(root, file),os.path.join(root, file).replace("template/",""))
generatedfile.close()
count += 1
prevcode = code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment