module Prawn::Stamp
This 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:
-
Faster document creation.
-
Smaller final document.
-
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([10, 15], 5) pdf.draw_text("hello world", at: [20, 10]) } pdf.stamp("my_stamp")
Public Instance Methods
Source
# File lib/prawn/stamp.rb, line 74 def create_stamp(name, &block) dictionary = create_stamp_dictionary(name) state.page.stamp_stream(dictionary, &block) end
Creates a re-usable stamp.
@example
pdf.create_stamp("my_stamp") { pdf.fill_circle([10, 15], 5) pdf.draw_text("hello world", at: [20, 10]) }
@param name [String] Stamp name. @yield Stamp content. @return [void] @raise [Prawn::Errors::NameTaken]
if a stamp already exists in this document with this name.
@raise [Prawn::Errors::InvalidName] if name is empty.
Source
# File lib/prawn/stamp.rb, line 35 def stamp(name) dictionary_name, dictionary = stamp_dictionary(name) renderer.add_content("/#{dictionary_name} Do") update_annotation_references(dictionary.data[:Annots]) state.page.xobjects.merge!(dictionary_name => dictionary) end
Renders the stamp.
@example
pdf.create_stamp("my_stamp") { pdf.fill_circle([10, 15], 5) pdf.text("hello world", at: [20, 10]) } pdf.stamp("my_stamp")
@param name [String] @return [void] @raise [Prawn::Errors::InvalidName] if name is empty. @raise [Prawn::Errors::UndefinedObjectName] if no stamp has been created
with this name.
Source
# File lib/prawn/stamp.rb, line 56 def stamp_at(name, point) translate(point[0], point[1]) { stamp(name) } end
Renders the stamp 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([0, 0], 25) end # draws a circle at 100, 100 pdf.stamp_at("circle", [100, 100])
@param name [String] @param point [Array(Number, Number)] @return [void] @see [stamp] for exceptions that might be raised.