如何以编程方式将 HTML 转换为 epub?

发布于 2024-09-13 23:45:54 字数 1539 浏览 12 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

转瞬即逝 2024-09-20 23:45:54

简短的回答是肯定的,它可以用任何编程语言来完成。

基本步骤:

  1. 将 HTML 转换为 XHTML (+ CSS)。这可以在您的程序中或通过 XSLT 文件完成。
  2. 将文件(XHTML、CSS、任何图像和字体)复制到遵循格式的目录结构中。
  3. 压缩目录结构并使用“.epub”扩展名命名存档。

一些可以帮助您入门的网站:

2015 年 6 月注意: epubcheck 验证器已移动从谷歌代码到 GitHub;记下新的 URL。

The short answer is yes, it can be done in any programming language.

Basic steps:

  1. Convert your HTML to XHTML (+ CSS). This can be done in your program or through an XSLT file.
  2. Copy your files (XHTML, CSS, any images and fonts) into a directory structure that follows the format.
  3. Zip the directory structure up and name the archive with a ".epub" extension.

Some web sites to help you get started:

June 2015 Note: The epubcheck validator has moved from google code to GitHub; note the new URL.

愛放△進行李 2024-09-20 23:45:54

Calibre 支持多种输入格式(包括 HTML)和多种输出格式(包括 EPUB) ,但它不是“一种编程语言或库”。您想要基于编程的方法而不是独立工具是否有具体原因?如果是这样,也许是 Python 和 ebookmaker。例如,py 可以帮助您。

Calibre supports a wide variety of input formats, including HTML, and a wide variety of output formats, including EPUB, but it's not "a programming language or library". Are there specific reasons you desire a programming-based approach rather than a free-standing tool? If so, maybe Python and ebookmaker.py, for example, could help you.

唠甜嗑 2024-09-20 23:45:54

回复晚了,但我发现基于 Python 3 的 ebookmaker 很有价值,至少在我之后贡献了一个删除 UTF-8 BOM 的拉取请求。它的一个问题似乎是它使用 解析 HTML 的脆弱正则表达式,但我想我必须在那里报告它。

A late reply, but I found the Python 3-based ebookmaker to be of value, at least after I contributed a pull request to remove a UTF-8 BOM. One problem with it appears to be that it uses brittle regular expressions to parse HTML, but I guess I'll have to report it there.

洒一地阳光 2024-09-20 23:45:54

这是pdf to epub,我知道这不是你想要的,但是这是一个开始。

calibre 包可能有你想要的

Here's pdf to epub, I know that's not what you're after, but it's a start.

The calibre package may have what you want

初吻给了烟 2024-09-20 23:45:54

我正在使用 Aspose 的以下库 - http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx

只需两行代码,我就可以进行 html 到 epub 的转换。当前在生产系统中使用它。

文档 doc = new Document(_sourceFilePath);

doc.Save(_destinationFilePath, SaveFormat.Epub);

I am using the following library from Aspose - http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx

In just two lines of code I am able to do html to epub conversions. Using this currently in a production system.

Document doc = new Document(_sourceFilePath);

doc.Save(_destinationFilePath, SaveFormat.Epub);

机场等船 2024-09-20 23:45:54

我刚刚开始用Java(兼容OpenJDK)实现这样一个工具:html2epub。为了摆脱手动编辑配置文件的麻烦,我可能会启动一个单独的工具来从任何给定目录生成配置文件(但是,仍然需要确定 EPUB 中 XHTML 的顺序 - 对于非-编程使用,可以考虑开发一个GUI帮助工具,对于完全灵活的编程解决方案,我还没有想出一个想法)。在此之前,我为自定义 XML 输入实现了基于 shell 脚本的转换器(hag2epub 工具 ) - 如果您感兴趣,我可能会将它们移植到 XHTML 输入(使用 EPUB 元数据的配置文件或从目录最顶层的 index.html 获取元数据(如果存在))。

I just started to implement such a tool in Java (OpenJDK compatible): html2epub. In order to get rid of manually editing the config file, I'll probably start a separate tool to generate the config file from any given directory (however, it would still be necessary to determine the order of the XHTMLs in the EPUB - for non-programmatical use, developing a GUI helper tool could be considered, for a fully flexible programmatical solution, I haven't come up with an idea yet). Before that, I implemented shell script based converters for custom XML input (hag2epub tools) - in case you're interested, I would probably port them to XHTML input (with a config file for the EPUB metadata or obtaining metadata from the topmost index.html of a directory, if existing).

空名 2024-09-20 23:45:54

我之前也遇到过同样的问题,因为我想在 iPad 上离线阅读一些网页内容。我不知道,我也不懂电脑。有 calibre 或 stanza blabla...

但对我来说它们只是格式转换器,我需要一个 ePub 图书创建器,它允许我将许多所需的文档组合在一起阅读。然后我找到了一个书呆子html到ePub转换器,我保存了html页面来自网络,然后用它进行转换。现在对我来说这是一个非常好的工具。

I have the same issue previously, necause I want to read some webpage content offline on my iPad. I have no idea and I am not a computer savvy. There are calibre or stanza blabla....

But for me they are just formats converters and I need a ePub book creator which will allows me to combine many desired documents together to read. Then I found a bookish html to ePub converter, I save the html page from web then convert with it. It's a quite good tool for me now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文