lib/fillable-pdf.rb in fillable-pdf-0.9.5 vs lib/fillable-pdf.rb in fillable-pdf-0.9.5.1
- old
+ new
@@ -85,16 +85,18 @@
##
# Sets the value of a field given its unique field name and value.
#
# @param [String|Symbol] key the field name
# @param [String|Symbol] value the field value
+ # @param [NilClass|TrueClass|FalseClass] generate_appearance true to generate appearance, false to let the PDF viewer application generate form field appearance, nil (default) to let iText decide what's appropriate
#
- def set_field(key, value)
- # we set generate_appearance to false for buttons to ensure that the chosen
- # appearance for checkboxes (i.e. check, circle, diamond) is not changed
- generate_appearance = field_type(key) != Field::BUTTON
- pdf_field(key).setValue(value.to_s, generate_appearance)
+ def set_field(key, value, generate_appearance: nil)
+ if generate_appearance.nil?
+ pdf_field(key).setValue(value.to_s)
+ else
+ pdf_field(key).setValue(value.to_s, generate_appearance)
+ end
end
##
# Sets an image within the bounds of the given form field. It doesn't matter
# what type of form field it is (signature, image, etc). The image will be scaled
@@ -155,13 +157,14 @@
##
# Sets the values of multiple fields given a set of unique field names and values.
#
# @param [Hash] fields the set of field names and values
+ # @param [NilClass|TrueClass|FalseClass] generate_appearance true to generate appearance, false to let the PDF viewer application generate form field appearance, nil (default) to let iText decide what's appropriate
#
- def set_fields(fields)
- fields.each { |key, value| set_field key, value }
+ def set_fields(fields, generate_appearance: nil)
+ fields.each { |key, value| set_field key, value, generate_appearance: generate_appearance }
end
##
# Renames a field given its unique field name and the new field name.
#
@@ -218,11 +221,11 @@
##
# Saves the filled out PDF document in a given path and flattens it if requested.
#
# @param [String] file_path the name of the PDF file or file path
- # @param [Hash] flatten: true if PDF should be flattened, false otherwise
+ # @param [TrueClass|FalseClass] flatten true if PDF should be flattened, false otherwise
#
def save_as(file_path, flatten: false)
if @file_path == file_path
save(flatten: flatten)
else
@@ -243,10 +246,10 @@
private
##
# Writes the contents of the modified fields to the previously opened PDF file.
#
- # @param [Hash] flatten: true if PDF should be flattened, false otherwise
+ # @param [TrueClass|FalseClass] flatten: true if PDF should be flattened, false otherwise
#
def finalize(flatten: false)
@pdf_form.flattenFields if flatten
close
@byte_stream.toByteArray