diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2024-09-02 15:10:26 +0200 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2024-09-02 15:10:26 +0200 |
commit | f9345021f03ee7925a30c56cbb57b68d735ba213 (patch) | |
tree | b0fdc2cb8f851ab0c8fda7a672e8dccf13c360e7 /planner/planner_generator.py | |
parent | 3ee00e87564045defc10400304f3ec2d481770cb (diff) |
Add support for arbitrary sizes
Diffstat (limited to 'planner/planner_generator.py')
-rwxr-xr-x | planner/planner_generator.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/planner/planner_generator.py b/planner/planner_generator.py index 906c0fc..2da3133 100755 --- a/planner/planner_generator.py +++ b/planner/planner_generator.py @@ -6,6 +6,7 @@ import datetime import locale import logging import os +import re import shutil import subprocess import sys @@ -87,6 +88,8 @@ class Generator: return "a5" if "A4" in template: return "a4" + if "×" in template: + return re.findall(r"\d+×\d+", template)[0] return "a6" def _get_cover_name(self, cover_template): @@ -163,14 +166,20 @@ class Generator: def join_pages(self): pdf_pages = self.get_pdf_pages() - try: - subprocess.run([ + command = [ "pdfjam", "--outfile", self.out_file, "--scale", "1", - "--paper", "{}paper".format(self.paper_size), - *pdf_pages - ]) + ] + if "×" in self.paper_size: + x, y = self.paper_size.split("×") + size = "{" + x + "mm," + y + "mm}" + command.extend(["--papersize", size]) + else: + command.extend(["--paper", "{}paper".format(self.paper_size)]) + command.extend(pdf_pages) + try: + subprocess.run(command) except FileNotFoundError: logging.warning("pdfjam is not installed") logging.warning("you will have to join the pdf pages yourself") |