From: Christian Heller Date: Wed, 20 Sep 2023 20:27:53 +0000 (+0200) Subject: Add crop/margin symmetry option to bookmaker script. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/foo.html?a=commitdiff_plain;h=be153cb8c016b195168a1dbb736f601e24fe2989;p=misc Add crop/margin symmetry option to bookmaker script. --- diff --git a/bookmaker.py b/bookmaker.py index dd5b2e7..9e66775 100755 --- a/bookmaker.py +++ b/bookmaker.py @@ -12,6 +12,7 @@ parser.add_argument("-p", "--pages", dest="page_range", help="page range, e.g., parser.add_argument("-c", "--crop", dest="crop_range", help="crops left, bottom, right, top – e.g., '10,10,10,10'") parser.add_argument("-n", "--nup4", dest="nup4", action='store_true', help="puts 4 input pages onto 1 output page") parser.add_argument("-a", "--analyze", dest="analyze", action="store_true", help="print lines identifying spine, page borders") +parser.add_argument("-t", "--symmetry", dest="symmetry", action="store_true", help="alternate horizontal crops between odd and even pages") args = parser.parse_args() with open(args.input_file, 'rb') as file: @@ -61,12 +62,17 @@ with open(args.input_file, 'rb') as file: writer = pypdf.PdfWriter() if not args.nup4: + odd_page = True for page in pages_to_add: - page.add_transformation(pypdf.Transformation().translate(tx=-crop_left, ty=-crop_bottom)) + if args.symmetry and odd_page: + page.add_transformation(pypdf.Transformation().translate(tx=-crop_left, ty=-crop_bottom)) + else: + page.add_transformation(pypdf.Transformation().translate(tx=-crop_right, ty=-crop_bottom)) page.add_transformation(pypdf.Transformation().scale(zoom, zoom)) page.mediabox.right = cropped_width * zoom page.mediabox.top = cropped_height * zoom writer.add_page(page) + odd_page = not odd_page else: n_pages_per_axis = 2 points_per_mm = 2.83465 @@ -111,7 +117,10 @@ with open(args.input_file, 'rb') as file: # in-section transformations: align pages on top, left-hand pages to left, right-hand to right page.add_transformation(pypdf.Transformation().translate(ty=(a4_height / zoom - (a4_height - crop_top)))) if i == 0 or i == 2: - page.add_transformation(pypdf.Transformation().translate(tx=-crop_left)) + if args.symmetry: + page.add_transformation(pypdf.Transformation().translate(tx=-crop_right)) + else: + page.add_transformation(pypdf.Transformation().translate(tx=-crop_left)) elif i == 1 or i == 3: page.add_transformation(pypdf.Transformation().translate(tx=(a4_width / zoom - (a4_width - crop_right)))) page.add_transformation(pypdf.Transformation().scale(zoom * bonus_shrink_factor, zoom * bonus_shrink_factor))