From: Christian Heller Date: Sun, 24 Sep 2023 16:47:35 +0000 (+0200) Subject: Bookmaker: Reduce reportlab dependency to --nup4 usage. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/templates?a=commitdiff_plain;h=f26aba1e5e9f396ad942988f3f60d27eac524e76;p=misc Bookmaker: Reduce reportlab dependency to --nup4 usage. --- diff --git a/bookmaker.py b/bookmaker.py index bf9eba8..e3e9188 100755 --- a/bookmaker.py +++ b/bookmaker.py @@ -13,14 +13,12 @@ try: import pypdf except ImportError: fail_with_msg("Can't run without pypdf installed.") -try: - from reportlab.lib.pagesizes import A4 -except ImportError: - fail_with_msg("Can't run without reportlab installed.") # some constants -A4_WIDTH, A4_HEIGHT = A4 POINTS_PER_CM = 10 * 72 / 25.4 +A4_WIDTH = 21 * POINTS_PER_CM +A4_HEIGHT = 29.7 * POINTS_PER_CM +A4 = (A4_WIDTH, A4_HEIGHT) CUT_DEPTH = 1.95 * POINTS_PER_CM CUT_WIDTH = 1.05 * POINTS_PER_CM MIDDLE_POINT_DEPTH = 0.4 * POINTS_PER_CM @@ -195,6 +193,11 @@ def parse_args(): def main(): args = parse_args() + if args.nup4: + try: + import reportlab + except ImportError: + raise ImportError("-n: need reportlab library installed for --nup4") # select pages from input files pages_to_add = [] @@ -397,11 +400,10 @@ def main(): print("merged page number %d (of %d)" % (page_count, len(pages_to_add))) i += 1 if i > 3: - from reportlab.pdfgen import canvas if args.analyze: # borders packet = io.BytesIO() - c = canvas.Canvas(packet, pagesize=A4) + c = reportlab.pdfgen.canvas.Canvas(packet, pagesize=A4) c.setLineWidth(0.1) c.line(0, A4_HEIGHT, A4_WIDTH, A4_HEIGHT) c.line(0, half_height, A4_WIDTH, half_height) @@ -420,7 +422,7 @@ def main(): x_right_SPINE_LIMIT = A4_WIDTH - x_left_SPINE_LIMIT if args.analyze or front_page: packet = io.BytesIO() - c = canvas.Canvas(packet, pagesize=A4) + c = reportlab.pdfgen.canvas.Canvas(packet, pagesize=A4) if args.analyze: # # spine lines c.setLineWidth(0.1) @@ -462,5 +464,5 @@ def main(): if __name__ == "__main__": try: main() - except ValueError as e: + except (ImportError, ValueError) as e: fail_with_msg(e)