lib/fillable-pdf.rb in fillable-pdf-0.9.3 vs lib/fillable-pdf.rb in fillable-pdf-0.9.4

- old
+ new

@@ -8,20 +8,21 @@ ## # Opens a given fillable-pdf PDF file and prepares it for modification. # # @param [String|Symbol] file_path the name of the PDF file or file path # - def initialize(file_path) + def initialize(file_path) # rubocop:disable Metrics/MethodLength raise IOError, "File <#{file_path}> is not found" unless File.exist?(file_path) @file_path = file_path begin @byte_stream = ITEXT::ByteArrayOutputStream.new @pdf_reader = ITEXT::PdfReader.new @file_path.to_s @pdf_writer = ITEXT::PdfWriter.new @byte_stream @pdf_doc = ITEXT::PdfDocument.new @pdf_reader, @pdf_writer @pdf_form = ITEXT::PdfAcroForm.getAcroForm(@pdf_doc, true) @form_fields = @pdf_form.getFormFields + @pdf_form.setGenerateAppearance false rescue StandardError => e raise "#{e.message} (Input file may be corrupt, incompatible, read-only, write-protected, encrypted, or may not have any form fields)" # rubocop:disable Layout/LineLength end end @@ -142,10 +143,10 @@ # @param [String|Symbol] key the field name # @param [String|Symbol] base64_image_data base64 encoded data image # def set_image_base64(key, base64_image_data) tmp_file = SecureRandom.uuid - File.open(tmp_file, 'wb') { |f| f.write(Base64.decode64(base64_image_data)) } + File.binwrite(tmp_file, Base64.decode64(base64_image_data)) set_image(key, tmp_file) ensure FileUtils.rm tmp_file end