From: Christian Heller Date: Sun, 24 Sep 2023 00:40:23 +0000 (+0200) Subject: Bookmaker: more expressive output. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/add_free?a=commitdiff_plain;h=5206a79c96848191646c6c73d3af82dceb947fe0;p=misc Bookmaker: more expressive output. --- diff --git a/bookmaker.py b/bookmaker.py index 3737edc..d9bf685 100755 --- a/bookmaker.py +++ b/bookmaker.py @@ -51,6 +51,15 @@ for i, input_file in enumerate(args.input_file): pages_to_add += [page] print("-i, -p: read in %s page number %d as new page %d" % (input_file, old_page_num+1, new_page_num)) +# if necessary, pad pages to multiple of 8 +if args.nup4: + mod_to_8 = len(pages_to_add) % 8 + if mod_to_8 > 0: + print("-n: number of input pages %d not multiple of 8, padding to that" % len(pages_to_add)) + for _ in range(8 - mod_to_8): + new_page = pypdf.PageObject.create_blank_page(width=a4_width, height=a4_height) + pages_to_add += [new_page] + # rotate page canvas if args.rotate: for rotate in args.rotate: @@ -83,11 +92,15 @@ if args.crop_range: page_range = None 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(',')] + crop_left_cm, crop_bottom_cm, crop_right_cm, crop_top_cm = [float(x) for x in crops.split(',')] + crop_left = crop_left_cm * points_per_cm + crop_bottom = crop_bottom_cm * points_per_cm + crop_right = crop_right_cm * points_per_cm + crop_top = crop_top_cm * points_per_cm if args.symmetry: - print("-c, -t: to pages %d to %d applying crops: left %dcm, bottom %dcm, right %dcm, top %dcm (but alternating left and right crop between even and odd pages)" % (start_page + 1, end_page, crop_left, crop_bottom, crop_right, crop_top)) + print("-c, -t: to pages %d to %d applying crops: left %.2fcm, bottom %.2fcm, right %.2fcm, top %.2fcm (but alternating left and right crop between even and odd pages)" % (start_page + 1, end_page, crop_left_cm, crop_bottom_cm, crop_right_cm, crop_top_cm)) else: - 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)) + print("-c: to pages %d to %d applying crops: left %.2fcm, bottom %.2fcm, right %.2fcm, top %.2fcm" % (start_page + 1, end_page, crop_left_cm, crop_bottom_cm, crop_right_cm, crop_top_cm)) cropped_width = a4_width - crop_left - crop_right cropped_height = a4_height - crop_bottom - crop_top zoom = 1 @@ -123,9 +136,13 @@ if not args.nup4: page.mediabox.top = cropped_height * zoom writer.add_page(page) odd_page = not odd_page + print("built page number %d (of %d)" % (i+1, len(pages_to_add))) else: print("-n: building 4-input-pages-per-output-page book") + print("-m: applying printable-area margin of %.2fcm" % args.margin) + if args.analyze: + print("-a: drawing page borders, spine limits") n_pages_per_axis = 2 printable_margin = args.margin * points_per_cm printable_scale = (a4_width - 2*printable_margin)/a4_width @@ -137,11 +154,6 @@ else: new_page_order = [] new_i_order = [] eight_pack = [] - mod_to_8 = len(pages_to_add) % 8 - if mod_to_8 > 0: - for _ in range(8 - mod_to_8): - new_page = pypdf.PageObject.create_blank_page(width=a4_width, height=a4_height) - pages_to_add += [new_page] i = 0 n_eights = 0 for page in pages_to_add: @@ -211,7 +223,7 @@ else: page.add_transformation(pypdf.Transformation().scale(section_scale_factor, section_scale_factor)) new_page.merge_page(page) page_count += 1 - print("merged page number", page_count) + print("merged page number %d (of %d)" % (page_count, len(pages_to_add))) i += 1 if i > 3: from reportlab.pdfgen import canvas