tanos-japanese-word-books/python/createWrapperDoc.py

26 lines
661 B
Python
Raw Normal View History

2022-02-09 01:19:57 +01:00
from sys import argv
from PyPDF2 import PdfFileReader
def inject_into_template(
output_file,
string,
template='tex/doc.tex.template',
replacement_char='###'
):
with open(template) as file:
content = file.read().replace(replacement_char, string)
with open(output_file, 'w') as file:
file.write(content)
if __name__ == "__main__":
pdfPath, outputPath = argv[1:3]
pdf = PdfFileReader(open(f'build/{pdfPath}','rb'))
pageNum = pdf.getNumPages()
inject_into_template(
f'build/{outputPath}',
f'\\includepdf[pages=-,nup=1x2,signature={pageNum},landscape,booklet=true]{{{pdfPath}}}',
template="tex/wrapper.tex.template"
)