diff --git a/lib/combine_pdf/pdf_public.rb b/lib/combine_pdf/pdf_public.rb index a55b81b..b22bdf8 100644 --- a/lib/combine_pdf/pdf_public.rb +++ b/lib/combine_pdf/pdf_public.rb @@ -157,6 +157,14 @@ def clear_forms_data @forms_data.nil? || @forms_data.clear end + def form? + !@forms_data.nil? + end + + def xfa_form? + form? && !@forms_data.dig(:referenced_object, :XFA).nil? + end + # Save the PDF to file. # # file_name:: is a string or path object for the output. diff --git a/test/combine_pdf/pdf_test.rb b/test/combine_pdf/pdf_test.rb new file mode 100644 index 0000000..eb898ad --- /dev/null +++ b/test/combine_pdf/pdf_test.rb @@ -0,0 +1,21 @@ +require 'bundler/setup' +require 'minitest/autorun' +require 'combine_pdf' + +describe CombinePDF::PDF do + subject { CombinePDF.load("test/fixtures/files/#{file}") } + + describe 'AcroForm documents' do + let(:file) { 'acro_form.pdf' } + + it('knows that it is an acro form') { assert(subject.form? == true) } + it('knows that it is NOT a dynamic XFA form') { assert(subject.xfa_form? == false) } + end + + describe 'dynamic xfa documents' do + let(:file) { 'xfa_form.pdf' } + + it('knows that it is an acro form') { assert(subject.form? == true) } + it('knows that it is IS a dynamic XFA form') { assert(subject.xfa_form? == true) } + end +end diff --git a/test/fixtures/files/acro_form.pdf b/test/fixtures/files/acro_form.pdf new file mode 100644 index 0000000..e7e1243 Binary files /dev/null and b/test/fixtures/files/acro_form.pdf differ diff --git a/test/fixtures/files/xfa_form.pdf b/test/fixtures/files/xfa_form.pdf new file mode 100644 index 0000000..54906b4 Binary files /dev/null and b/test/fixtures/files/xfa_form.pdf differ