Can create last incomplete book

This commit is contained in:
itec78 2021-09-06 22:06:51 +02:00
parent 04fc7fe1b6
commit 9cf0b8e0de

View file

@ -100,7 +100,13 @@ def indice(text):
doc.build(parts)
pdfReader = PdfFileReader(packet)
return([pdfReader.getPage(0),pdfReader.getPage(1)])
pdfWriter = PdfFileWriter()
for page in pdfReader.pages:
pdfWriter.addPage(page)
pdfWriter.addBlankPage()
return([pdfWriter.getPage(0),pdfWriter.getPage(1)])
@ -250,12 +256,13 @@ def main():
print("Genero i libretti")
os.makedirs('books', exist_ok=True)
for book_num in range(1, int(len(vgo_dict) / 50) + 1):
for pagstart in range(1, len(vgo_dict), 50):
pdfWriter = PyPDF2.PdfFileWriter()
print(book_num)
pagstart = (book_num - 1) * 50 + 1
pagend = book_num * 50
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)))
@ -276,7 +283,8 @@ def main():
except:
pass
pdfWriter.addBlankPage()
for i in range(0, 8 - ((((pagend - 1) % 50) + 1 + 5) % 8)):
pdfWriter.addBlankPage()
# aggiungere indice
for indpag in indice(indtext):
@ -289,7 +297,7 @@ def main():
pageObj = pdfReader.getPage(0)
pdfWriter.addPage(pageObj)
book_name = os.path.join('books', 'book' + str(book_num).zfill(2) + '.pdf')
book_name = os.path.join('books', 'vgo_' + str(book_num).zfill(2) + '.pdf')
with open(book_name, 'wb') as pdfOutput:
pdfWriter.write(pdfOutput)