converting epub files to PDF format

115,894

Solution 1

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.

Solution 2

  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.

Solution 3

sudo apt install pandoc
pandoc -f epub -t pdf infile.epub -o outfile.pdf

Solution 4

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.

Solution 5

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
Share:
115,894

Related videos on Youtube

UnicornsOnLSD
Author by

UnicornsOnLSD

Updated on September 18, 2022

Comments

  • UnicornsOnLSD
    UnicornsOnLSD almost 2 years

    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.

  • thorstorm
    thorstorm about 11 years
    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_instal‌​ler').read()); main()"
  • David Foerster
    David Foerster over 9 years
    Ehm, you've got it the wrong way around. This question is about converting from EPub to PDF.
  • noobninja
    noobninja almost 9 years
    IOError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
  • noobninja
    noobninja almost 9 years
    sudo -v && wget -nv -O- https://raw.githubusercontent.com/kovidgoyal/calibre/master/‌​setup/linux-installe‌​r.py | sudo python -c "import sys; main=lambda:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main()"
  • The Demz
    The Demz over 8 years
    For full documentation of the conversion system see manual.calibre-ebook.com/conversion.html
  • Jadeye
    Jadeye almost 6 years
    @ToDo's code yields errors, use noobninja' s code (14.04LTS)
  • Evgeny Bobkin
    Evgeny Bobkin over 4 years
    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
  • FredericB
    FredericB about 4 years
    Just a dumb hint, after install calibre, one can convert all files in a folder with the command (no quotes): "find . -name *.epub -exec ebook-convert {} {}.pdf \;"
  • Scott Wade
    Scott Wade almost 4 years
    calibre is a big package. The installation currently requires: After this operation, 906 MB of additional disk space will be used.
  • aderchox
    aderchox almost 4 years
    Newest installation recommendation by the official website: sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin W
  • CodeConnoisseur
    CodeConnoisseur over 3 years
    I tried this and got an error when converting epub to pdf
  • milia
    milia over 2 years
    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.