pdf2zine.py: put arg parsing in function
This commit is contained in:
parent
e678b71778
commit
86f77fa1f8
69
pdf2zine.py
69
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 |
|
||||
@ -199,6 +230,8 @@ def make_zine(reader, lst):
|
||||
# )
|
||||
return writer
|
||||
|
||||
|
||||
|
||||
lst=get_reorder(number_of_pages, signature_size)
|
||||
if args.zine :
|
||||
if number_of_pages != 16:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user