Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add #form? and #xfa_form? methods to CombinePDF::PDF #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/combine_pdf/pdf_public.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions test/combine_pdf/pdf_test.rb
Original file line number Diff line number Diff line change
@@ -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
Binary file added test/fixtures/files/acro_form.pdf
Binary file not shown.
Binary file added test/fixtures/files/xfa_form.pdf
Binary file not shown.