Created
March 25, 2023 23:14
-
-
Save ivanistheone/9f90ee676e5059d2aaf71346263ac129 to your computer and use it in GitHub Desktop.
Converst an .epub file to .pdf --- because Preview is easier to use than iBooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# Converts an .epub file to .pdf | |
# Requires Calibre and ghostscript to be installed | |
epubfilename="$1" | |
namenoext="$(basename -- "$epubfilename" .epub)" | |
randomstr="$(basename $(mktemp))" | |
tmpfilename1="$namenoext-$randomstr-1.pdf" | |
tmpfilename2="$namenoext-$randomstr-2.pdf" | |
pdffilename="$namenoext.pdf" | |
echo "Convering $epubfilename to pdf..." | |
ebook-convert "$epubfilename" "$tmpfilename1" --embed-all-fonts | |
gs \ | |
-sDEVICE=pdfwrite \ | |
-dCompatibilityLevel=1.4 \ | |
-dPDFSETTINGS=/ebook \ | |
-dNOPAUSE -dQUIET -dBATCH \ | |
-dPrinted=false \ | |
-sOutputFile="$tmpfilename2" \ | |
"$tmpfilename1" | |
rm "$tmpfilename1" | |
mv "$tmpfilename2" "$pdffilename" | |
echo "PDF file saved to $pdffilename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment