1

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?

  • Would you be open to LaTeX solutions? Unless you already use LaTeX, it will probably be overkill to install it just for this. – terdon Dec 13 '17 at 20:55
  • Yes. In fact, foo.pdf was generated by foo.tex! – Brian Fitzpatrick Dec 13 '17 at 20:59
  • 2
    Oh wow, in that case there are all sorts of things you can do, but by going back to the original 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. – terdon Dec 13 '17 at 21:08
  • This may work using Latex: Insert a blank page after current – RubberStamp Dec 13 '17 at 21:19
3

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 make blank100.pdf (a pdf with 100 blank pages)? – Brian Fitzpatrick Dec 13 '17 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 '17 at 21:29
  • @terdon Issuing this command raises the error GPL Ghostscript 9.10: Unrecoverable error, exit code 1 – Brian Fitzpatrick Dec 13 '17 at 21:34
  • @BrianFitzpatrick oh. I just copy/pasted it on my Arch and it worked fine. Sorry. – terdon Dec 13 '17 at 21:36
0

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/.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.