From: Christian Heller Date: Wed, 20 Sep 2023 21:21:43 +0000 (+0200) Subject: To DIY bookmaker add rotation handling. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/static/condition?a=commitdiff_plain;h=62bedf672e025c1e8cca6dd04ce75bcbe25fbe26;p=misc To DIY bookmaker add rotation handling. --- diff --git a/bookmaker.py b/bookmaker.py index 342050e..e6c8d2a 100755 --- a/bookmaker.py +++ b/bookmaker.py @@ -14,6 +14,7 @@ parser.add_argument("-n", "--nup4", dest="nup4", action='store_true', help="puts 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") parser.add_argument("-s", "--second", dest="second", help="append second file as input to append") +parser.add_argument("-r", "--rotate", dest="rotate", help="rotate page of number by 90°") args = parser.parse_args() with open(args.input_file, 'rb') as file: @@ -44,8 +45,17 @@ with open(args.input_file, 'rb') as file: print("read second PDF's page number", page_num) page_num += 1 - # normalize all pages to A4 + # rotate page canvas + if args.rotate: + page = pages_to_add[int(args.rotate) - 1] + page.add_transformation(pypdf.Transformation().translate(tx=-a4_width/2, ty=-a4_height/2)) + page.add_transformation(pypdf.Transformation().rotate(-90)) + page.add_transformation(pypdf.Transformation().translate(tx=a4_width/2, ty=a4_height/2)) + + # normalize all pages to portrait A4 for page in pages_to_add: + if "/Rotate" in page: + page.rotate(360 - page["/Rotate"]) page.mediabox.left = 0 page.mediabox.bottom = 0 page.mediabox.top = a4_height