WicketPDF渲染表未正确对齐,页脚位于最后一页 [英] WicketPDF rendering table not aligned properly and footer place at last page

查看:85
本文介绍了WicketPDF渲染表未正确对齐,页脚位于最后一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从html页面生成pdf报告,我分别用页眉和页脚创建了布局,我在最后一页只需要第一页和页脚的标题,我尝试了一些
脚本但是它不起作用,以及如何避免表行内的分页,我需要每个页面的边框而不会破坏表格行如图所示。

I am generating pdf report from html page, I created the layout with header and footer separately , I need header only for first page and footer at last page, I tried some scripts for that but it is not working, and how to avoid page break inside table row and I need border for each page without breaking table row is breaking like as shown in an image.

respond_to do |format|
  format.html
  format.pdf {
     render :pdf => "Report",
            :template => 'layouts/pdf_layout.pdf.erb',
            :layout => 'pdf_layout.pdf.erb',
            :margin => {:bottom => 35},
            :page_size => 'A4',
            :header => {:content => render_to_string({:template => 'layouts/header.pdf.erb'})},
            :footer => {:content => render_to_string({:template => 'layouts/footer.pdf.erb'})}
  }
end

任何其他建议

提前致谢

推荐答案

通常可以通过一些css规则来缓解分页问题,​​这些规则很好:

Page break issues can usually be mitigated with a few css rules, well placed:

div.alwaysbreak { page-break-before: always; }
div.nobreak:before { clear:both; }
div.nobreak{ page-break-inside: avoid;
  /* http://code.google.com/p/wkhtmltopdf/issues/detail?id=9#c21 */
}

因此,其中一个有趣的事情是这些规则对表格元素不起作用,所以如果你有一张表并希望防止细胞被分成两半,你可以用< div> 包装每个表格行。

So, one of the interesting things is that these rules don't work on table elements, so if you have a table and want to prevent cells from being split in half, you can wrap each table row with a <div>.

这当然不干净&语义,但你可以这样做:

This is certainly not clean & semantic, but you can do it like this:

<table>
  <thead>
    <div class='nobreak'>
      <tr>
        <th>One</th><th>Two</th>
      </tr>
    </div>
  </thead>
  <tbody>
    <div class = 'nobreak'>
      <tr>
        <td>Uno</td><td>Dos</td>
      </tr>
    </div>
  </tbody>
</table>

为了让您的页面边框完美排列,您可能需要将其设置为使用带有 .awaysbreak 的CSS固定高度,然后使用一些javascript来计算表的高度,并根据高度将其分成块。

To get your page borders to line up perfectly, you are probably going to have to set it to a fixed height with CSS with an .awaysbreak, then have some javascript that computes the height of the table and breaks it into chunks based on height.

也许只是因为你的表到目前为止这么简单,但看起来它可能是一个很好的候选人尝试使用。你可以更好地控制这些类型的布局问题。

Maybe it's just because your table so far is so simple, but this looks like it might be a good candidate to try using prawn with. You'll have better control of those types of layout issues.

它有一个railscast 这里

There's a railscast for it here.

这篇关于WicketPDF渲染表未正确对齐,页脚位于最后一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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