I have a pdf file foo.pdf
. I want to create a pdf file foo-blankbacks.pdf
whose odd pages are the pages of foo.pdf
and whose even pages are blank. Can this be easily accomplished from the command line?
2 Answers
There's an example in the pdftk
man page that serves as a good starting point:
EXAMPLES
Collate scanned pages
pdftk A=even.pdf B=odd.pdf shuffle A B output collated.pdf
In your case foo.pdf
is called even.pdf
and a second pdf called odd.pdf
is filled with blank odd pages. The only work left is to count the number of odd pages required.
If you want a quick answer:
$ convert xc:none -page Letter blank.pdf
$ pdftk blank.pdf cat 1 1 1 1 1 1 1 1 1 1 output 10blank.pdf
$ pdftk 10blank.pdf cat 1-10 1-10 1-10 1-10 1-10 1-10 1-10 1-10 1-10 1-10 output 100blank.pdf
I'm sure there's a much neater way to do this... but this will work for the immediate need.
-
If I have
blank.pdf
(one blank page), is there a convenient way to makeblank100.pdf
(a pdf with 100 blank pages)? Dec 13, 2017 at 20:39 -
@BrianFitzpatrick this should do it:
gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=/dev/stdout $(perl -e 'print "blank.pdf " x 100') > 100blank.pdf
– terdon ♦Dec 13, 2017 at 21:29 -
@terdon Issuing this command raises the error
GPL Ghostscript 9.10: Unrecoverable error, exit code 1
Dec 13, 2017 at 21:34 -
@BrianFitzpatrick oh. I just copy/pasted it on my Arch and it worked fine. Sorry.– terdon ♦Dec 13, 2017 at 21:36
You can hack this with a little script that generates a silly LaTeX file. First, you need to know how many pages you have in your foo.pdf
and then create the LatEx file with:
numberOfPages=100 ## change this to the correct number
echo '\documentclass{article}' > new.tex
echo '\usepackage{pdfpages}' >> new.tex
echo '\begin{document}' >> new.tex
for((i=1;i<=$numberOfPages;i++)); do
echo "\includepdf[pages=$i]{foo}"
echo '\newpage\null\thispagestyle{empty}\newpage'
done >> new.tex
echo '\end{document}' >> new.tex
Then, compile it and it should be what you need:
pdflatex new.tex
That said, it would be much easier to just generate the original foo.pdf
with extra blank pages, but how to do that would be best asked over at https://tex.stackexchange.com/.
foo.pdf
was generated byfoo.tex
!foo.tex
file. I don't remember how off the top of my head, but you can relatively easily configure LaTeX to add empty pages. You might want to post a question on TeX - LaTeX with your original LaTeX code and see if they can help.