| Module | Prawn::Stamp |
| In: |
lib/prawn/stamp.rb
|
The Prawn::Stamp module is used to create content that will be included multiple times in a document. Using a stamp has three advantages over creating content anew each time it is placed on the page:
i. faster document creation ii. smaller final document iii. faster display on subsequent displays of the repeated element because the viewer application can cache the rendered results
Example:
pdf.create_stamp("my_stamp") {
pdf.fill_circle_at([10, 15], :radius => 5)
pdf.draw_text("hello world", :at => [20, 10])
}
pdf.stamp("my_stamp")
Creates a re-usable stamp named name
raises Prawn::Errors::NameTaken if a stamp already exists in this document with this name raises Prawn::Errors::InvalidName if name.empty?
Example:
pdf.create_stamp("my_stamp") {
pdf.fill_circle_at([10, 15], :radius => 5)
pdf.draw_text("hello world", :at => [20, 10])
}
Renders the stamp named name to the page raises Prawn::Errors::InvalidName if name.empty? raises Prawn::Errors::UndefinedObjectName if no stamp has been created with this name
Example:
pdf.create_stamp("my_stamp") {
pdf.fill_circle_at([10, 15], :radius => 5)
pdf.text("hello world", :at => [20, 10])
}
pdf.stamp("my_stamp")
Renders the stamp named name at a position offset from the initial coords at which the elements of the stamp was created
Example:
pdf.create_stamp("circle") do
pdf.fill_circle_at([0, 0], :radius => 25)
end
# draws a circle at 100, 100
pdf.stamp_at("circle", [100, 100])
See stamp() for exceptions that might be raised