#31 new
Kendall Gifford

Pass optional "current page number" parameter to LazyBoundingBox's block when drawn.

Reported by Kendall Gifford | December 2nd, 2009 @ 08:18 PM

Header/Footer Feature Suggestion/Request:

When drawing a Prawn::Document::LazyBoundingBox instance for a given page, pass an optional parameter to the #draw method that, in turn, can be passed to the internal @action block as a parameter:

Prawn::Document::LazyBoundingBox (prawn-layout-0.3.2/lib/prawn/layout/page.rb around line 105)


def draw
    ...
    @action.call
    ...
end

instead becomes:

def draw(current_page_index = 0)
    ...
    @action.call(current_page_index + 1)
    ...
end

Then in Prawn::Document::Internals (prawn-core-0.6.3/lib/prawn/document/internals.rb around line 108)


def finalize_all_page_contents
  page_count.times do |i|
    ...
    @header.draw if defined?(@header) and @header
    @footer.draw if defined?(@footer) and @footer
    ...
  end
end

instead becomes:

def finalize_all_page_contents
  page_count.times do |i|
    ...
    @header.draw(i) if defined?(@header) and @header
    @footer.draw(i) if defined?(@footer) and @footer
    ...
  end
end

The upshot, of course, is to be able to provide a "current page number" to the "footer block" so you create #number_pages like footers (or headers) but more powerful:


pdf.footer [x, y] do |current_page_number|
  pdf.line_width = 1
  pdf.stroke_horizontal_rule
  pdf.text "Page #{current_page_number} of #{pdf.page_count}", :align => :center
  #... fancy footer graphics ...
end

This is just a suggestion (not a bug). The hack (pseudo-patch) provided has NOT been through any testing. It just seems to work fine for what I'm doing. I'm running prawn 0.6.3 (and prawn-layout 0.3.2) with ruby 1.8.6 on an ubuntu box.

No comments found

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages