summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpage_manipulation/a5_book.py38
-rwxr-xr-xpage_manipulation/a6_book.py44
2 files changed, 56 insertions, 26 deletions
diff --git a/page_manipulation/a5_book.py b/page_manipulation/a5_book.py
index 846ca86..1e004e0 100755
--- a/page_manipulation/a5_book.py
+++ b/page_manipulation/a5_book.py
@@ -4,6 +4,11 @@ import argparse
import os.path
import subprocess
+try:
+ import pypdf
+except ImportError:
+ pypdf = None
+
SIGNATURE = (
15, 0,
@@ -20,12 +25,12 @@ SIGNATURE = (
def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
- "--file", '-f',
- help="Name of the PDF file",
+ "--pagespec",
+ help="Page selection. At the moment only '<start>-<end>' is supported"
)
parser.add_argument(
- "pagespec",
- help="Page selection. At the moment only '<start>-<end>' is supported"
+ "file",
+ help="Name of the PDF file",
)
return parser
@@ -33,14 +38,23 @@ def get_parser():
def main():
parser = get_parser()
args = parser.parse_args()
- pspec = args.pagespec.split('-')
- try:
- start = int(pspec[0])
- end = int(pspec[1])
- except ValueError:
- parser.print_usage()
- except IndexError:
- parser.print_usage()
+
+ if not args.pagespec:
+ if not pypdf:
+ print("Detecting the number of pages in the pdf requires pypdf")
+ sys.exit(1)
+ reader = pypdf.PdfReader(args.file)
+ start = 1
+ end = end = len(reader.pages)
+ else:
+ pspec = args.pagespec.split('-')
+ try:
+ start = int(pspec[0])
+ end = int(pspec[1])
+ except ValueError:
+ parser.print_usage()
+ except IndexError:
+ parser.print_usage()
pages = [str(i) for i in range(start, end+1)]
if len(pages) % 16 != 0:
diff --git a/page_manipulation/a6_book.py b/page_manipulation/a6_book.py
index 550cb5d..cbb9d44 100755
--- a/page_manipulation/a6_book.py
+++ b/page_manipulation/a6_book.py
@@ -4,6 +4,11 @@ import argparse
import os.path
import subprocess
+try:
+ import pypdf
+except ImportError:
+ pypdf = None
+
SIGNATURE = (
15, 0, 13, 2,
@@ -38,10 +43,6 @@ SIGNATURE_64 = (
def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
- "--file", '-f',
- help="Name of the PDF file",
- )
- parser.add_argument(
"--double", "-d",
action="store_true",
help="Put two signatures on 4 A4 sheet. Pages will be a "
@@ -54,8 +55,13 @@ def get_parser():
"multiple of 64",
)
parser.add_argument(
- "pagespec",
- help="Page selection. At the moment only '<start>-<end>' is supported"
+ "--pagespec",
+ help="Page selection. At the moment only '<start>-<end>' is supported",
+ default=None,
+ )
+ parser.add_argument(
+ "file",
+ help="Name of the PDF file",
)
return parser
@@ -63,14 +69,24 @@ def get_parser():
def main():
parser = get_parser()
args = parser.parse_args()
- pspec = args.pagespec.split('-')
- try:
- start = int(pspec[0])
- end = int(pspec[1])
- except ValueError:
- parser.print_usage()
- except IndexError:
- parser.print_usage()
+
+
+ if not args.pagespec:
+ if not pypdf:
+ print("Detecting the number of pages in the pdf requires pypdf")
+ sys.exit(1)
+ reader = pypdf.PdfReader(args.file)
+ start = 1
+ end = end = len(reader.pages)
+ else:
+ pspec = args.pagespec.split('-')
+ try:
+ start = int(pspec[0])
+ end = int(pspec[1])
+ except ValueError:
+ parser.print_usage()
+ except IndexError:
+ parser.print_usage()
if args.double:
signature = SIGNATURE_32