如何在Rails中创建表示一个数据表(包括每个新页面上的列标题)的多页PDF?我已经看过很多使用wicked-pdf、pdfkit和prawn的例子,但是还没有看到任何专门针对溢出到后续页面以及在每个新页面中重复标题的需要的东西。谢谢你的帮助。
发布于 2012-06-15 12:00:29
我使用Prawn生成我的pdf,可以得到你想要的效果,如下所示:
def render_photo_table(pdf)
ps = self.photos.map do |photo|
[photo.filename, photo.image_height, photo.image_width]
end
ps.insert(0, ['Filename', 'Height', 'Width'])
pdf.table(ps) do |table|
table.header = true
end
end这将在每页的顶部产生一个标题(设置在数组位置0中)。
发布于 2012-11-15 17:19:27
在这方面也遇到了麻烦,但找到了一个相当简单的方法(在经历了许多令人头疼的事情之后)。
在项目上方放置一个浮动的placemark div,这样就可以获得起始坐标(我称之为ID item_top)。
然后使用'unbreakable‘类呈现带有顶级数据div的页面。
还包括一个强制分页符的类:
.page-breaker {
display: block;
clear: both;
page-break-after: always;
}然后在渲染之后
<script>
// Very top of items
var current_top = $('#item_top').offset().top;
// Check distance from top of page to bottom of item
// If greater than page size put page break and headers before
// Reset top of page to top of item.
$('.unbreakable_section').each(function(index) {
var item_bottom = $(this).offset().top + $(this).outerHeight(true);
if ((item_bottom - current_top) > 1250) {
$(this).before("<div class='page-breaker'></div>");
$(this).before("Headings Div here");
current_top = $(this).offset().top - 48; // item - header height
}
});
</script>这将测量自上一分页符以来的垂直间距,如果间距超过页面高度,则开始新页并在其上方放置页眉。(1250是近似值,对我来说已经足够近了-我在页面上也有一个页脚,所以高度可能会根据你的设置而变化)。
在100页的文档上进行了测试,结果与预期一致。
发布于 2012-05-25 23:22:25
为此,我们编写了内部jquery代码。
如果你有像这样的页面:
<div class="mypage">
<div class="mypage_footer"></div>
</div>而在外面,你有:
<div class="mybox">
<table><tbody><tr><td>omg</td></tr></tbody></table>
</div>
<div class="mybox">
<table><tbody><tr><td>lol</td></tr></tbody></table>
</div>假设您有一个固定的页面高度(最好是A4大小),您可以使用jquery:
https://stackoverflow.com/questions/10712315
复制相似问题