For arguments like -p, page numbers are assumed to start with 1 (not 0, which is treated as an invalid page number value).
+If -p defines a page range beyond the source document's last page, the remaining pages will be created blank.
+
The target page shape so far is assumed to be A4 in portrait orientation; bookmaker.py normalizes all pages to this format before applying crops, and removes any source PDF /Rotate commands (for their production of landscape orientations).
if args_page_range and len(args_page_range) > i:
range_string = args_page_range[i]
start_page, end_page = parse_page_range(range_string, reader.pages)
- if end_page > len(reader.pages): # no need to test start_page cause start_page > end_page is checked above
- raise HandledException(f"-p: page range goes beyond pages of input file: {range_string}")
for old_page_num in range(start_page, end_page):
new_page_num += 1
- page = reader.pages[old_page_num]
+ if old_page_num >= len(reader.pages):
+ page = pypdf.PageObject.create_blank_page(width=A4_WIDTH, height=A4_HEIGHT)
+ else:
+ page = reader.pages[old_page_num]
pages_to_add += [page]
print(f"-i, -p: read in {input_file} page number {old_page_num+1} as new page {new_page_num}")
return pages_to_add, opened_files