Search code examples
ruby-on-railspdf-generationprawnprawnto

Prawn: conditional text for multiple page


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?


Solution

  • 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