Results 1 to 5 of 5
Greetings!
I would like to ask for you help resolving a little problem. Unfortunately I`m not a programmer
I have a lot of pdf files and I want to convert ...
- 10-09-2010 #1Just Joined!
- Join Date
- Oct 2010
- Posts
- 3
Batch script for all files in folder
Greetings!
I would like to ask for you help resolving a little problem. Unfortunately I`m not a programmer
I have a lot of pdf files and I want to convert them to a lower quality for the web. I tried to use the following command (using ghostscript):
Is there a way to make a batch to do this for all pdf-s in a folder?Code:gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Thank you in advance for your help!
I.
ps. if anyone knows a better way to reduce pdf dpi you can tell that too
- 10-09-2010 #2
for name in *.pdf ; do command ; done.
You will have to use "$name" in your command string instead of the literal filename."I'm just a little old lady; don't try to dazzle me with jargon!"
- 10-09-2010 #3Just Joined!
- Join Date
- Oct 2010
- Posts
- 3
Thank you for your answer!
But could you please a little more specific what do I have to do?
Write the line :
for $name in *.pdf ; do command ; done.
in a file and run it?
Thank you for your patiance!
- 10-10-2010 #4
The command that hazel gave is basically a loop in a Bash script. If we wrote a script to do it, it would look like this:
What this script does is:Code:for file in *.pdf; do output_file=$(echo "$file" | sed -re 's/\.pdf$/out.pdf/') gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$output_file" "$file" done
For every file ending in '.pdf' in the current directory, create a string called output_file, and then run the command, substituting the input file for "$file", and the output file for "$output_file". The output file name that I created here just adds '.out' before the '.pdf' of the filename. So we go from "file.pdf" to "file.out.pdf".
Hazel's approach was to collapse this script into a single line so that it's easy to run:
You could also copy the script that I wrote above into a file, and be able to run, for instance, a "downgrade_all_pdfs" command to run the command automatically in the current directory.Code:for file in *.pdf; do output_file=$(echo "$file" | sed -re 's/\.pdf$/out.pdf/'); gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$output_file" "$file"; done
This is all about Bash scripting. If you want to learn more, you can check:
Bash Guide for Beginners
Advanced Bash-Scripting GuideDISTRO=Arch
Registered Linux User #388732
- 10-10-2010 #5Just Joined!
- Join Date
- Oct 2010
- Posts
- 3
Thank you very much for your answer!


Reply With Quote