Last active
March 25, 2021 20:48
-
-
Save svenk/98cc2731b0b115b59281 to your computer and use it in GitHub Desktop.
Insert blank (white) pages between each page in a PDF file from shell
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
#!/bin/bash | |
base64 -d <<BASE | gunzip > blank.pdf | |
H4sICAEz+lIAA2JsYW5rLnBkZgCNVE1P20AQpa16WXEk970goCXsh712XCGkxB8RIgiU5ECbcjDO | |
AqHBRs66Cr32RvsTKvXSX1CpVZF6Kn+g6qWnnntHcO9snJCUILWW7PW+ed55b2bk+W0vKLIVE81f | |
fLj4evH54j3imOJk7witrpKajA/UITYAqZOg01UyJUE3VNKTUdKWa2uop1IZHqP+O+O70Vz8/ahJ | |
t+nMx1px8/rt3HJt9np57qx+/u3T3OWX+wVUuNr99Xqz8ONN4co9q809vyzcP58JH87+RDJuD0+C | |
N50cGUMVlnEDmWNhzdMTSXa29o5kpBBpZHtKA0GSHiNSqST9Fi462OQUW9TU6wrDu4hU0yQ7ga8b | |
pJmGce8kTGUcnRK3QTz5shPJerVCNrBKM+1sZL6E7nCOJq0/mIHr3h0exFiwW8Z0RSCMMYnCwSuc | |
MOLZN7xJtDT+OkhihTWrjkaudRFS8KZBrdbvq2pDgUAI+NWGwGIU2U6TqCFVi0CrSVP2FVk/Dg+k | |
my/r+VLZnUzNblV6GxjwgHIpbA2GoS57SZZGsodLg/2mbHdCXXgKW+EIXDL57n8VfH1YcOKCSUjQ | |
w3yofKTGukNND92WgMYa8IQI3feNTrvXwtpUXW/dJAMfbCKDcyuDG6qwmxzkmXLHiGydyLgcqU4S | |
t/KjyM7TZzjOut38QeHoWhgfLLZl0fOX/qonHScoZ+owSVcDPwgoFQaltkWpJeD2KeUUGubCEKkx | |
xQYKh7ADq5lTbZ73tZ1FcsQz3Zxj8SEfeCbgljW8dczIcQhTA87ikNJgo5TgzIMBWvSecMpMyhlj | |
glvUeUzZAqULSxOG+qncRxQzhujNhS0hDIH38QgTBkznIBLfYJQ5UxgTxjRm8ynMMKe/tWxrmlea | |
5pmMTWG2Pa2vZNMxptKw05Wp7lqj80qCXVJPEoWdfCDW4/0ED1qrNx5u4dWyxwR0iTm87PBKxYCm | |
+rbj2zYrMc65WEP/pugR9ZLIPZTRi152jIljcuHSki6oblzZC0zfMzzXdMsVQVmQ/4zCVA26wqjt | |
oPl5fytAfwDZoOdK3QUAAA== | |
BASE | |
file blank.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
#!/bin/bash | |
INPUT_PDF=$1 | |
BLANK_PDF="blank.pdf" | |
NUMPAGES=$(pdftk "${INPUT_PDF}" dump_data 2>/dev/null | grep NumberOfPages | sed 's/[^0-9]*//') | |
PAGES=$(python -c "print ' B1-1 '.join(['A%d-%d'%(x,x) for x in range(1,${NUMPAGES}+1)])") | |
pdftk A="${INPUT_PDF}" B="${BLANK_PDF}" cat ${PAGES} output "blanked_${INPUT_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
Usage: | |
./insblank.sh yourfile.pdf | |
Output goes to blanked_yourfile.pdf. | |
This shell (bash for convenience) script uses pdftk and python. It needs a file herein callede blank.pdf which contains a white page/blank page, which can easily be generated from any program (e.g. OpenOffice). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment