From: Christian Heller Date: Sat, 23 Sep 2023 23:53:20 +0000 (+0200) Subject: In Bookmaker, document code and its execution better. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/%7B%7Bdb.prefix%7D%7D/processes?a=commitdiff_plain;h=0699581e262021aa52cd01617c45e11a7246219f;p=misc In Bookmaker, document code and its execution better. --- diff --git a/bookmaker.py b/bookmaker.py index 2211b84..64acf6f 100755 --- a/bookmaker.py +++ b/bookmaker.py @@ -44,10 +44,12 @@ for i, input_file in enumerate(args.input_file): if args.page_range and len(args.page_range) > i: range_string = args.page_range[i] start_page, end_page = parse_page_range(range_string, reader.pages) - for page_num in range(start_page, end_page): - page = reader.pages[page_num] + new_page_num = 0 + for old_page_num in range(start_page, end_page): + new_page_num += 1 + page = reader.pages[new_page_num] pages_to_add += [page] - print("read in %s page number %d" % (input_file, page_num+1)) + print("-i, -p: read in %s page number %d as new page %d" % (input_file, new_page_num+1, new_page_num)) # rotate page canvas if args.rotate: @@ -56,6 +58,7 @@ if args.rotate: page.add_transformation(pypdf.Transformation().translate(tx=-a4_width/2, ty=-a4_height/2)) page.add_transformation(pypdf.Transformation().rotate(-90)) page.add_transformation(pypdf.Transformation().translate(tx=a4_width/2, ty=a4_height/2)) + print("-r: rotating (by 90°) page", rotate) # normalize all pages to portrait A4 for page in pages_to_add: @@ -81,6 +84,7 @@ if args.crop_range: crops = initial_split[0] start_page, end_page = parse_page_range(page_range, pages_to_add) crop_left, crop_bottom, crop_right, crop_top = [float(x) * points_per_cm for x in crops.split(',')] + print("-c: to pages %d to %d applying crops: left %dcm, bottom %dcm, right %dcm, top %dcm" % (start_page + 1, end_page, crop_left, crop_bottom, crop_right, crop_top)) cropped_width = a4_width - crop_left - crop_right cropped_height = a4_height - crop_bottom - crop_top zoom = 1 @@ -266,8 +270,9 @@ else: writer.add_page(new_page) i = 0 front_page = not front_page + +# write and close for file in opened_files: file.close() - with open(args.output_file, 'wb') as output_file: writer.write(output_file)