60

I would like to know the ways in which epub files can be converted to pdf in ubuntu. Any method, GUI or command line conversion is fine as far as my epub gets converted to pdf. Thanks.

90

You definitely want Calibre. You can use it to convert virtually any file type to any other file type, as long as the source file doesn't have DRM (like Amazon, Adobe, etc.). If it does have DRM, check out Apprentice Alf's blog for help stripping it out with Calibre plugins. Don't use the DRM stripper to pirate books or otherwise violate your agreement with the vendor. Use it so you can enjoy your books on any device in any format.

Calibre is also an awesome e-book management program that can do virtually everything. It can manage Kindles, Android phones/tablets, etc. It can even email your books with one click to your Kindle's email address if you want. You won't be disappointed :-)

From a terminal:

sudo apt-get install calibre

Or search for it in Ubuntu Software Center

To actually convert the EPUB file you can use the following command:

ebook-convert file.epub file.pdf (For details, check this other answer)

Or you can check the details for the conversion dialog using the Calibre GUI.

  • 4
    I agree that Calibre is the way to go, but I would not install the version in the repos because they're outdated. There's a new version almost every Friday so I would install using the command recommended on the Calibre site sudo python -c "import sys; py3 = sys.version_info[0] > 2; u = __import__('urllib.request' if py3 else 'urllib', fromlist=1); exec(u.urlopen('http://status.calibre-ebook.com/linux_installer').read()); main()" – To Do Jun 1 '13 at 10:31
  • IOError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) – noobninja Sep 15 '15 at 16:15
  • 1
    sudo -v && wget -nv -O- https://raw.githubusercontent.com/kovidgoyal/calibre/master/setup/linux-installer.py | sudo python -c "import sys; main=lambda:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main()" – noobninja Sep 15 '15 at 16:23
  • works perfectly on ubuntu 14.04LTS, thanks! – hdoghmen Sep 23 '15 at 20:39
  • For full documentation of the conversion system see manual.calibre-ebook.com/conversion.html – The Demz Feb 1 '16 at 20:56
9
  1. Install Calibre from the Ubuntu Software Center.
  2. Open Calibre and click on the Add books icon in the Calibre menu. A file selection window will open up.
  3. Browse to the epub file(s) that you want to add, and select one or more epub files to add to Calibre.
  4. Select one or more epub files from the Calibre library in the center pane. Or type formats:"=EPUB" in the search box to search for only EPUB format files and select one or more epub files from the filtered library list in the center pane. Click on the Convert books icon in the Calibre menu.
  5. A new Convert window will open up. In the Convert Window for the Input format select EPUB. For the Output format select PDF. Click the OK button to start converting the file(s).
  6. To find your PDF files, click on a file that you converted to PDF. In the pane on the right-hand side of Calibre you will see an entry called Path: Click to open. Click on the link for "Click to open" to open a new file browser window at the directory of the PDF file.
7

epub to pdf converter

Before trying calibre, I actually converted my file using the above program, a command line epub to pdf converter that is actually good with some handy options.

Usage:

1) unzip the file into a convenient location, and change to the unzipped folder in terminal

2) make the .sh file executable

 chmod +x ./epub2pdf.sh 

3) run the file

 ./epub2pdf.sh <path-to-epub-file>

The default output directory is home folder, but a lot of customization is available through a properties file where it can be changed.

Though the program hasn't been updated for a while, it works really good and I thought it might be an option for people to try out for converting their epub to pdf.

  • Good find! That's handy for a quick and dirty convert – Freedom_Ben May 27 '13 at 15:20
4
sudo apt install pandoc
pandoc -f epub -t pdf infile.epub -o outfile.pdf
2

Here's my recipe :

pandoc -s -t latex --toc --chapters \
        --latex-engine=lualatex $BOOK.epub -o $BOOK.pdf

if the additon of --toc and --chapters does not produce the desired results, leave these out. Sometimes the pictures inside the epub are invalid to be used with latex so you need to convert them in the process :

$ pandoc -s -t latex --toc --chapters \
    --latex-engine=lualatex $BOOK.epub -o $BOOK.pdf
!LuaTeX error (file /tmp/tex2pdf.23440/3f21bef8dd2877aad72f5cddbf00284ca88fa0e7
.jpg): reading JPEG image failed (no marker found)
 ==> Fatal error occurred, no output PDF file produced!

pandoc: Error producing PDF

Here's a workaround. Check to see if a tex file can be produced:

$ pandoc \
-s -t latex \
--toc --chapters \
--latex-engine=lualatex $BOOK.epub -o $BOOK.tex

Extract images and other media contained in the epub container to the path DIR, creating it if necessary, and adjust the images references in the [LaTeX] document so they point to the extracted files, with the option --extract-media= DIR . Select the current directory which also contains the ePub file. Add --extract-media=. which means extract in the current directory, which is also $HOME/Documents

$ cd Documents
$ pandoc \
-s -t latex \
--toc --chapters \
--latex-engine=lualatex \
--extract-media=. $BOOK.epub -o $BOOK.tex
pandoc: extracting ./images/9781501144158.jpg
pandoc: extracting ./images/com-01.jpg
pandoc: extracting ./images/f0003-01.jpg
pandoc: extracting ./images/f0005-01.jpg
[ ----- extract-media logging shortened ---- ]
pandoc: extracting ./images/f0177-01.jpg
pandoc: extracting ./images/f0187-01.jpg
pandoc: extracting ./images/logo.jpg
pandoc: extracting ./images/logo1.jpg
pandoc: extracting ./images/title.jpg

Repeal the extracted .jpg images by creating new LaTeX compatible JPEG images with the `convert' utility (from the imagemagick program suite)

$ cd images
$ convert logo1.jpg logo1.jpeg 

and Replace the previously with pandoc extracted .jpg images with the newly created .jpeg images:

$ mv logo1.jpeg logo1.jpg 

One can do this with a single for loop on the commandline:

$ cd images/
$ for i in *.jpg; do convert $i `echo $i | sed 's/jpg/jpeg/'`; done
$ rm -f *.jpg
$ for i in *.jpeg; do mv $i `echo $i | sed 's/jpeg/jpg/'`; done 
$ cd ..

Run the first command line again, but this time have the LuaTeX engine seek for its \includegraphics in the same directory as where the ePub images were extracted earlier (--data-dir=DIRECTORY Specify the user data directory to search for pandoc data files. If this option is not specified, the default user data directory will be used. This is, in Unix: $HOME/.pandoc) by adding the option --data-dir=.:

$ pandoc \
-s -t latex \
--toc --chapters \
--latex-engine=lualatex \
--data-dir=. $BOOK.epub -o $BOOK.pdf
1

I really liked the answer that I saw on a similar post here: https://askubuntu.com/a/170119

Especially the following command helped me get a better conversion:

ebook-convert file.pdf file.epub --enable-heuristics
  • 7
    Ehm, you've got it the wrong way around. This question is about converting from EPub to PDF. – David Foerster Mar 19 '15 at 1:02

protected by Community Nov 13 '17 at 10:22

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.