Skip to content

Instantly share code, notes, and snippets.

@Thomashighbaugh
Created June 1, 2024 11:32
Show Gist options
  • Save Thomashighbaugh/dd26792bca24a05f880947199dec77a7 to your computer and use it in GitHub Desktop.
Save Thomashighbaugh/dd26792bca24a05f880947199dec77a7 to your computer and use it in GitHub Desktop.
Converts epubs and azw files into PDFs, recursively within the present directory.
#!/bin/bash
# Check if Calibre's ebook-convert command is available
if ! command -v ebook-convert &>/dev/null; then
echo "Calibre's ebook-convert command not found. Please install Calibre."
exit 1
fi
# Create a directory to store the converted PDF files
mkdir -p converted_pdfs
# Loop through EPUB and AZW files in the current directory
for ebook in *.epub *.azw; do
if [ -f "$ebook" ]; then
# Extract the file name without extension
filename_noext=$(basename -- "$ebook" | cut -f 1 -d '.')
# Convert the ebook to PDF and store it in the "converted_pdfs" directory
ebook-convert "$ebook" "converted_pdfs/${filename_noext}.pdf"
echo "Converted $ebook to PDF"
fi
done
echo "Conversion complete. PDF files are stored in the 'converted_pdfs' directory."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment