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:
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