Sha256: d018a00f01e8a73f2cb8a8b20000842f30dc25b477e4d6cc3409f5395576a91d
Contents?: true
Size: 1.71 KB
Versions: 1
Compression:
Stored size: 1.71 KB
Contents
module GBDev module PDF # A page that represents a PDF page. class Page # String template : A path to the template file def initialize(template) @template = template @fields = {} @images = {} end # Sets a known text field in the PDF template. # # key : A known field in the PDF. # value : The value to apply to the know field. def set_text(key, value) @fields[key] = value end # Alias for set_text method alias :text :set_text # Sets a know image area in the PDF template. # # key : A known field in the PDF. # value : The image to apply to the know image area. def set_image(key, value) @images[key] = value end # Alias for the set_image method alias :image :set_image # Renders the template with the given data and saves to the given filename path. # # String filename : A path to the file to be created. def save_to(filename) field_cache = HashMap.new reader = PdfReader.new(@template) stamper = PdfStamper.new( reader, FileOutputStream.new(filename) ) form = stamper.getAcroFields() form.setFieldCache(field_cache) @fields.each do |field, value| form.setField(field.to_s, value.to_s) end stamper.setFormFlattening(true) stamper.close end def display end def save_and_display(filename) save(filename) display end include Gbdev::Utils::PrivateMethods end # End Page end # End PDF end # End GBDev
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gbdev-pdf_filler-0.2.0 | lib/pdf_filler/page.rb |