knitr/Rmd: page break after n lines/n distance

邮差的信 提交于 2019-12-03 01:58:29

Programatically. Create an HTML div. Set this div's width and height to a fixed amount and the overflow to scroll.

<div style="height:1000px; width: 500px; overflow-y: scroll;">
    ...
</div>

Process your markdown into HTML elements. I have 5 h1 tags that are 300px tall each.

<h1 style="height:300px;">First</h1>
<h1 style="height:300px;">Second</h1>
<h1 style="height:300px;">Third</h1>
<h1 style="height:300px;">Fourth</h1>
<h1 style="height:300px;">Fifth</h1>

These 5 h1 wont all fit on the same page. The page is only 1,000 pixels tall. Only 3 h1 tags will fit on this page. We'll need to insert a pagebreak after the third element.

Incrementally add each new item into the DOM. After inserting each item check to see if the browser's scroll bar is present. If it is, then we know that the item we just inserted was too big for this page; remove the item and insert a page break.

Before:

### First
### Second
### Third
### Fourth
### Fifth

After:

### First
### Second
### Third
------
### Fourth
### Fifth

This would work for any element and you wouldn't have to worry about an item's height. Because, if the item you just inserted made the HTML div scroll then we need a page break. Images, videos, h1, h2, p, custom/dynamic css, anything.

UPDATE

You could also calculate the height of each div element. http://api.jquery.com/height/ That way recalculating a 54 page document would be much easier.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!