diff --git a/foliator.py b/foliator.py index 9c09a75..da269db 100755 --- a/foliator.py +++ b/foliator.py @@ -88,11 +88,23 @@ def foliate_A6(input_pdf, strat_func, max_folio_size, append_to=PdfWriter()): folio_page_size = 0 current_page = 0 + + print("Folio sizes, in order") + old_l = L[0] + old_l_run = 0 for l in L: + if l != old_l: + print(old_l, "a5 sheet(s), x", old_l_run) + old_l = l + old_l_run = 1 + else: + old_l_run += 1 + # l is a number of _sheets_, each containing 4 pages folio_page_size = min(doc_length - current_page, 4*l) append_folio_A6(input_pdf, current_page, folio_page_size, append_to) current_page += folio_page_size + print(old_l, "a5 sheet(s), x", old_l_run) return writer @@ -138,9 +150,15 @@ parser.add_argument("-a5", help="output as a5, reverse on short edge", action="store_true") parser.add_argument("-fs", help="maximum folio size, in sheets", action="store", default=-1, type=int) +parser.add_argument("--strategy", help="greedy packing of pages into folios", + action="store", default="balanced") + +stratnames_dict = {"balanced": find_partition_mink, "greedy": find_partition_greedy} + args = parser.parse_args() input_pdf = PdfReader(args.infile) +strategy = stratnames_dict[args.strategy] a5 = foliate_A6(input_pdf, find_partition_greedy, args.fs) if (args.a5): a5.write(args.outfile)