Last active
May 15, 2019 12:36
-
-
Save kana/4530b802c3919c54236e51bffe1b83c8 to your computer and use it in GitHub Desktop.
Rearrange PDF pages
This file contains 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
# Original PDF: | |
# 1. Front cover | |
# 2. content 1 | |
# 3. content 2 | |
# 4. ... | |
# 5. content -2 | |
# 6. content -1 | |
# 7. Back cover | |
# | |
# Resulting PDF: | |
# 1. Front cover | |
# 2. conent 2 + content 1 (right-to-left) | |
# 3. ... (right-to-left) | |
# 4. content -1 + content -2 (right-to-left) | |
# 5. Back cover | |
# Separate pages. | |
qpdf k-original.pdf --pages . 1 -- k-t-1.pdf | |
qpdf k-original.pdf --pages . 2-r2 -- k-t-2r2.pdf | |
qpdf k-original.pdf --pages . z -- k-t-z.pdf | |
# Convert content pages into right-to-left 2-up layout. | |
pdfpun k-t-2r2.pdf --outfile k-t-2r2-pun.pdf | |
# Join all pages. | |
# | |
# Note that all pages in an output file from pdfjam will have the same size and orientation. | |
# Therefore gs is used instead of pdfjam to join all pages. | |
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=k-gs.pdf k-t-1.pdf k-t-2r2-pun.pdf k-t-z.pdf |
This file contains 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
# Original PDF: | |
# 1. Front cover | |
# 2. content 1 | |
# 3. content 2 | |
# 4. ... | |
# 5. content -2 | |
# 6. content -1 | |
# 7. Back cover | |
# | |
# Resulting PDF: | |
# 1. Front cover | |
# 2. conent 1 + content 2 | |
# 3. ... | |
# 4. content -2 + content -1 | |
# 5. Back cover | |
n=164 # Number of pages in original.pdf | |
qpdf original.pdf --pages . 1 -- t-1.pdf | |
qpdf original.pdf --pages . 2-r2 -- t-2r2.pdf | |
qpdf original.pdf --pages . z -- t-z.pdf | |
pdfnup t-2r2.pdf | |
pdfjoin --fitpaper true --rotateoversize false t-2r2-nup.pdf t-z.pdf t-1.pdf | |
pdfjam --fitpaper true t-1-joined.pdf "$((n / 2 + 1))" t-1-joined.pdf "1-$(( n / 2 - 1 ))" t-1-joined.pdf "$(( n / 2 ))" --outfile t-x.pdf | |
# pdfjam t-x.pdf --fitpaper true --trim '0.83cm 0cm 0.835cm 0cm' --clip true --outfile t-x-trimmed.pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment