Last active
January 23, 2022 12:23
-
-
Save krzyspmac/01644a6aedace96fa9240a277d72a4ee to your computer and use it in GitHub Desktop.
Print rearranged page counts to reflect the order of the pages when printed as booklets of 3, double sided, sheets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Booklet of counter of sheets | |
booklet_sheet_count = 3 | |
booklet_package_page_count = booklet_sheet_count * 2 * 2 | |
pages = sys.argv[1:] | |
if len(pages) % booklet_package_page_count != 0: | |
sys.stderr.write("Page count of PDF needs to be a multiple of " + str(booklet_run_count) + ".\n") | |
sys.stderr.write("You can append blank pages using Preview if needed. Select the last page and choose 'Edit > Insert > Blank Page'.\n") | |
sys.exit(1) | |
page_count = len(pages) | |
run_count = len(pages) / booklet_package_page_count | |
sys.stdout.write("Number of pages = " + str(page_count) + "\n") | |
sys.stdout.write("Pages per sheet = " + str(2) + "\n") | |
sys.stdout.write("Sheet count per run = " + str(booklet_sheet_count) + "\n") | |
sys.stdout.write("Pages per run = " + str(booklet_package_page_count) + "\n") | |
sys.stdout.write("Runs = " + str(run_count) + "\n") | |
for i in range(0, page_count, booklet_package_page_count): | |
start = i | |
end = i + booklet_package_page_count-1 | |
double_page_counter = 2 * booklet_sheet_count | |
for n in range(0, double_page_counter): | |
if n % 2 == 0: | |
print(pages[end]) | |
print(pages[start]) | |
else: | |
print(pages[start]) | |
print(pages[end]) | |
start += 1 | |
end -= 1 | |
pass | |
pass | |
# usage: | |
# python test.py 1 2 3 4 5 6 7 8 9 10 11 12 | |
/* output */ | |
12 | |
1 | |
2 | |
11 | |
10 | |
3 | |
4 | |
9 | |
8 | |
5 | |
6 | |
7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment