简体   繁体   English

Wicked_PDF for Rails中更好的分页符

[英]Better Page Breaks in Wicked_PDF for Rails

I was able to use the technique described here to get page breaks at certain points I wanted. 我能够使用此处描述的技术在所需的某些位置获得分页符。 However, I have a two column layout as follows: 但是,我有两列的布局,如下所示:

    <div class='book-main-image'><img src="<%= page[:image] %>" /></div>

    <div class='book-headline-holder'>
      <h1><%= page[:title] %></h1>
    </div>

    <div class='book-sidebar book-main-section'>
      <div class='book-sidebar-section'>
        <h4>Location</h4>
        <div class='sidebar-text'><%= page[:location] %></div>

        <h4>Client</h4>
        <div class='sidebar-text'><%= page[:client] %></div>
      </div>
    </div>

    <div class='book-main-content book-main-section'>
      <div class='book-body'><%= page[:body].html_safe %></div>
    </div>

Which is styled like this: 样式如下:

  .book-main-section    { display: inline-block; vertical-align: top; }
  .book-sidebar         { width: 20%; margin-left: 3%; margin-top: 10px; }
  .book-main-content    { width: 70%; margin-left: 2%; }

This is fine most of the time, but if the book-body div + the height of book-main-image and book-headline-holder are longer than one page, both book-main-section divs are shifted to the next page, leaving an image and headline on one page with a huge gap and the rest of the content on the next page. 多数情况下,这很好,但是如果book-body div + book-body本主book-main-image高度和book-headline-holder高度超过一页,则book-main-section div都将移至下一页,在一页上留下图片和标题,差距很大,而其余内容在下一页上。

I tried to start introducing some javascript (using an external link to jQuery in the page) to break up the page content into separate divs based on the height of them, but I could never get the Javascript to execute (seems to totally ignore it). 我试图开始引入一些javascript(使用页面中jQuery的外部链接),以根据页面的高度将页面内容分成单独的div,但是我无法执行Javascript(似乎完全忽略了它) 。 Is there any other way to avoid this, or to get the javascript working? 还有其他方法可以避免这种情况,或者使javascript工作吗?

I figured out that the way to get it fixed was remove the monolithic div holding the page[:body].html_safe . 我发现解决该问题的方法是删除包含page[:body].html_safe的单片div。 That data contained paragraph tags, so I instead styled them and removed <div class='book-body'> and <div class='book-main-content book-main-section'> , and styled the paragraphs like so: 该数据包含段落标签,因此我给它们加了样式,并删除了<div class='book-body'><div class='book-main-content book-main-section'> ,并为段落设置了样式:

p { float:right; width: 70%; margin-left: 2%; margin-right: 35px; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM