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.
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.
- Install Calibre with
sudo apt install calibrefrom the default Ubuntu repositories.
- Open Calibre and click on the Add books icon in the Calibre menu. A file selection window will open up.
- Browse to the epub file(s) that you want to add, and select one or more epub files to add to Calibre.
- 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.
- 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).
- 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.
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.
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
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.
Here's my recipe :
pandoc -s -t latex --toc --chapters \ --latex-engine=lualatex $BOOK.epub -o $BOOK.pdf
if the additon of
--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
$ 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
$ pandoc \ -s -t latex \ --toc --chapters \ --latex-engine=lualatex \ --data-dir=. $BOOK.epub -o $BOOK.pdf
Please fist install
calibre by running the following command
sudo apt-get -y install calibre
Afterwards you can simply convert yout
epub file into
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