From 86f77fa1f8d7b33e932a48fcc11361d5d0623401 Mon Sep 17 00:00:00 2001 From: yaw Date: Sun, 26 Oct 2025 22:53:00 +0100 Subject: [PATCH] pdf2zine.py: put arg parsing in function --- pdf2zine.py | 69 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/pdf2zine.py b/pdf2zine.py index b0a7ea3..8ecb929 100755 --- a/pdf2zine.py +++ b/pdf2zine.py @@ -2,26 +2,44 @@ from pypdf import PaperSize, PdfReader, PdfWriter, Transformation from pypdf.generic import RectangleObject - - import argparse -parser = argparse.ArgumentParser( - prog='pdf2zine', - description='pdf2zine rearranges pages for signature printing ', - epilog='onipa') -parser.add_argument('pdf_file') # positional argument -#parser.add_argument('pages', type=int) # positional argument -#parser.add_argument('-s', '--signature') # option that takes a value -parser.add_argument('-v', '--verbose', action='store_true') # on/off flag -parser.add_argument('-z', '--zine', action='store_true', help='Input pdf needs to be 16 pages') -parser.add_argument('-s', '--signature', - dest='signature', - type=int, - action='store', - default=0, - help='') -args = parser.parse_args() +# TODO +# - default: +# - - folio portrait +# - folio fold landscape +# - folio cut landscape +# - octavo portrait (zine) +# - landscape 0 +# - done: + + +def get_arguments(): + parser = argparse.ArgumentParser( + prog='pdf2zine', + description='pdf2zine rearranges pages for signature printing ', + epilog='onipa') + + parser.add_argument('pdf_file') # positional argument + #parser.add_argument('pages', type=int) # positional argument + #parser.add_argument('-s', '--signature') # option that takes a value + parser.add_argument('-v', '--verbose', action='store_true') # on/off flag + parser.add_argument('-z', '--zine', action='store_true', help='Input pdf needs to be 16 pages') + parser.add_argument('-s', '--signature', + dest='signature', + type=int, + action='store', + default=0, + help='') + parser.add_argument('-l', '--landscape', + dest='landscape', + type=int, + action='store', + default=0, + help='') + args = parser.parse_args() + return args +args = get_arguments() signature_size=args.signature if signature_size < 0 : @@ -40,9 +58,22 @@ pages=number_of_pages lst=[] def get_reorder(number_of_pages: int, signature_size: int): + # TODO: + # - if landspace + # panu = 64 + # sisi = 0 + # 1, 3, 2, 4 + # 1, 5, 2, 6, 3, 7, 4, 8 + # 1, 7, 2, 8, 3, 9, 4,10, 5,11, 6, 12 + # simple cut and combine + # 1. i+1 + # 2. N/2+1 + # 3. i + 2 + # 4. N/2+2 panu=number_of_pages sisi=signature_size + #p\s| 1 | 2 | 3 | 4 | #----------------------- # 1 | 4 | 8 | 12 | 16 | @@ -198,6 +229,8 @@ def make_zine(reader, lst): # height=PaperSize.A4.width # ) return writer + + lst=get_reorder(number_of_pages, signature_size) if args.zine :