Last active
May 16, 2016 22:09
-
-
Save max6cn/ed292abbe3ef487aae33f3733dcaacdc to your computer and use it in GitHub Desktop.
Script to add margin to a PDF file and merge with page number on footer(can be header also)
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
#!/bin/bash -f | |
prepocesse() { | |
pdfinfo newbook.pdf | |
pdflatex pageNumbers.tex | |
pdftk newbook.pdf burst output tmps/file_%04d.pdf | |
pdftk pageNumbers.pdf burst output tmps/number_%04d.pdf | |
} | |
format() { | |
pdfcrop --margin "29 50 29 50" tmps/file_${1}.pdf tmps/filem_${1}.pdf ; | |
pdfjam --outfile tmps/file_a4_${1}.pdf --paper a4paper tmps/filem_${1}.pdf ; | |
pdftk tmps/file_a4_${1}.pdf background tmps/number_${1}.pdf output tmps/new-${1}.pdf ; | |
} | |
postprocess() { | |
pdftk tmps/new-????.pdf output new.pdf | |
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new-s.pdf new.pdf | |
cp new-s.pdf .. | |
} | |
PAGES=64 | |
JOBS=8 | |
pid=() | |
prepocesse | |
for i in {0..7} ; do | |
for ((j=1; j<$PAGES; j=$j+8)); do | |
format $(printf "%0.4d" $(($i+$j))) | |
# sleep 0.5 | |
done & | |
pid[$i]=$? | |
done | |
for i in {0..7}; do | |
wait ${pid[$i]} | |
done | |
postprocess | |
echo done $(date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pagenumber.tex