如何将HTML文档分解为电子书的页面? [英] How to break up HTML documents into pages for ebook?

查看:112
本文介绍了如何将HTML文档分解为电子书的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于iPhone电子书应用程序,我需要将任意长的HTML文档分割成适合一个屏幕的页面。如果我简单地使用UIWebView,最底部的行往往只显示一部分:其余部分消失在视图的边缘。

所以我想我会需要知道UIWebView将显示多少完整的行(或字符),并给出源HTML,然后为其提供恰到好处的数据量。这可能涉及很多计算,用户还需要能够更改字体和大小。



我不知道这是否可能,尽管像Stanza采取HTML(epub)文件并且很好地分页。我看了JavaScript很长一段时间,这是一个值得期待的选择吗?



任何建议都非常感谢!



update

所以我打了一个可能的解决方案,使用JavaScript来注释DOM树的大小和位置的每个元素。然后应该可以重构树(使用内置的XSLT或JavaScript),并将其切割成完全适合屏幕的页面。



这里剩下的问题是这总是打破段落边界的页面,因为没有比P元素更低的层次访问文本。也许这可以通过将文本解析为单词,将每个单词封装在SPAN标签中,重复上面的测量过程,然后仅显示适合屏幕的SPAN元素,将剩余的单元插入到下一个的前面页面。



这听起来相当复杂。我在说什么?有没有更简单的方法?

.w3.org / TR / css3-page /rel =noreferrer> http://www.w3.org/TR/css3-page/
CSS3也支持多列布局(google for css3-multicol。我没有足够的Karma包含第二个链接: - )

做一个页面的布局,然后使用溢出的DIV:隐藏文本部分。接下来的事情就是在上面覆盖一个透明的项目,这将根据一些导航控件(或手势)以编程方式向上或向下滚动DIV PAGE_HEIGHT像素的内部内容。


For an iPhone ebook application I need to break arbitrarily long HTML documents up into pages which fit exactly on one screen. If I simply use UIWebView for this, the bottom-most lines tend to get displayed only partly: the rest disappears off the edge of the view.

So I assume I would need to know how many complete lines (or characters) would be displayed by the UIWebView, given the source HTML, and then feed it exactly the right amount of data. This probably involves lots of calculation, and the user also needs to be able to change fonts and sizes.

I have no idea if this is even possible, although apps like Stanza take HTML (epub) files and paginate them nicely. It's a long time since I looked at JavaScript, would that be an option worth looking at?

Any suggestions very much appreciated!

update

So I've hit upon a possible solution, using JavaScript to annotate the DOM-tree with sizes and positions of each element. It should then be possible to restructure the tree (using built-in XSLT or JavaScript), cutting it up in pages which fit exactly on the screen.

Remaining problem here is that this always breaks the page on paragraph-boundaries, since there is no access to the text at a lower level than the P-element. Perhaps this can be remedied by parsing the text into words, encapsulating each word in a SPAN-tag, repeating the measurement procedure above, and then only displaying the SPAN elements that fit onto the screen, inserting the remaining ones at the front of the next page.

All this sounds rather complicated. Am I talking any sense? Is there a simpler way?

解决方案

You should look at the PagedMedia CSS module: http://www.w3.org/TR/css3-page/ CSS3 also support multicolumn layouts (google for "css3-multicol". I don't have enough Karma to include a second link here :-)

About your update: how about doing the layout of one single page, then use a DIV with overflow:hidden for the text part. Next thing would be to overlay a transparent item on top of that, that would programmatically scroll the inner content of the DIV PAGE_HEIGHT pixels up or down according to some navigation controls (or gestures).

这篇关于如何将HTML文档分解为电子书的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆