gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
Please write a shell script for batch squeezing PDF files with CoherentPDF (cpdf)]
- User
Please write a shell script for batch squeezing PDF files with CoherentPDF (cpdf)]
- Assistant
Before we start, make sure you have CoherentPDF (cpdf) installed on your system. You can download it from here.
Here is a shell script to batch squeeze PDF files with CoherentPDF (cpdf):
#!/bin/bash # This script squeezes all the PDF files in the current directory and # saves the squeezed version in a folder called 'squeezed'. # Check if 'squeezed' directory exists; if not, create it if [ ! -d "squeezed" ]; then mkdir squeezed fi # Iterate through all PDF files in the current directory for file in *.pdf; do # Check if the file is actually a PDF if file --mime-type "$file" | grep -q pdf$; then # Call cpdf with the '-squeeze' option to squeeze the PDF cpdf -squeeze "$file" -o squeezed/"$file" echo "Squeezed: $file" fi done echo "All PDF files have been squeezed."To use this script, follow these steps:
- Open a text editor and paste the script contents.
- Save the file with a
.shextension (for example,squeeze-pdfs.sh). - Open your terminal (or command prompt on Windows with an appropriate shell) and navigate to the folder containing your PDF files.
- Make sure the script file is in the same folder as the PDF files or adjust the path accordingly in the terminal.
- Make the script executable by running
chmod +x squeeze-pdfs.sh(not required on Windows). - Run the script with
./squeeze-pdfs.sh(or./squeeze-pdfs.shon Windows' command prompt).
The script will create a folder named "squeezed" and save the squeezed versions of your PDF files in it.