3

I have a series of PDFs (Computer Gaming World issues) and I want to remove the first page from the pdf file of each issue. There are 100 issues, so a GUI is just not gonna cut it. I used pdftk to remove the first page from one issue:

pdftk 1981_1112_issue1.pdf cat 1 output 1.pdf

My problem is that I do not want to have to modify and run this command for every pdf issue as that is not much better than the GUI method.

Using *.pdf as an input does not seem to work. What other ways can I use to run pdftk on every PDF?

Richard Martinez
  • 692
  • 1
  • 8
  • 16

2 Answers2

6

Loop on all issues. Output is named after issue by replacing "issue" by "output". The first line extract page 1, the second line extract the other pages:

for issue in *_issue*.pdf
do
    pdftk ${issue} cat 1 output page1_${issue/issue/output}
    pdftk ${issue} cat 2-end output otherpages_${issue/issue/output}
done
mouviciel
  • 66,855
  • 13
  • 106
  • 140
  • Oh I see how this works. I have done some programming but I didn't realize how variables worked in bash. What exactly are you doing with ${issue/issue/output}? – Richard Martinez Oct 16 '10 at 09:39
  • ${a/b/c} replaces the b substring by the c substring in the contents of the a variable. – mouviciel Oct 16 '10 at 10:13
1
shopt -s nullglob
for file in *.pdf
do
 out=${file%.pdf}_page1.pdf
 pdftk "$file" cat 1 output "$out"
done
ghostdog74
  • 327,991
  • 56
  • 259
  • 343