diff options
Diffstat (limited to 'a6_book.py')
-rwxr-xr-x | a6_book.py | 32 |
1 files changed, 28 insertions, 4 deletions
@@ -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() @@ -20,6 +31,12 @@ def get_parser(): 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 '<start>-<end>' 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 |