home · contact · privacy
To DIY book maker, add option to append second PDF.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 20 Sep 2023 20:40:16 +0000 (22:40 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 20 Sep 2023 20:40:16 +0000 (22:40 +0200)
bookmaker.py

index 9e66775f4ae9aaefa9a5d3b2783f865fc51faeff..342050ecfcd34cda778a227712cba6dec3292907 100755 (executable)
@@ -13,6 +13,7 @@ parser.add_argument("-c", "--crop", dest="crop_range", help="crops left, bottom,
 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")
+parser.add_argument("-s", "--second", dest="second", help="append second file as input to append")
 args = parser.parse_args()
 
 with open(args.input_file, 'rb') as file:
@@ -33,9 +34,18 @@ with open(args.input_file, 'rb') as file:
         pages_to_add += [page]
         print("read in page number", page_num+1)
 
+    # add pages of second PDF
+    if args.second:
+        file2 = open(args.second, 'rb')
+        reader2 = pypdf.PdfReader(file2)
+        page_num = 1
+        for page in reader2.pages:
+            pages_to_add += [page]
+            print("read second PDF's page number", page_num)
+            page_num += 1
+
     # normalize all pages to A4
-    for page_num in range(start_page, end_page):
-        page = reader.pages[page_num]
+    for page in pages_to_add:
         page.mediabox.left = 0
         page.mediabox.bottom = 0
         page.mediabox.top = a4_height 
@@ -215,3 +225,5 @@ with open(args.input_file, 'rb') as file:
 
     with open(args.output_file, 'wb') as output_file:
         writer.write(output_file)
+    if args.second:
+        file2.close()