Skip to content

Instantly share code, notes, and snippets.

@max6cn
Last active May 16, 2016 22:09
Show Gist options
  • Save max6cn/ed292abbe3ef487aae33f3733dcaacdc to your computer and use it in GitHub Desktop.
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)
#!/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)
@max6cn
Copy link
Author

max6cn commented May 16, 2016

Pagenumber.tex

\documentclass[12pt,a4paper]{article}
\usepackage{multido}
\usepackage[hmargin=.8cm,vmargin=1.5cm,nohead,nofoot]{geometry}


\begin{document}
\multido{}{1588}{\vphantom{x}\newpage}
\end{document}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment