0

I know there is another thread with many answers for this question; however, I am a newbie and a lot of that was gibberish to me. I am trying to learn though:)

Anyway, I've installed ghostscript and tried to run it a few times using this script

for file in *.pdf ; do gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
         -sOutputFile="${file%.pdf}-page1.pdf" -dFirstPage=1 -dLastPage=1 "$file" ;

I got that script from here.

I didn't really know where to put the directory name that I wanted the program to batch extract from nor the output filename, and or the output director. I realize this is basic stuff for most you but if anyone could help me out you'd be saving me probably years of work.

Thanks!

AFH
  • 17,958

1 Answers1

0

The directory where the PDF files reside is the current directory, since for files in *.pdf ; ... does not specify a directory path for the matching files.

The output file is formed from "$file" with the bash expansion "${file%.pdf}-page1.pdf", which deletes .pdf from the end of the file name and replaces it with -page1.pdf, so that, for example, report.pdf generates the output file report-page1.pdf in the same directory.

You can prepend a directory path in the for clause, eg for files in SourceDir/*.pdf ; ...

You can change the replacement string; or you can prepend a directory, though the substitution becomes more complex if you use a directory path in the for clause.

You should read up on Parameter Expansion in the bash manual.

AFH
  • 17,958