Reputation: 3894
I can generate a pdf in prawn. I need to show some text if the generated pdf is multipage. For example, if generated pdf is more than one page, then I have to show "continued ..." in all pages except last page. And if the pdf is just one page then I don't want to show it at all. Is it possible?
Upvotes: 2
Views: 1296
Reputation: 1779
Prawn's repeat
can print text on any selection of pages. The first argument takes a named key, an array, a range or a lambda. In your case, you can define all pages except the last as a range.
page_range = (1..(pdf.page_count - 1))
pdf.repeat(page_range) do
pdf.draw_text "continued ..."
end
Upvotes: 1
Reputation: 1351
I think it should work:
if (num_pages = pdf.page_count) > 1
pdf.repeat(lambda { |pg| pg < num_pages }) do
pdf.draw_text "continued...", :at => [250, 20]
end
end
Upvotes: 3