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