tags:

views:

24

answers:

3

Hi, 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?

A: 
shopt -s nullglob
for file in *.pdf
do
 out=${file%.pdf}_page1.pdf
 pdftk "$file" cat 1 output "$out"
done
ghostdog74
I like this answer for its straightforwardness. Is the shopt line necessary?
John Smith
A: 

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
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}?
John Smith
${a/b/c} replaces the b substring by the c substring in the contents of the a variable.
mouviciel
A: 

If you can coding then both HotPDF and EzPDFlibrary from losLab can do this job well.

Sarah