From 6ab7b2a87311169b7841b04e4f0356de04774ef9 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Thu, 25 May 2023 20:53:17 +0200 Subject: Print two signatures on 4 A4 pages --- a6_book.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'a6_book.py') diff --git a/a6_book.py b/a6_book.py index 189018f..2a641ba 100755 --- a/a6_book.py +++ b/a6_book.py @@ -12,6 +12,17 @@ SIGNATURE = ( 5, 10, 7, 8, ) +SIGNATURE_32 = ( + 15, 0, 31, 16, + 1, 14, 17, 30, + 13, 2, 29, 18, + 3, 12, 19, 28, + 11, 3, 27, 20, + 5, 10, 21, 26, + 9, 6, 25, 22, + 7, 8, 23, 24, +) + def get_parser(): parser = argparse.ArgumentParser() @@ -19,6 +30,12 @@ def get_parser(): "--file", '-f', help="Name of the PDF file", ) + parser.add_argument( + "--double", "-d", + action="store_true", + help="Put two signatures on 4 A4 sheet. Pages should be a " + "multiple of 32", + ) parser.add_argument( "pagespec", help="Page selection. At the moment only '-' is supported" @@ -38,16 +55,23 @@ def main(): except IndexError: parser.print_usage() + if args.double: + signature = SIGNATURE_32 + else: + signature = SIGNATURE + sig_len = len(signature) + pages = [str(i) for i in range(start, end+1)] - if len(pages) % 16 != 0: - empty = 16 - len(pages) % 16 + if len(pages) % sig_len != 0: + empty = sig_len - len(pages) % sig_len pages = pages + ["{}"] * empty rearranged = [] + while pages: - for i in SIGNATURE: + for i in signature: rearranged.append(pages[i]) - pages = pages[16:] + pages = pages[sig_len:] base, ext = os.path.splitext(args.file) out_fname = base + '-book' + ext -- cgit v1.2.3