0

I have a Rails 3.2 app using Bootstrap and Wicked_pdf. I'm trying to page break the pdf after each @costproject.

Gems:

gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'

I read this post: Rails WickedPDF Page Breaks

So, I tried it.

This is in my CSS:

.page-break {
  display:block;
  clear:both;
  page-break-after:always;
}

And this is in projects.pdf.erb:

<% @costprojects.each do |costproject| %>
    <div class="page-break"></div>
    <div id="pdfbody">
      <table class="table table-striped">
...

But, the page breaks don't happen.

Thanks for the help!

Community
  • 1
  • 1
Reddirt
  • 5,913
  • 9
  • 48
  • 126
  • Try to open your HTML page with these CSS rules in Google Chrome and open it in Print Preview (File -> Print...). Do you see page breaks in this case? – Maxim Mar 11 '15 at 16:21
  • I corrected my post. It's not a view (HTML), it's a pdf.erb – Reddirt Mar 11 '15 at 16:51
  • Yes, I understand it. Save it to HTML (because you generate HTML markup) and open in Google Chrome as I described above. – Maxim Mar 11 '15 at 16:54
  • Not sure how to do that. I tried the url `...costprojects/viewprojects.html`, but I get missing template. – Reddirt Mar 11 '15 at 19:04
  • Just temporary rename `projects.pdf.erb` to `projects.html.erb` and open it in browser use URL correspond to this controller action (you can check URL path use `rake routes` command) i.e. `http://localhost:3000/projects`. The main target is try to detect side of problem i.e. is this CSS problem or WickedPDF generator? – Maxim Mar 11 '15 at 19:42
  • There is no page break when viewing as html. – Reddirt Mar 11 '15 at 22:51
  • So, seems like problem with CSS. Open [Chrome Developer Tools](https://developer.chrome.com/devtools/docs/dom-and-styles#dom) and check that your `.page-break` CSS rule is applied to `div` elements. – Maxim Mar 11 '15 at 22:56
  • "There is no page break when viewing as html." - you are viewing it in Chrome **Print** Preview. Right? – Maxim Mar 12 '15 at 00:52
  • The page breaks work if I change it to html and use Chrome print preview. – Reddirt Mar 12 '15 at 20:04
  • ok, this is mean that the problem on the WickedPDF side. Now, need to check how you installed `wkhtmltopdf` binary. Requires your Gemfile. – Maxim Mar 12 '15 at 22:21
  • I updated my questions to show the gems used. – Reddirt Mar 18 '15 at 14:39
  • ok, I am using the same gems and they make page breaks. The `wkhtmltopdf` gem has Qt Webkit patches. But which versions are you using? Try to specify these versions: `wkhtmltopdf-binary:0.9.9.1`, `wicked_pdf:0.9.6' – Maxim Mar 18 '15 at 15:22
  • Installing wicked_pdf 0.9.6 (was 0.11.0) Using will_paginate 3.0.4 Installing wkhtmltopdf-binary 0.9.9.1 (was 0.9.9.3) Still no pagination! – Reddirt Mar 25 '15 at 20:13

1 Answers1

0

I tried a lot of different approaches.

Placing this code in the viewprojects.pdf.erb worked for me:

    <p style='page-break-after:always;'></p>
Reddirt
  • 5,913
  • 9
  • 48
  • 126