如何为iPad / iPhone应用程序实现ePub阅读器

时间:2023-01-12 18:04:57

I want to implement an ePub reader for the iOS platform. Please suggest any open source code for book flipping animation, bookmarks, font-size customization and single page view (without scroll bars).

我想为iOS平台实现一个ePub阅读器。请为推荐动画,书签,字体大小自定义和单页视图(无滚动条)推荐任何开源代码。

4 个解决方案

#1


4  

As the previous article points out, there is no API that given an ePub will just display it -- you need to do some work:

正如前一篇文章所指出的那样,没有API可以让ePub显示它 - 你需要做一些工作:

  1. Unzip the ePub
  2. 解压缩ePub

  3. Read the manifest file and metadata file to find the xhtml documents to display
  4. 读取清单文件和元数据文件以查找要显示的xhtml文档

  5. Load the xhtml documents into a UIWebView using a file:/// URL to the unzipped document
  6. 使用文件:///解压缩文档的URL将xhtml文档加载到UIWebView中

If you want to ensure that the documents don't hit the network you'll need to implement a custom NSURLProtocol and serve the bytes for the files yourself as file:/// allows cross domain access.

如果要确保文档不会到达网络,则需要实现自定义NSURLProtocol并自行为文件提供字节,因为file:///允许跨域访问。

That will display the content just fine, but the "hard" part is moving between the documents (which usually represent a whole chapter). This is the work that iBooks and other apps do for you.

这将显示内容很好,但“硬”部分在文档之间移动(通常代表整个章节)。这是iBooks和其他应用程序为您所做的工作。

NOTE: For the UIWebView to display the content correctly, you have to ensure that the file has a .xhtml extension when using file:/// urls. If you implement your own URL protocol handler, you need to make sure the protocol handler returns the correct xml content type for xhtml, namely:

注意:要使UIWebView正确显示内容,您必须确保在使用file:/// urls时该文件具有.xhtml扩展名。如果您实现自己的URL协议处理程序,则需要确保协议处理程序为xhtml返回正确的xml内容类型,即:

application/xhtml+xml

#2


4  

Use the ePub packaging format and an open-source reader for reference:

使用ePub打包格式和开源阅读器作为参考:

#3


1  

Try this steps :

Source code: AePubReader

源代码:AePubReader


Implementation:

Step 1: Create a view with a UIWebView

第1步:使用UIWebView创建视图

Step 2: Download an EPUB file and import into your project

第2步:下载EPUB文件并导入到您的项目中

Step 3: Unzip EPUB file to a subdirectory in your app's documents folder.

第3步:将EPUB文件解压缩到应用程序文档文件夹中的子目录。

Step 4: Parse the XML file from directory META-INF/container.xml. If this file directory doesn't exist means, your EPUB file is invalid.

步骤4:从目录META-INF / container.xml解析XML文件。如果此文件目录不存在,则表示您的EPUB文件无效。

Step 5: In this XML, find the first "rootfile" with media-type application/oebps-package+xml. This is the OPF file for the book.

步骤5:在此XML中,找到第一个带有media-type application / oebps-package + xml的“rootfile”。这是本书的OPF文件。

Step 6: Parse the OPF file (also XML)

第6步:解析OPF文件(也是XML)

Step 7: Now you need to know what the first chapter of the book is.

第7步:现在您需要知道本书的第一章是什么。

  • Each in the element has an id and an href. Store these in an NSDictionary where the key is the id and the object is the href.
  • 元素中的每个元素都有一个id和一个href。将它们存储在NSDictionary中,其中键是id,对象是href。

  • Look at the first in the . It has an idref attribute which corresponds to one of the ids in (Step 7a). Look up that id in the NSDictionary and you'll get an href.
  • 看看第一个。它具有idref属性,该属性对应于(步骤7a)中的一个id。在NSDictionary中查找该ID,您将获得一个href。

  • this is the the file of the first chapter to show the user. Work out what the full path is (hint: it's wherever you unzipped the zip file to in (Step 3), plus the base NSDictionary of the OPF file in (Step 6).
  • 这是显示用户的第一章的文件。弄清楚完整路径是什么(提示:它是将zip文件解压缩到的位置(步骤3),以及OPF文件的基本NSDictionary(步骤6)。

Step 8: Create an NSURL using fileURLWithPath:, where the path is the full path from (Step 7c). Load this request using the UIWebView you created in (Step 1).

步骤8:使用fileURLWithPath:创建NSURL,其中路径是来自的完整路径(步骤7c)。使用您在(步骤1)中创建的UIWebView加载此请求。

Step 9: You'll need to implement forward / backward buttons or swipes or something so that users can move from one chapter to another. Use the to work out which file to show next. Then the XML are in the order they should appear to the reader.

步骤9:您需要实现前进/后退按钮或滑动或其他内容,以便用户可以从一个章节移动到另一个章节。使用它来确定下一个要显示的文件。然后,XML按照它们应该向读者显示的顺序排列。

These step got referred from this link

这个步骤来自这个链接

#4


1  

Use UITextView with pageview controller . (Specify your doubts , if any)

将UITextView与pageview控制器一起使用。 (指出你的疑惑,如果有的话)

#1


4  

As the previous article points out, there is no API that given an ePub will just display it -- you need to do some work:

正如前一篇文章所指出的那样,没有API可以让ePub显示它 - 你需要做一些工作:

  1. Unzip the ePub
  2. 解压缩ePub

  3. Read the manifest file and metadata file to find the xhtml documents to display
  4. 读取清单文件和元数据文件以查找要显示的xhtml文档

  5. Load the xhtml documents into a UIWebView using a file:/// URL to the unzipped document
  6. 使用文件:///解压缩文档的URL将xhtml文档加载到UIWebView中

If you want to ensure that the documents don't hit the network you'll need to implement a custom NSURLProtocol and serve the bytes for the files yourself as file:/// allows cross domain access.

如果要确保文档不会到达网络,则需要实现自定义NSURLProtocol并自行为文件提供字节,因为file:///允许跨域访问。

That will display the content just fine, but the "hard" part is moving between the documents (which usually represent a whole chapter). This is the work that iBooks and other apps do for you.

这将显示内容很好,但“硬”部分在文档之间移动(通常代表整个章节)。这是iBooks和其他应用程序为您所做的工作。

NOTE: For the UIWebView to display the content correctly, you have to ensure that the file has a .xhtml extension when using file:/// urls. If you implement your own URL protocol handler, you need to make sure the protocol handler returns the correct xml content type for xhtml, namely:

注意:要使UIWebView正确显示内容,您必须确保在使用file:/// urls时该文件具有.xhtml扩展名。如果您实现自己的URL协议处理程序,则需要确保协议处理程序为xhtml返回正确的xml内容类型,即:

application/xhtml+xml

#2


4  

Use the ePub packaging format and an open-source reader for reference:

使用ePub打包格式和开源阅读器作为参考:

#3


1  

Try this steps :

Source code: AePubReader

源代码:AePubReader


Implementation:

Step 1: Create a view with a UIWebView

第1步:使用UIWebView创建视图

Step 2: Download an EPUB file and import into your project

第2步:下载EPUB文件并导入到您的项目中

Step 3: Unzip EPUB file to a subdirectory in your app's documents folder.

第3步:将EPUB文件解压缩到应用程序文档文件夹中的子目录。

Step 4: Parse the XML file from directory META-INF/container.xml. If this file directory doesn't exist means, your EPUB file is invalid.

步骤4:从目录META-INF / container.xml解析XML文件。如果此文件目录不存在,则表示您的EPUB文件无效。

Step 5: In this XML, find the first "rootfile" with media-type application/oebps-package+xml. This is the OPF file for the book.

步骤5:在此XML中,找到第一个带有media-type application / oebps-package + xml的“rootfile”。这是本书的OPF文件。

Step 6: Parse the OPF file (also XML)

第6步:解析OPF文件(也是XML)

Step 7: Now you need to know what the first chapter of the book is.

第7步:现在您需要知道本书的第一章是什么。

  • Each in the element has an id and an href. Store these in an NSDictionary where the key is the id and the object is the href.
  • 元素中的每个元素都有一个id和一个href。将它们存储在NSDictionary中,其中键是id,对象是href。

  • Look at the first in the . It has an idref attribute which corresponds to one of the ids in (Step 7a). Look up that id in the NSDictionary and you'll get an href.
  • 看看第一个。它具有idref属性,该属性对应于(步骤7a)中的一个id。在NSDictionary中查找该ID,您将获得一个href。

  • this is the the file of the first chapter to show the user. Work out what the full path is (hint: it's wherever you unzipped the zip file to in (Step 3), plus the base NSDictionary of the OPF file in (Step 6).
  • 这是显示用户的第一章的文件。弄清楚完整路径是什么(提示:它是将zip文件解压缩到的位置(步骤3),以及OPF文件的基本NSDictionary(步骤6)。

Step 8: Create an NSURL using fileURLWithPath:, where the path is the full path from (Step 7c). Load this request using the UIWebView you created in (Step 1).

步骤8:使用fileURLWithPath:创建NSURL,其中路径是来自的完整路径(步骤7c)。使用您在(步骤1)中创建的UIWebView加载此请求。

Step 9: You'll need to implement forward / backward buttons or swipes or something so that users can move from one chapter to another. Use the to work out which file to show next. Then the XML are in the order they should appear to the reader.

步骤9:您需要实现前进/后退按钮或滑动或其他内容,以便用户可以从一个章节移动到另一个章节。使用它来确定下一个要显示的文件。然后,XML按照它们应该向读者显示的顺序排列。

These step got referred from this link

这个步骤来自这个链接

#4


1  

Use UITextView with pageview controller . (Specify your doubts , if any)

将UITextView与pageview控制器一起使用。 (指出你的疑惑,如果有的话)