sathyajith
sathyajith

Reputation: 46

How to prevent blank page getting added at the end of pdf report due to page break

I am printing the pdf report where i will be looping each student and i am applying page-break after each student

And my applied page break code is as below

<style type="text/css" >
  .page-break { display:block; clear:both; page-break-after: always;}
</style>

And my view is

<% @students.each do |student| %>
<%= student.first_name %>
  <div class="page-break"></div>
<% end %>

Problem is i am getting empty page at last in pdf report, i am using wicked-pdf gem for pdf generation i think problem is with page-break css can anyone help me

Upvotes: 0

Views: 6551

Answers (2)

Marlon Bernal
Marlon Bernal

Reputation: 577

Just dont add the class that gives page break on your last loop, that way "page-break-after: always" wont take effect

Upvotes: 0

Tamer Shlash
Tamer Shlash

Reputation: 9523

Quick and dirty solution, but should work fine:

<% @students.each do |student| %>
  <%= student.first_name %>
  <% if student.id != @students.last.id %>
    <div class="page-break"></div>
  <% end %>
<% end %>

Also if you can show us the html container of the each loop, we can give a better answer depending on this one.

Upvotes: 2

Related Questions