- 安装Prawn:gem install prawn
- rails4项目中使用prawn,首先在Gemfile中添加gem 'prawn',然后bundle install
- 使用Prawn创建PDF的三种方法(第2种方法比较代码量较少,建议使用):
# Assignment
pdf = Prawn::Document.new
paf.text "Hello World"
pdf.render_file "assignment.pdf"
# Implicit Block
Prawn::Document.generate("implicit.paf") do
text "Hello World"
end
# Explicit Block
Prawn::Document.generate("exlicit.pdf") do |pdf|
pdf.text "Hello World"
end
- Prawn以PDF左下角bottom-left corner作为页面的基准点origin[0, 0]
- 方法:
stroke_axis, stroke_circle [0, 0], bounding_box
move_down move_up move_cursor_to
stroke_horizontal_rule pad pad_top pad_bottom float