2

Rails 3アプリケーションにエビの宝石をインストールしました。

フッターが各ページで機能しないのはなぜでしょうか。

最後のページの最後でのみ機能します。

これが私のコードです:

(私はエビに非常に慣れていません)

だから我慢してください。

どんな回避策も非常に高く評価されます

require 'prawn'
require 'rubygems'
require 'date'

pdf = Prawn::Document.new(:page_layout => :landscape,:skip_page_creation => true,:margin => [5,5,5,5]) do
    start_new_page
    pdf.font "Helvetica"    
end


pdf.text "Project Procurement Management Plan (PPMP)", :size=> 12, :spacing => 4, :align=> :center

pdf.move_down 400


pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"
pdf.text "Text"


# This is the footer code

pdf.bounding_box([pdf.bounds.right - 59, pdf.bounds.bottom - -20], :width => 60, :height => 20) do

  pagecount = pdf.page_count
  pdf.text "Page #{pagecount}"
end

解決しました!

以下でわかったことを見てください。

4

5 に答える 5

3

こんにちは私はすでに答えを見つけました。

こんなお悩みをお持ちの方へ

pdf.repeat :all do

  pdf.bounding_box [pdf.bounds.left, pdf.bounds.bottom + 25], :width  => pdf.bounds.width do
  pdf.stroke_horizontal_rule
  pdf.move_down(5)
  pdf.text "#{current_user.first_name}", :size => 10
end
end
于 2013-03-04T08:24:27.397 に答える
3

左/中央/右 -各ページの下部マージンの外側のコンテンツを生成しようとしました。
number_pagesブロックを 1 つだけ生成します。
いくつかのアプローチ:

を。とを使用repeattext_boxます。ここで重要なことはtext_box、明示的な高さを境界の外に表示する必要があるということです。

repeat :all do
  text_box "title: some text", at: [bounds.left, -20], height: 20
  text_box "printet at #{Time.now}", height: 20, width: 200, align: :right, at: [bounds.right-200,-20]
end

b. number_pagesPDF 生成の最後に数回呼び出すことができます。ページ番号テンプレートを提供する必要はありません。number_pages境界外のテキストを生成できます (内部で高さを設定します):

number_pages "title: some text", at: [bounds.left, -20]
number_pages "page <page> of <total>", at: [300,-20]
number_pages "printed at #{Time.now}", at: [bounds.right-200,-20], width: 200, align: :right
于 2014-06-28T05:54:06.257 に答える
1

pdf.number_pages水平線の区切りを表示する必要がない場合、これは最小限の解決策ですpdf.repeat(:all)

options = {
        :at => [pdf.bounds.right - 150, 0],
        :width => 150,
        :align => :right,
        :start_count_at => 1
}
pdf.number_pages "Page <page> of <total>", options
于 2013-03-13T10:28:09.407 に答える
1

これを試して

pdf.page_count.times do |i|
  pdf.go_to_page(i+1)
  pdf.bounding_box([0, pdf.bounds.bottom + 25], :width => pdf.bounds.width) {
    pdf.line_width(3)
    pdf.stroke_horizontal_rule
    pdf.move_down(5)
    pdf.draw_text "Page #{i+1}" ,:at => [240, pdf.bounds.height - 20]
    pdf.draw_text "#{Time.now.strftime("%B %d, %Y")}" ,:at => [455, pdf.bounds.height - 20]
  }
end
于 2016-03-30T07:35:51.787 に答える
0

これを試して:

pdf.repeat(:all) do
  pdf.stroke do
    pdf.horizontal_line 0, 540, :at => 10
  end

  pdf.number_pages "(<page>/<total>)", :size => 9, :at => [500, 0]
end

だから私が理解していることは、これを使用しnumber_pagesて作成する必要があるということです。基本的に私がしていることはきれいで正しくありませんでした.ヘッダーとフッターを作成するために私はすべてを使用しますnumber_pagesが、自由に位置を割り当てることができるので機能します.それは簡単です。

于 2013-03-04T08:27:58.183 に答える