From: Christian Heller Date: Wed, 20 Sep 2023 20:40:16 +0000 (+0200) Subject: To DIY book maker, add option to append second PDF. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/condition?a=commitdiff_plain;h=eca8ea185df520645a48d200bd33dd0d42db45b0;p=misc To DIY book maker, add option to append second PDF. --- diff --git a/bookmaker.py b/bookmaker.py index 9e66775..342050e 100755 --- a/bookmaker.py +++ b/bookmaker.py @@ -13,6 +13,7 @@ parser.add_argument("-c", "--crop", dest="crop_range", help="crops left, bottom, parser.add_argument("-n", "--nup4", dest="nup4", action='store_true', help="puts 4 input pages onto 1 output page") parser.add_argument("-a", "--analyze", dest="analyze", action="store_true", help="print lines identifying spine, page borders") parser.add_argument("-t", "--symmetry", dest="symmetry", action="store_true", help="alternate horizontal crops between odd and even pages") +parser.add_argument("-s", "--second", dest="second", help="append second file as input to append") args = parser.parse_args() with open(args.input_file, 'rb') as file: @@ -33,9 +34,18 @@ with open(args.input_file, 'rb') as file: pages_to_add += [page] print("read in page number", page_num+1) + # add pages of second PDF + if args.second: + file2 = open(args.second, 'rb') + reader2 = pypdf.PdfReader(file2) + page_num = 1 + for page in reader2.pages: + pages_to_add += [page] + print("read second PDF's page number", page_num) + page_num += 1 + # normalize all pages to A4 - for page_num in range(start_page, end_page): - page = reader.pages[page_num] + for page in pages_to_add: page.mediabox.left = 0 page.mediabox.bottom = 0 page.mediabox.top = a4_height @@ -215,3 +225,5 @@ with open(args.input_file, 'rb') as file: with open(args.output_file, 'wb') as output_file: writer.write(output_file) + if args.second: + file2.close()