如何在 Fedora 上生成 EPUB 电子书
电子书
![](/data/attachment/album/202006/14/132129wwnfkgdg6gpipzfp.png)


在智能手机上阅读内容正在变得越来越流行。每一部手机都有它自己的电子书阅读器。可能你不知道，在 Fedora 创建你自己的电子书文件是非常容易的。


这篇文章展示了使用两种不同的方法来创建一个 [EPUB](https://en.wikipedia.org/wiki/EPUB) 文件。EPUB 格式是最流行的格式之一，并且被很多开源软件所支持。


绝大数的人们将会询问 “在很容易创建 PDF 文件的情况下，为什么要花费时间和精力来创建 EPUB 文件?” 答案是: “你曾经尝试看过每次只能看到一张纸的一小部分的吗?”为阅读一个 PDF 文件，你不得不经常缩放和移动文档，或者将其缩放到一个小尺寸来适合屏幕大小。在另一方面，EPUB 文件则被设计成可以适合很多不同的屏幕类型。


### 方法 1: ghostwriter 和 pandoc


第一种方法创建一个速成版的电子书文件。它使用一个名为 [ghostwriter](https://github.com/wereturtle/ghostwriter) 的 Markdown 编辑器，和一个名为 [pandoc](https://pandoc.org/) 的命令行文档转换工具。


你可以从软件中心搜查和安装它们，也可以从终端中安装它们。如果你使用终端来安装它们，运行这个命令:



```
sudo dnf install pandoc ghostwriter

```

对于那些不知道 [Markdown](https://fedoramagazine.org/applications-for-writing-markdown/) 是什么的人们来说，在这里有一个简要的解释：它是一个大约在 15 年前创建的简单的标记语言。它使用简单的语法来格式化纯文本。Markdown 文件可以随后转换成很多其它文档格式的文件。


![ghostwriter](/data/attachment/album/202006/14/132130reyre8zcctt2phjc.jpg)


对于工具，ghostwriter 是一个跨平台的易于使用的 Markdown 编辑器。pandoc 是一个非常易于使用的文档转换工具，可以处理数百种不同的格式。


要创建你的电子书，打开 ghostwriter，开始编写你的文档。如果你以前使用过 Markdown，你可能习惯于在文档的“标题 1”的前面放置一个 `#` 符号来作为标题。像这样: `# My Man Jeeves`。然而，pandoc 将不会识别其为标题，并将在你的电子书的顶部放置一个一个大的 “UNTITLED” 。相反地在你的标题前放置一个 `%` 来作为标题。例如，`% My Man Jeeves` 。章节应该被格式为“标题 2”，例如，`## Leave It to Jeeves`。如果你有子章节，使用“标题 3”（`###`）。


![](/data/attachment/album/202006/14/132131b6bem2yes6rz24j8.jpg)


在你的文档完成后，单击“文件 -> 导出”（或按 `Ctrl+E` 键）。在对话框中，在几个 Markdown 转换器中进行选择。如果这是你第一次使用 ghostwriter ，默认选择的是 Sundown 转换器。从对话框中，选择 pandoc 。接下来单击“导出”。现在你的 EPUB 文件已经创建好了。


![ghostwriter 导出对话框](/data/attachment/album/202006/14/132132on9xxvh5payyoayr.jpg)


注意: 如果你得到一个与 pandoc 有关的错误，关闭“智能排版”，并再试一次。


### 方法 2: calibre


如果你想要一个更完美的电子书，那这就是你正在寻找的方法。它需要更多的步骤，但是是值得的。


![](/data/attachment/album/202006/14/132133neever0vvafsj7vh.jpg)


首先，安装一个名为 [calibre](https://calibre-ebook.com/) 的应用程序。calibre 不仅仅是一个电子书阅读器，它也是一个电子书管理器系统。你可以从软件中心安装它，也可以从终端安装它：



```
sudo dnf install calibre

```

在这个方法中，你可以在 LibreOffice、ghostwriter，或者其它你选择的编辑器中编写你的文档。确保书籍的标题被格式为“标题 1”，章节被格式为“标题 2”，子章节被格式为“标题 3”。


接下来，导出你的文档为一个 HTML 文件。


现在添加该文件到 calibre 。打开 calibre ，并单击 “添加书籍”。calibre 会用几秒钟来添加文件。


![](/data/attachment/album/202006/14/132133xpr1zkn11h33gin1.jpg)


在文件导入后，通过单击 “编辑元数据” 按钮来编辑文件的元数据。在这里你可以填写书的标题和作者的姓名。你也可以上传一个封面图片（如果你有的话），或者 calibre 将为你生成一个封面。


![](/data/attachment/album/202006/14/132134c5ar0j99brw20a0a.jpg)


接下来，单击 “转换书籍” 按钮。在新的对话框中，选择 “界面与外观” 部分的 “布局” 标签页。勾选 “删除段间空行” 选项。这将更加严格地缩进每一段的内容。


![](/data/attachment/album/202006/14/132134kygalt0l94s5sl4o.jpg)


现在，设置目录。选择 “内容目录” 部分。这里有三个需要注意的选项: “一级目录”、“二级目录” 和 “三级目录”。对于每一个选项点击其末尾处的魔法棒按钮。在新的对话框中，选择应用于目录表项的 HTML 标记。例如，为“一级目录”选择 “h1”。


![](/data/attachment/album/202006/14/132135cvp5pioarnjzr1yn.jpg)


接下来，告诉 calibre 包含内容目录。选择 “输出 EPUB” 部分并勾选 “插入内联目录”。单击“确定“ 创建 epub 文件。


![](/data/attachment/album/202006/14/132135d3vciviev64gci5c.jpg)


现在，你有了一个看起来很专业的电子书文件。




---


via: <https://fedoramagazine.org/how-to-generate-an-epub-file-on-fedora/>


作者：[John Paul Wohlscheid](https://fedoramagazine.org/author/johnblood/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[robsean](https://github.com/robsean) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
It is becoming more popular to read content on smartphones. Every phone comes with its own ebook reader. Believe or not, it is very easy to create your own ebook files on Fedora.

This article shows two different methods to create an [EPUB](https://en.wikipedia.org/wiki/EPUB). The epub format is one of the most popular formats and is supported by many open-source applications.

Most people will ask “Why bother creating an EPUB file when PDFs are so easy to create?” The answer is: “Have you ever tried reading a sheet of paper when you can only see a small section at a time?” In order to read a PDF you have to keep zooming and moving around the document or scale it down to a small size to fit the screen. An EPUB file, on the other hand, is designed to fit many different screen types.

## Method 1: ghostwriter and pandoc

This first method creates a quick ebook file. It uses a Markdown editor named [ghostwriter](https://github.com/wereturtle/ghostwriter) and a command-line document conversion tool named [pandoc](https://pandoc.org/).

You can either search for them and install them from the Software Center or you can install them from the terminal. If you are going to use the terminal to install them, run this command: *sudo dnf install pandoc ghostwriter*.

For those who are not aware of what [Markdown](https://fedoramagazine.org/applications-for-writing-markdown/) is, here is a quick explanation. It is a simple markup language created a little over 15 years ago. It uses simple syntax to format plain text. Markdown files can then be converted to a whole slew of other document formats.

![](https://fedoramagazine.org/wp-content/uploads/2020/05/ghostwriter-1024x640.jpg)

Now for the tools. ghostwriter is a cross-platform Markdown editor that is easy to use and does not get in the way. pandoc is a very handy document converting tool that can handle hundreds of different formats.

To create your ebook, open ghostwriter, and start writing your document. If you have used Markdown before, you may be used to making the title of your document Heading 1 by putting a pound sign in front of it. Like this: *# My Man Jeeves*. However, pandoc will not recognize that as the title and put a big UNTITLED at the top of your ebook. Instead put a *%* in front of your title. For example, *% My Man Jeeves*. Sections or chapters should be formatted as Heading 2, i.e.* ## Leave It to Jeeves*. If you have subsections, use Heading 3 (*###*).

![](https://fedoramagazine.org/wp-content/uploads/2020/05/ghostwriter-menu-1024x640.jpg)

Once your document is complete, click *File* -> *Export* (or press *Ctrl* + *E*). In the dialog box, select between several options for the Markdown converter. If this is the first time you have used ghostwriter, the Sundown converter will be picked by default. From the dialog box, select pandoc. Next click *Export*. Your EPUB file is now created.

![](https://fedoramagazine.org/wp-content/uploads/2020/05/ghostwriter-export-1024x640.jpg)

Note: If you get an error saying that there was an issue with pandoc, turn off *Smart Typography* and try again.

## Method 2: calibre

If you want a more polished ebook, this is the method that you are looking for. It takes a few more steps, but it’s worth it.

![](https://fedoramagazine.org/wp-content/uploads/2020/05/calibre-pre-1024x640.jpg)

First, install an application named [calibre](https://calibre-ebook.com/). calibre is not just an ebook reader, it is an ebook management system. You can either install it from the Software Center or from the terminal via *sudo dnf install calibre*.

In this method, you can either write your document in LibreOffice, ghostwriter, or another editor of your choice. Make sure that the title of the book is formatted as Heading 1, chapters as Heading 2, and sub-sections as Heading 3.

Next, export your document as an HTML file.

Now add the file to calibre. Open calibre and click “*Add books*“. It will take calibre a couple of seconds to add the file.

![](https://fedoramagazine.org/wp-content/uploads/2020/05/calibre-metadata-1024x640.jpg)

Once the file is imported, edit the file’s metadata by clicking on the “*Edit metadata*” button. Here you can fill out the title of the book and the author’s name. You can also upload a cover image (if you have one) or calibre will generate one for you.

![](https://fedoramagazine.org/wp-content/uploads/2020/05/calibre-lookandfeel-1024x640.jpg)

Next, click the “*Convert books*” button. In the new dialog box, select the “*Look & Feel*” section and the “*Layout*” tab. Check the “*Remove spacing between paragraphs*” option. This will tighten up the contents as indent each paragraph.

![](https://fedoramagazine.org/wp-content/uploads/2020/05/calibre-toc2-1024x640.jpg)

Now, set up the table of contents. Select the “*Table of Contents*” section. There are three options to focus on: Level 1 TOC, Level 2 TOC, and Level 3 TOC. For each, click the wand at the end. In this new dialog box, select the HTML tag that applies to the table of contents entry. For example, select *h1* for Level 1 TOC and so on.

![](https://fedoramagazine.org/wp-content/uploads/2020/05/calibre-epub-output-1024x640.jpg)

Next, tell calibre to include the table of contents. Select the “*EPUB output*” section and check the “*Insert Inline Table of Contents*“. To create the epub file, click “*OK*“.

![](https://fedoramagazine.org/wp-content/uploads/2020/05/calibre-post-1024x640.jpg)

Now you have a professional-looking ebook file.

## Robert Keeney

There are a lot of command-line tools that come with Calibre one of these is ebook-convert.

## John Paul Wohlscheid

I was unaware of that. Thanks. I’ll look into it.

## dimwit

Cool, but where is the paragraph with some usage examples of the pandoc command line conversion tool?

Ok, as a seasoned Linux user I would study pandoc’s man page now.

## John Paul Wohlscheid

“where is the paragraph with some usage examples of the pandoc command line conversion tool?”

Unfortunately, I haven’t used pandoc from the command line. You don’t need to know those commands to make an epub file, but I’m sure it would help.

## Alper Orus

It’s simply $ pandoc -s -o output.docx file.md

## petersen

You can read the pandoc manual at https://pandoc.org/MANUAL.html or run

.

## Chris Moller

A more elaborate use of calibre, one I use in writing books, is to write the book using DocBook markups, an HTML-like schema.

DocBook sources can be spun in different ways, including directly to publication-quality PDF as well as to HTML, and then from there to EPUB using a CLI utility, called ebook-convert, that’s part of the calibre package. (I use a Makefile to run all that, so going from DocBook to EPUB is just a matter of pounding in “make epub” on the command line.)

The advantage of all this is that DocBook offers a lot of things like title page formatting, table-of-contents, bibliography, index, and glossary formatting, etc, and gives you access to most or all of the Unicode character set. You can also write the DocBook source using any text editor–I use emacs–that gives you a lot more control than WYSIWYG things like LibreOffice. (A plus of emacs is that you can customise it to, for example, have it insert things like pairs with a single keystroke.)

(DocBook is part of the “Authoring and Publishing” packages group.)

(Editor’s note: This comment was edited to remove artifacts of WordPress trying to treat the example as HTML)## John Paul Wohlscheid

I never heard of DocBook before. Thanks for mentioning it. I stopped using word processors about five years ago and now write exclusively in Markdown. I was writing in plain text, but I wanted to be able to add simple formating. I discovered Markdown and was hooked.

## John Paul Wohlscheid

Also, I’ve been meaning to get into the world of emacs, but haven’t had a chance to do so.

## Leslie Satenstein

My bit of fun for today.

This symbol # is called the octothorpe

and this one £ is the pound symbol.

I am not sure what to call ¤

And yes, I did find your article informative and I learned about

pandoc, ghostwriter and more.

Thanks

Leslie

## John Paul Wohlscheid

Thanks for setting me straight. I’ll fix it. By the way, was it named after a guy named Thorpe or a guy named Octo? 🙂

## leslie Satenstein

Hi John,

Actually, named after Thorpe. He was born missing the two pinky fingers from each hand.

No-one questioned him about his toes.

I also discovered that the ¤ on my Canadian French keyboard layout. I believe it represents currency, but the glyph has no name.

## Vernon Van Steenkist

In the Linux/Unix world, # is known as the pound, hash or number symbol – never the octothorpe symbol.

## Paul W. Frields

What Leslie means is that’s the actual name for the symbol itself. People also often call & an “and,” although the symbol is itself named the ampersand, because it’s clumsy to say “use ampersand ampersand for a logical AND” instead of “use ‘and and’ for a logical AND.” You’re right though, we usually refer to # as pound, hash, or number.

## robert pratersch

My E-Reader tolino doesnt work with linux/fedora. lsusb command list the device correctly but mounting did not work. So Fedora is unable to communicate with the device. What can i do?

## Ben Cotton

Robert, this sounds like a good question to post on Ask Fedora.

## Vernon Van Steenkist

What do you mean doesn’t work? Have you tried opening Calibre, connecting your tolino reader to your computer, and seeing if Calibre recognizes it?

## Rene Reichenbach

I am using Tolino shine 1 and 3 … both work flawless with fedora 32.

I fear your setup is slightly broken.

## Eduard Lucena

Quick fix: “Level 1 TOC, Level 3 TOC, and Level 3 TOC” should be “Level 1 TOC, Level 2 TOC, and Level 3 TOC”

## Ben Cotton

Fixed, thanks!

## Vernon Van Steenkist

A few comments.

Both LibreOffice and the web version of Google Docs, accessible through Firefox and Chromium will export into epub format directly. Not sure why you are exporting to HTML, importing into Calibre and then converting to epub.

Besides an epub editor, Calibre is also an e-book library. Epubs catalogued in the Calibre library can be transferred to an e-book reader by Calibre via USB. In addition, Calibre can act as a server. The Calibre Content Sharing button allows you to access your library through an HTML web browser (ex. http://fedorabox:8080) or an e-book reader supporting OPDS (ex. (ex. http://fedorabox:8080/opds). The Calibre server can be started through the menus or from the command line (calibre-server).

Reading e-books on your phone can cause eye problems since the screen is constantly refreshing and generating light. You are much better off reading e-books on an e-ink e-book reader. E-ink screens reflect light rather than emit light and the screen only refreshes when you turn the page. E-ink is like paper and will not wash out in direct sunlight. I personally use an Onyx Boox e-book reader model that supports WiFi and OPDS.

Finally, another way to generate epubs is to scan your paper book or printed page (scanimage), process the image with unpaper (unpaper) and then perform optical character recognition on the scanned image via tesseract. The resulting text file can be edited and converted into an epub via Calibre. You can also convert the scanned image to pdf using convert and then perform optical character recognition via the web version of Google Docs.

## John Paul Wohlscheid

Thanks for the input. I haven’t used LibreOffice or Google Docs in a while.

## Sergey

https://the-digital-reader.com/2018/02/01/libre-office-6-0-now-makes-epub-ebooks/

## Anthony

I have experimented with asciidoc, and with asciidoctor, using the output as html. Alternatively, if I specify the output as docbook, I can then use pandoc to send it to many different formats, such as epub, docx, or latex. Where I need precise PDF output, I’ve found writing latex the best method. I’ve wondered how to go from docbook to customised html (i.e. themed), but couldn’t wrap my head around xslt/saxon or whatever the mechanisms were to achieve that.

## John Paul Wohlscheid

I have experimented with LaTex, but it has more features than I need. I’ll have to look into asciidoc.

## Stefano Costa

LibreOffice Writer can export to EPUB as well. It’s perhaps a little less flexible than the tools described above but it is much more accessible. On my Fedora Workstation it’s in the “File – Export as …” menu.

## John Paul Wohlscheid

Cool. Thanks.

## Morten Juhl-Johansen Zölde-Fejér

I would write a piece on the excellent Sigil application, but I see that Fedora carries a rather older version of it.

## Marc Balmer

There is also AsciiDoctor, asciidoctor.org, which produces beautiful e-books in .epub format.