- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
假设我们要在占据页面上半部分的第一页上显示一个标题。页面的下半部分应该填满我们的文章文本,文本应该继续流入后续页面直到用完:
这是一个非常基本的布局场景,但我不明白如何在 Prawn 中实现它。
这是从他们的在线文档中派生的一些示例代码:
pdf = Prawn::Document.new do
text "The Prince", :align => :center, :size => 48
text "Niccolò Machiavelli", :align => :center, :size => 20
move_down 42
column_box([0, cursor], :columns => 3, :width => bounds.width) do
text((<<-END.gsub(/\s+/, ' ') + "\n\n") * 20)
All the States and Governments by which men are or ever have been ruled,
have been and are either Republics or Princedoms. Princedoms are either
hereditary, in which the bla bla bla bla .....
END
end
end.render
但这只会继续显示每个页面的标题空间:
正确的做法是什么?
最佳答案
我一直在和同样的问题作斗争。我最终继承了 ColumnBox 并添加了一个助手来调用它:
module Prawn
class Document
def reflow_column_box(*args, &block)
init_column_box(block) do |parent_box|
map_to_absolute!(args[0])
@bounding_box = ReflowColumnBox.new(self, parent_box, *args)
end
end
private
class ReflowColumnBox < ColumnBox
def move_past_bottom
@current_column = (@current_column + 1) % @columns
@document.y = @y
if 0 == @current_column
@y = @parent.absolute_top
@document.start_new_page
end
end
end
end
end
然后它就像普通的列框一样被调用,但在下一个分页符将回流到父边界框。改变你的线路:
column_box([0, cursor], :columns => 3, :width => bounds.width) do
到
reflow_column_box([0, cursor], :columns => 3, :width => bounds.width) do
希望对你有帮助。 Prawn 的级别很低,是一把双刃剑,它有时无法满足您的需求,但工具可以扩展和构建更复杂的结构。
关于ruby - 用 Prawn 控制内容流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17282100/
我一直在 Prawn 中为 Ruby 随机尝试字体。 例如: Times New Roman - 是的 Palatino Linotype - 没有 是否有可用字体和不可用字体的列表? 最佳答案 代码
我正在尝试为单行设置 prawn 中笔划线的宽度。我想做的是...... pdf.stroke_horizontal_line(0, bounds.width, :at => row*spacin
我正在使用Rails 4 + prawn_rails +最新版本的prawn(v 1.1.0),并在以下更改日志中注意到:https://github.com/prawnpdf/prawn/wiki/
对不起我的英语不好。 我正在尝试在我的应用程序上使用 prawn 和 prawnto。我有一个 pdf 文件用作模板,该 pdf 文件只有一个页面,而该页面只有一个页眉和一个页脚,然后,我的 Cont
我在 rails 3.0 应用程序中使用 Prawn Gem 0.12.0。 我的文档显示正常: class TemplatePdf filename) text_box "2005
我采用了 Railscast episode 153 revised 的方法。 我的 Controller 是 class AdminsController "https://github.com/
我正在关注这个 railscasts #153,我正在尝试将表数据添加到 prawn。我不断收到此错误: Prawn::Errors::UnrecognizedTableContent 最佳答案 注意
我正在使用 ruby、prawn 和 prawnto 动态生成包含其他语言文本的 pdf。我似乎无法显示任何带有非英语字符的语言的文本。它不会抛出任何错误...只是显示一堆破折号而不是字符。 Pr
我正在尝试使用 Prawn 生成 pdf @buyer = Buyer.last Prawn::Document.generate("samle.pdf") do text "hello #{@b
我正在尝试在 prawn 类中使用 rails 3.2 助手,但 rails 抛出: undefined method `number_with_precision' for # Prawn 类 cl
我使用 Prawn 创建 pdf 文件,我想将 Logo 放入文件中。我看过这个网站 Creating pdf引用如何添加图像。 这是我在 ExamResultPdf.rb 中的代码生成pdf的文件:
我有一个 4 页的 PDF 模板,我想用 prawn 生成.我需要在我的 pdf 中多次重复这个模板,每次用不同的内容填充它。 如果我使用: Prawn::Document.generate('o
我正在尝试使用 Prawn 从包含大量图像的目录生成 PDF。到目前为止,我的代码运行良好,只有一个小问题,它会在 PDF 的开头插入一个空白页。 因为我不一定知道图像的大小(除了它们大致相同,任一维
我最近开始在我的应用程序中使用 Prawn 来生成 PDF,我还使用 Nori 来解析 XML 和发送 SMS。 我意识到我的应用无法再发送短信,我收到了这条错误消息: nori: undefine
目标是:创建具有标题横幅和重复标题表的 PDF 问题是:如果表格开始新页面,pdf.move_down 不起作用 CODE: # repeat drawing in every page pdf.re
我似乎无法将元数据设置为基于模板生成的 pdf。这是不允许的还是我做错了什么。 这是代码 pdf = Prawn::Document.new(:template => "sample.pdf",
我正在尝试这个简单的脚本: require 'prawn' template_file_name = File.join(File.dirname(__FILE__), 'template.pdf')
我的客户说生成的 PDF 必须是 CMYK 格式。 Prawn 能做到吗? 我在文档中找不到答案。 最佳答案 是的,Prawn 可以做到这一点。这个主题似乎被文档省略了,所以你可以看看源代码。 Thi
我有一张图片image.jpg,我想将它放在每页左下角的页脚中。我目前正在这样做,使用 Ruby 1.9.3 和 prawn gem 来创建 PDF,如下所示: start_new_page imag
我正在使用 Prawn 在 Rails 3 应用程序中生成 PDF。 是否可以像在 HTML View 中一样将 Unicode 字符串打印到 PDF 中? 例如, 在 show.html.erb
我是一名优秀的程序员,十分优秀!