Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5939013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:45:59+00:00 2026-05-22T15:45:59+00:00

I’m building a PDF export function in Rails and Prawn where I want to

  • 0

I’m building a PDF export function in Rails and Prawn where I want to export a number of “Companies” in one single PDF. A company usually flows over 2-3 pages. Right now when exporting a single Company this works with a pdf.repeat(:all). I want the logo to change in the header based on the Company though. A simple code example is:

@companies.each do |c|
 pdf.repeat(:all) do
  pdf.image company.logo.url(:thumb), :at => [0,520]
 end
end

Is there a way of doing this? I have looked at related topics, like header and footer in Prawn PDF but it won’t help me since I can’t see what Company belongs to which page after it’s generated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:45:59+00:00Added an answer on May 22, 2026 at 3:45 pm

    The awesome self-documenting manual (http://cloud.github.com/downloads/sandal/prawn/manual.pdf) contains this code (page 105), which may be of help:

    repeat(lambda { |pg| pg % 3 == 0 }) do
      draw_text "Every third page", :at => [250, 20]
    end
    repeat(:all, :dynamic => true) do
      draw_text page_number, :at => [500, 0]
    end
    

    Either lambda or the dynamic should do the trick for you, provided that you know what company starts at what page.

    In case you do not know about the number of pages per company, make a pdf for each of them and merge them. Manual, page 109:

    filename = "#{Prawn::BASEDIR}/data/pdfs/multipage_template.pdf"
    Prawn::Example.generate("full_template.pdf", :template => filename) do
      go_to_page(page_count)
      start_new_page
      text "Previous pages and content imported.", :align => :center
      text "This page and content is brand new.", :align => :center
    end
    

    In the worst case you will end up with merging two at a time.

    You might also check if pdf.number_pages with :filter option works with images (if you have not tried it yet). I have absolutely no idea if it works and I have no chance to check it right now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.