116

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.

7 Answers 7

155

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.

8
  • 10
    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, 2013 at 10:31
  • IOError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
    – noobninja
    Sep 15, 2015 at 16:15
  • 4
    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, 2015 at 16:23
  • 1
    For full documentation of the conversion system see manual.calibre-ebook.com/conversion.html
    – The Demz
    Feb 1, 2016 at 20:56
  • @ToDo's code yields errors, use noobninja' s code (14.04LTS)
    – Jadeye
    Jul 7, 2018 at 13:35
18
sudo apt install pandoc
pandoc -f epub -t pdf infile.epub -o outfile.pdf
2
  • cannot produce pdf output from pdf
    – nilon
    Sep 2, 2022 at 15:11
  • Sounds like your source actually was a PDF and not some epub file. Sep 3, 2022 at 19:55
15
  1. Install Calibre with sudo apt install calibre from the default Ubuntu repositories.
  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.
1
  • 2
    I tried this and got an error when converting epub to pdf Jan 26, 2021 at 19:38
11

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.

0
10

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
  • Hello, thanks for this reply. Just to report that using the lualatex engine produces an error for me. Using xelatex though works just fine: pandoc -s -t latex --toc --latex-engine=xelatex $BOOK -o $BOOK.pdf.
    – milia
    Mar 1, 2022 at 8:46
6

Please fist install calibre by running the following command

sudo apt-get -y install calibre 

Afterwards you can simply convert yout epub file into pdf with:

ebook-convert my-book.epub my-book.pdf --enable-heuristics

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

3
  • 9
    Ehm, you've got it the wrong way around. This question is about converting from EPub to PDF. Mar 19, 2015 at 1:02
  • Yep, it should be the other way around, but the idea is clear enough. First install sudo apt-get -y install calibre and second, simply run ebook-convert my-book.epub my-book.pdf --enable-heuristics Oct 20, 2019 at 6:03
  • 1
    calibre is a big package. The installation currently requires: After this operation, 906 MB of additional disk space will be used.
    – Scott Wade
    Jul 11, 2020 at 18:22
0

It is sufficient to open the EPUB file in a document viewer that can print to a PDF. For me, okular works very well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .