EPUB is a popular file format supported by e-book readers on Amazon Kindle, Mobiles, Tablets and other devices. But sometimes you may need to convert Epub to PDF file to be able to view the documents using Adobe Acrobat Reader. There are many Epub to PDF converters that allow you to easily convert Epub files to PDF files. You can also use online Epub to PDF converters for this purpose. But these allow conversion of only 1 file at a time. If you want to batch convert many Epub documents to PDF, it is advisable to use a package so you can run it via command line. In this article, we will learn how to convert Epub to PDF using Calibre command line software.
How to Convert Epub to PDF in Linux
Here are the steps to convert Epub to PDF in Linux. Calibre is not present on Linux systems, by default. You will need to install it using the following command.
1. Install Calibre
Open terminal and run the following command to install Calibre.
Ubuntu/Debian
$ sudo apt update $ sudo apt install calibre
Redhat/CentOS/SUSE/Fedora
In this case, we will use a binary install that has private versions of all its dependencies. Run the following command to install wget first and then use wget to download and install Calibre.
# CentOS $ sudo yum -y install wget # Fedora $ sudo dnf -y install wget $ sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin
2. Convert Epub to PDF File
Calibre software is referred to as ebook-convert command. Here is the command to convert epub file to pdf file.
ebook-convert <file>.epub <file>.pdf
Here is an example to convert /home/ubuntu/test.epub to /home/ubuntu/test.pdf.
ebook-convert /home/ubuntu/test.epub /home/ubuntu/test.pdf
Once the pdf file is created, you can verify it using file command.
$ file /home/ubuntu/test.pdf test.pdf: PDF document, version 1.4
If your PDF doesn’t appear to be properly readable, try converting the epub file again using –enable-heuristics option.
ebook-convert /home/ubuntu/test.epub /home/ubuntu/test.pdf --enable-heuristics
Calibre software is also available as GUI. You can download and install the software from its official website to be able to convert epub to pdfs graphically.
If you want to batch convert multiple epub documents to pdf you, you can loop through the file paths in your folder and run ebook-convert command for each file one by one. Let us say you have files test1.epub, test2.epub, …, test100.epub in /home/ubuntu folder. Here is how you can loop through the files in your folder one by one and call ebook-convert command on each of them.
#!/bin/bash for filename in /home/ubuntu/*.epub; do ebook-convert $(basename "$filename" .epub) "$(basename "$filename" .pdf)" done
Of course, there are other ways to do this. You can always use find command to find all epub files to be converted and call ebook-convert function on them using exec option or xargs command.
In this article, we have learnt how to convert epub to pdf documents using Calibre software. You can use these commands in your script or application to easily automate epub to pdf conversion. Since it is a command line tool, you can also use it to batch convert multiple epub documents to pdf. You can use either the command line or graphical version of Calibre depending on your requirement.
Also read:
How to Convert Docx to PDF in Linux
How to Remove Yum Repository in Linux
How to Remove Repository in Ubuntu
How to Deny Access to SSH Users or Groups
How to Batch Convert PNG to JPG in Linux
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.