Created
November 13, 2022 09:19
-
-
Save pranavgade20/4e0839509646ba6c8ad3b2c5f01727c6 to your computer and use it in GitHub Desktop.
A script to merge pdf files and add chapter annottions using ghostscript
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 | |
# usage: merge-pdf out.pdf `ls -v *.pdf` | |
merge-pdf() { | |
cumulative=1 | |
for f in "${@:2}" | |
do | |
cnt=$(gs -q -dNODISPLAY -dNOSAFER -c "($f) (r) file runpdfbegin pdfpagecount = quit") | |
echo "[/Page $cumulative /Title ($f) /OUT pdfmark" | |
cumulative=$((cnt+cumulative)) | |
done > pdfmark.txt | |
gs -q -dBATCH -dNOPAUSE -dNOSAFER -sDEVICE=pdfwrite -sOutputFile="$1" -dPDFSETTINGS=/prepress pdfmark.txt "${@:2}" | |
rm pdfmark.txt # cleanup | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment