Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在rails 3.2中,每个页面的页脚都不起作用(Prawn PDF)_Ruby On Rails_Pdf_Pdf Generation_Prawn_Prawnto - Fatal编程技术网

Ruby on rails 在rails 3.2中,每个页面的页脚都不起作用(Prawn PDF)

Ruby on rails 在rails 3.2中,每个页面的页脚都不起作用(Prawn PDF),ruby-on-rails,pdf,pdf-generation,prawn,prawnto,Ruby On Rails,Pdf,Pdf Generation,Prawn,Prawnto,我在rails 3应用程序中安装了prawn gem 我想知道为什么我的页脚在每一页都不起作用 它只在最后一页的末尾起作用 这是我的密码: (我对对虾很陌生) 所以请容忍我 我们将非常感谢任何解决办法 require 'prawn' require 'rubygems' require 'date' pdf = Prawn::Document.new(:page_layout => :landscape,:skip_page_creation => true,:margin =&g

我在rails 3应用程序中安装了prawn gem

我想知道为什么我的页脚在每一页都不起作用

它只在最后一页的末尾起作用

这是我的密码:

(我对对虾很陌生)

所以请容忍我

我们将非常感谢任何解决办法

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
解决了


看看我在下面发现了什么。

嗨,我已经找到了答案

对于那些有这样问题的人:

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
试试这个:

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
pdf.重复(:all)do
pdf.do
水平线0540:at=>10
结束
pdf.number_pages“(/)”,:size=>9,:at=>[500,0]
结束

所以我的理解是,我需要使用这个
number\u pages
来创建它,基本上我所做的并不干净和正确,因为对于创建页眉和页脚,我使用的都是
number\u pages
,但我使用它,因为我们可以自由地分配它的位置,而且很简单。

如果您不需要显示水平线分隔符,那么这是一个最小的解决方案,因为即使没有
pdf,
pdf.number\u页面
也可以工作。重复(:all)

选项={
:at=>[pdf.bounds.right-150,0],
:宽度=>150,
:align=>:右,
:开始计数时间=>1
}
pdf.number_页面“第页,共页”,选项

我试图在每一页的底部边距之外生成左/中/右内容。
number\u pages
只生成一个块。
有几只蟑螂:

a。使用
重复
文本框
。这里重要的一点是,
文本框
需要在边界外显示一个eplicit高度:

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。在PDF生成结束时,您可以多次调用
number\u pages
。您不必提供页码模板<代码>页数可以在边界外生成文本(它在内部设置高度):

number_页面“标题:一些文本”,位于:[bounds.left,-20]
“第页,共页”,页数:[300,-20]
“在{Time.now}打印”的页数,在:[bounds.right-200,-20],宽度:200,对齐::right
试试这个

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

哈哈,很高兴听到,我来晚了…哈哈,但很高兴你找到了。
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
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