Module: CorpPdf::Actions::Base

Included in:
AddField, RemoveField, UpdateField, Fields::Base
Defined in:
lib/corp_pdf/actions/base.rb

Instance Method Summary collapse

Instance Method Details

#acroform_refObject



39
40
41
# File 'lib/corp_pdf/actions/base.rb', line 39

def acroform_ref
  @document.send(:acroform_ref)
end

#apply_patch(ref, body, original_body = nil) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/corp_pdf/actions/base.rb', line 20

def apply_patch(ref, body, original_body = nil)
  original_body ||= resolver.object_body(ref)
  return if body == original_body

  patches.reject! { |p| p[:ref] == ref }
  patches << { ref: ref, body: body }
end

#find_page_by_number(page_num) ⇒ Object



43
44
45
# File 'lib/corp_pdf/actions/base.rb', line 43

def find_page_by_number(page_num)
  @document.send(:find_page_by_number, page_num)
end

#get_object_body_with_patch(ref) ⇒ Object



14
15
16
17
18
# File 'lib/corp_pdf/actions/base.rb', line 14

def get_object_body_with_patch(ref)
  body = resolver.object_body(ref)
  existing_patch = patches.find { |p| p[:ref] == ref }
  existing_patch ? existing_patch[:body] : body
end

#next_fresh_object_numberObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/corp_pdf/actions/base.rb', line 28

def next_fresh_object_number
  max_obj_num = 0
  resolver.each_object do |ref, _|
    max_obj_num = [max_obj_num, ref[0]].max
  end
  patches.each do |p|
    max_obj_num = [max_obj_num, p[:ref][0]].max
  end
  max_obj_num + 1
end

#patchesObject



10
11
12
# File 'lib/corp_pdf/actions/base.rb', line 10

def patches
  @document.instance_variable_get(:@patches)
end

#resolverObject



6
7
8
# File 'lib/corp_pdf/actions/base.rb', line 6

def resolver
  @document.instance_variable_get(:@resolver)
end