Skip to content

Commit

Permalink
Upgrade slf4j and iText to v8.0.5. (#49)
Browse files Browse the repository at this point in the history
* Upgrade slf4j and iText to v8.0..5

* Remove a useless comment.
  • Loading branch information
vkononov authored Oct 16, 2024
1 parent a4336a2 commit 54e9693
Show file tree
Hide file tree
Showing 17 changed files with 12 additions and 13 deletions.
Binary file removed ext/commons-7.2.4.jar
Binary file not shown.
Binary file added ext/commons-8.0.5.jar
Binary file not shown.
Binary file renamed ext/font-asian-7.2.4.jar → ext/font-asian-8.0.5.jar
100755 → 100644
Binary file not shown.
Binary file removed ext/forms-7.2.4.jar
Binary file not shown.
Binary file added ext/forms-8.0.5.jar
Binary file not shown.
Binary file removed ext/io-7.2.4.jar
Binary file not shown.
Binary file added ext/io-8.0.5.jar
Binary file not shown.
Binary file removed ext/kernel-7.2.4.jar
Binary file not shown.
Binary file added ext/kernel-8.0.5.jar
Binary file not shown.
Binary file removed ext/layout-7.2.4.jar
Binary file not shown.
Binary file added ext/layout-8.0.5.jar
Binary file not shown.
Binary file added ext/slf4j-api-2.0.16.jar
Binary file not shown.
Binary file removed ext/slf4j-api-2.0.4.jar
Binary file not shown.
Binary file added ext/slf4j-simple-2.0.16.jar
Binary file not shown.
Binary file removed ext/slf4j-simple-2.0.4.jar
Binary file not shown.
14 changes: 7 additions & 7 deletions lib/fillable-pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(file_path)
@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
@form_fields = @pdf_form.getAllFormFields
rescue StandardError => e
handle_pdf_open_error(e)
end
Expand Down Expand Up @@ -123,7 +123,10 @@ def set_image(key, file_path) # rubocop:disable Metrics/AbcSize, Metrics/MethodL
widgets = field.getWidgets
widget_dict = suppress_warnings { widgets.isEmpty ? field.getPdfObject : widgets.get(0).getPdfObject }
orig_rect = widget_dict.getAsRectangle(ITEXT::PdfName.Rect)
border_width = field.getBorderWidth

border_style = field.getWidgets.get(0).getBorderStyle
border_width = border_style.nil? ? 0 : border_style.getWidth

bounding_rectangle = ITEXT::Rectangle.new(
orig_rect.getWidth - (border_width * 2),
orig_rect.getHeight - (border_width * 2)
Expand Down Expand Up @@ -213,6 +216,7 @@ def rename_field(old_key, new_key)
def remove_field(key)
if @form_fields.containsKey(key.to_s)
@pdf_form.removeField(key.to_s)
@form_fields.remove(key.to_s)
else
raise "Unknown key name `#{key}'"
end
Expand Down Expand Up @@ -306,10 +310,6 @@ def validate_input(key, value)
end

def handle_pdf_open_error(err)
if err.message.include?('crypto/BlockCipher')
raise 'The PDF file is encrypted and cannot be opened.'
else
raise "#{err.message} (Input file may be corrupt, incompatible, read-only, write-protected, encrypted, or may not have any form fields)" # rubocop:disable Layout/LineLength
end
raise "#{err.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
11 changes: 5 additions & 6 deletions test/pdf_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_that_file_has_a_positive_number_of_editable_fields
end

def test_that_hash_can_be_accessed
assert_equal 16, @pdf.fields.length
assert_equal 12, @pdf.fields.length
end

def test_that_a_field_value_can_be_accessed_by_name
Expand Down Expand Up @@ -117,10 +117,10 @@ def test_that_a_checkbox_can_be_checked_and_unchecked
def test_that_a_radio_button_can_be_checked_and_unchecked
@pdf.set_field(:language, 'ruby')

3.times { |i| assert_equal 'ruby', @pdf.field("language.#{i}".gsub('.0', '')) }
assert_equal 'ruby', @pdf.field(:language)
@pdf.set_field(:language, 'Off')

3.times { |i| assert_equal 'Off', @pdf.field("language.#{i}".gsub('.0', '')) }
assert_equal 'Off', @pdf.field(:language)
end

def test_that_a_field_can_be_renamed
Expand All @@ -136,7 +136,7 @@ def test_that_a_field_can_be_renamed
end

def test_that_a_field_can_be_removed
@pdf.remove_field(:first_name)
assert @pdf.remove_field(:first_name)
err = assert_raises RuntimeError do
@pdf.field(:first_name)
end
Expand Down Expand Up @@ -220,11 +220,10 @@ def test_save_with_flattening

def test_open_encrypted_pdf
encrypted_pdf_path = 'test/files/encrypted.pdf'
# Assuming you have an encrypted PDF for testing
err = assert_raises StandardError do
FillablePDF.new(encrypted_pdf_path)
end
assert_equal 'The PDF file is encrypted and cannot be opened.', err.message
assert_match 'file may be corrupt, incompatible, read-only, write-protected, encrypted', err.message
end

def test_open_signed_and_certified_pdf
Expand Down

0 comments on commit 54e9693

Please sign in to comment.