book generation
This commit is contained in:
parent
851b7ab4f9
commit
e3e6820621
1 changed files with 38 additions and 35 deletions
|
@ -257,51 +257,54 @@ def main():
|
|||
print("Genero i libretti")
|
||||
os.makedirs('books', exist_ok=True)
|
||||
for pagstart in range(1, len(vgo_dict), 50):
|
||||
pdfWriter = PyPDF2.PdfFileWriter()
|
||||
|
||||
book_num = int(pagstart / 50) + 1
|
||||
pagend = min(book_num * 50, len(vgo_dict))
|
||||
|
||||
print(book_num)
|
||||
|
||||
# aggiungere copertina
|
||||
pdfWriter.addPage(copertina(str(pagstart).zfill(3) + " - " + str(pagend).zfill(3)))
|
||||
|
||||
pdfWriter.addBlankPage()
|
||||
book_name = os.path.join('books', 'vgo_' + str(book_num).zfill(2) + '.pdf')
|
||||
if not os.path.isfile(book_name):
|
||||
pdfWriter = PyPDF2.PdfFileWriter()
|
||||
print(book_num)
|
||||
|
||||
indtext = ""
|
||||
for vgo_num in [str(x).zfill(3) for x in range(pagstart, pagend + 1)]:
|
||||
pdf_name = os.path.join('pdf', vgo_num + '.pdf')
|
||||
# aggiungere copertina
|
||||
pdfWriter.addPage(copertina(str(pagstart).zfill(3) + " - " + str(pagend).zfill(3)))
|
||||
|
||||
try:
|
||||
#print(vgo_num + " - " + vgo_dict[vgo_num])
|
||||
indtext = indtext + vgo_num + "\t" + vgo_dict[vgo_num] + "\n"
|
||||
pdfFileObj = open(pdf_name, 'rb')
|
||||
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
|
||||
pageObj = pdfReader.getPage(0)
|
||||
pdfWriter.addPage(pageObj)
|
||||
except:
|
||||
pass
|
||||
|
||||
for i in range(0, 8 - ((((pagend - 1) % 50) + 1 + 5) % 8)):
|
||||
pdfWriter.addBlankPage()
|
||||
|
||||
# aggiungere indice
|
||||
for indpag in indice(indtext):
|
||||
pdfWriter.addPage(indpag)
|
||||
indtext = ""
|
||||
for vgo_num in [str(x).zfill(3) for x in range(pagstart, pagend + 1)]:
|
||||
pdf_name = os.path.join('pdf', vgo_num + '.pdf')
|
||||
|
||||
try:
|
||||
#print(vgo_num + " - " + vgo_dict[vgo_num])
|
||||
indtext = indtext + vgo_num + "\t" + vgo_dict[vgo_num] + "\n"
|
||||
pdfFileObj = open(pdf_name, 'rb')
|
||||
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
|
||||
pageObj = pdfReader.getPage(0)
|
||||
pdfWriter.addPage(pageObj)
|
||||
except:
|
||||
pass
|
||||
|
||||
for i in range(0, 8 - ((((pagend - 1) % 50) + 1 + 5) % 8)):
|
||||
pdfWriter.addBlankPage()
|
||||
|
||||
#Aggiungere pagina finale
|
||||
#pdfWriter.addBlankPage()
|
||||
pdfFileObj = open("quarta.pdf", 'rb')
|
||||
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
|
||||
pageObj = pdfReader.getPage(0)
|
||||
pdfWriter.addPage(pageObj)
|
||||
# aggiungere indice
|
||||
for indpag in indice(indtext):
|
||||
pdfWriter.addPage(indpag)
|
||||
|
||||
book_name = os.path.join('books', 'vgo_' + str(book_num).zfill(2) + '.pdf')
|
||||
with open(book_name, 'wb') as pdfOutput:
|
||||
pdfWriter.write(pdfOutput)
|
||||
#Aggiungere pagina finale
|
||||
#pdfWriter.addBlankPage()
|
||||
pdfFileObj = open("quarta.pdf", 'rb')
|
||||
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
|
||||
pageObj = pdfReader.getPage(0)
|
||||
pdfWriter.addPage(pageObj)
|
||||
|
||||
|
||||
with open(book_name, 'wb') as pdfOutput:
|
||||
pdfWriter.write(pdfOutput)
|
||||
|
||||
# # Genera indice
|
||||
# with open("index.txt", 'w') as handler:
|
||||
# for key in sorted(vgo_dict):
|
||||
# handler.write(key + ' - ' + vgo_dict[key] + '\n')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue