acrobat 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop/minitest.yml +2 -0
- data/.rubocop/strict.yml +4 -0
- data/.rubocop.yml +23 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/Guardfile +28 -30
- data/{LICENSE.adoc → LICENSE.txt} +3 -4
- data/README.md +107 -0
- data/Rakefile +6 -54
- data/examples/6030.17.antenna.pdf +0 -0
- data/examples/6030.17.cm300.tx.pdf +0 -0
- data/examples/form_field.rb +21 -0
- data/examples/merge.rb +11 -0
- data/exe/acrobat +3 -0
- data/gemfiles/rubocop.gemfile +6 -0
- data/lib/acrobat/app.rb +197 -187
- data/lib/acrobat/avdoc.rb +22 -0
- data/lib/acrobat/jso.rb +87 -94
- data/lib/acrobat/pdoc.rb +155 -137
- data/lib/acrobat/version.rb +5 -0
- data/lib/acrobat.rb +5 -44
- data/rbs_collection.yaml +19 -0
- data/samples_other/background.js +40 -0
- data/samples_other/find_word.vb +440 -0
- data/samples_other/form.vb +393 -0
- data/sig/generated/acrobat/app.rbs +94 -0
- data/sig/generated/acrobat/avdoc.rbs +15 -0
- data/sig/generated/acrobat/jso.rbs +37 -0
- data/sig/generated/acrobat/pdoc.rbs +63 -0
- data/sig/generated/acrobat/version.rbs +5 -0
- data/sig/generated/acrobat.rbs +6 -0
- data/sig/prototype/lib/acrobat/app.rbs +3 -0
- data/sig/prototype/lib/acrobat/jso.rbs +5 -0
- data/sig/prototype/lib/acrobat/pdoc.rbs +5 -0
- data/vba/overlay.vba +40 -0
- metadata +45 -180
- data/.gitignore +0 -32
- data/History.adoc +0 -6
- data/Manifest.txt +0 -14
- data/README.adoc +0 -117
- data/bin/acrobat +0 -3
- data/test/acrobat_test.rb +0 -36
- data/test/test_helper.rb +0 -13
data/lib/acrobat/pdoc.rb
CHANGED
@@ -1,137 +1,155 @@
|
|
1
|
-
module Acrobat
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
attr_reader
|
6
|
-
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
ole_obj.
|
96
|
-
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
# return the
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
1
|
+
module Acrobat
|
2
|
+
class PDoc
|
3
|
+
attr_reader :ole_obj
|
4
|
+
|
5
|
+
attr_reader :path #: Path | Nil
|
6
|
+
|
7
|
+
def self.from_path(path)
|
8
|
+
filepath = Pathname(path).expand_path
|
9
|
+
raise FileNotFound.new(filepath) unless filepath.file?
|
10
|
+
pdoc = WIN32OLE.new("AcroExch.PDDoc")
|
11
|
+
result = pdoc.open FileSystemObject.windows_path(filepath)
|
12
|
+
raise "Error opening Acrobat::Pdoc from #{filepath}" if result == 0
|
13
|
+
new(pdoc, path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(ole, path = nil)
|
17
|
+
@ole_obj = ole
|
18
|
+
@path = path
|
19
|
+
end
|
20
|
+
|
21
|
+
def show(name = nil)
|
22
|
+
name ||= ole_obj.GetFileName
|
23
|
+
ole_obj.OpenAVDoc(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @rbs return Fixnum -- the number of pages in the pdf
|
27
|
+
def page_count
|
28
|
+
ole_obj.GetNumPages()
|
29
|
+
end
|
30
|
+
|
31
|
+
def last_page # : Fixnum
|
32
|
+
page_count - 1
|
33
|
+
end
|
34
|
+
|
35
|
+
# merges the doc to the
|
36
|
+
# @rbs doc: PDoc|String|Pathname -- an open PDoc to merge or filename
|
37
|
+
# @rbs return Boolean -- whether the doc was merged correctly
|
38
|
+
def merge(doc)
|
39
|
+
src = open_ole_pdoc(doc)
|
40
|
+
ole_insert_pages(src, self_start_page: last_page, merge_doc_page_start: 0,
|
41
|
+
number_pages: src.page_count, bookmarks: true)
|
42
|
+
end
|
43
|
+
|
44
|
+
# opens and/or returns PDoc
|
45
|
+
# @rbs doc: String|Pathname|Pdoc -- the String path of a pdf file
|
46
|
+
def open_ole_pdoc(doc) # : Pdoc
|
47
|
+
case doc
|
48
|
+
when PDoc
|
49
|
+
doc
|
50
|
+
when String, Pathname
|
51
|
+
self.class.from_path(doc)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def fill_and_save(results, name: nil, dir: nil)
|
56
|
+
fill_form(results)
|
57
|
+
is_saved = save_as(name: name, dir: dir)
|
58
|
+
puts "saved file: %s" % [dir + name] if is_saved
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
def prepend_pages(src_path:, src_page_start: 1, src_page_end: nil)
|
63
|
+
insert_pages(insert_after: 0, src_path: src_path, src_page_start: src_page_start, src_page_end: src_page_end)
|
64
|
+
end
|
65
|
+
|
66
|
+
# returns [Pathname] of d
|
67
|
+
# @rbs dir: [String, Nil] the String path
|
68
|
+
# @rbs return dir [Pathname] Pathname of dir or of working directory
|
69
|
+
def default_dir(dir)
|
70
|
+
Pathname(dir || Pathname.getw)
|
71
|
+
end
|
72
|
+
|
73
|
+
def save_as(name, dir: nil)
|
74
|
+
name ||= path.basename
|
75
|
+
dir = Pathname(dir || Pathname.getwd)
|
76
|
+
dir.mkpath
|
77
|
+
windows_path = FileSystemObject.windows_path(dir + name)
|
78
|
+
ole_obj.save(ACRO::PDSaveFull | ACRO::PDSaveCopy, windows_path)
|
79
|
+
end
|
80
|
+
|
81
|
+
def name
|
82
|
+
ole_obj.GetFileName
|
83
|
+
end
|
84
|
+
|
85
|
+
def close # : Bool -- true if closes successfully
|
86
|
+
result = ole_obj.Close
|
87
|
+
result == -1
|
88
|
+
rescue
|
89
|
+
false
|
90
|
+
end
|
91
|
+
|
92
|
+
def replace_pages(doc, start: 0, replace_start: 0, num_of_pages: 1, merge_annotations: true)
|
93
|
+
src = open_ole_pdoc(doc)
|
94
|
+
|
95
|
+
ole_obj.ReplacePages(start, src.ole_obj, replace_start, num_of_pages, merge_annotations)
|
96
|
+
end
|
97
|
+
|
98
|
+
# return the instance of JSO object
|
99
|
+
# @rbs return [Jso] a WIN32OLE wrapped Jso object 'javascript object'
|
100
|
+
def jso
|
101
|
+
@jso ||= Jso.new(self, ole_obj.GetJSObject)
|
102
|
+
end
|
103
|
+
|
104
|
+
# return the field_names of the pdf form
|
105
|
+
def field_names
|
106
|
+
jso.field_names
|
107
|
+
end
|
108
|
+
|
109
|
+
def fill_form(results)
|
110
|
+
jso.fill_form(results)
|
111
|
+
end
|
112
|
+
|
113
|
+
protected
|
114
|
+
|
115
|
+
def ole_insert_pages(merge_doc, self_start_page: 0, merge_doc_page_start: 0,
|
116
|
+
number_pages: nil, bookmarks: true)
|
117
|
+
bookmarks_ole = bookmarks ? 1 : 0
|
118
|
+
result = ole_obj.InsertPages(self_start_page, merge_doc.ole_obj, merge_doc_page_start, number_pages, bookmarks_ole)
|
119
|
+
if result == 0
|
120
|
+
raise "ole.InsertPages unable to insert merge doc #{merge_doc.name} into #{name}"
|
121
|
+
end
|
122
|
+
true
|
123
|
+
end
|
124
|
+
|
125
|
+
def ole_replace_pages(merge_doc, self_start_page: nil, merge_doc_page_start: nil,
|
126
|
+
number_pages: nil, bookmarks: true)
|
127
|
+
self_start_page_ole = self_start_page ? self_start_page - 1 : page_count - 1
|
128
|
+
page_start_ole = merge_doc_page_start ? merge_doc_page_start - 1 : merge_doc.GetNumPages - 1
|
129
|
+
number_pages_ole = number_pages || merge_doc
|
130
|
+
bookmarks_ole = bookmarks ? 1 : 0
|
131
|
+
result = ole_obj.ReplacePages(self_start_page_ole, merge_doc.ole, page_start_ole, number_pages_ole, bookmarks_ole)
|
132
|
+
end
|
133
|
+
|
134
|
+
def insert_pages(src:, insert_after: nil, src_page_start: nil, src_page_end: nil)
|
135
|
+
insert_hash = {"nPage" => insert_after - 1}
|
136
|
+
insert_hash["nStart"] = src_page_start + 1 if src_page_start
|
137
|
+
insert_hash["nEnd"] = src_page_end + 1 if src_page_end
|
138
|
+
ole_obj.InsertPages(**insert_hash)
|
139
|
+
end
|
140
|
+
|
141
|
+
def merge_pdoc(doc, **options)
|
142
|
+
if options
|
143
|
+
start = options[:start]
|
144
|
+
start_page
|
145
|
+
options[:pages]
|
146
|
+
ole_obj.InsertPages(start, doc.ole_obj, 0, doc.page_count, true)
|
147
|
+
else
|
148
|
+
ole_obj.InsertPages(page_count - 1, doc.ole_obj, 0, doc.page_count, true)
|
149
|
+
|
150
|
+
end
|
151
|
+
rescue
|
152
|
+
false
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/lib/acrobat.rb
CHANGED
@@ -1,48 +1,9 @@
|
|
1
|
-
|
2
|
-
require 'acrobat/app'
|
1
|
+
# frozen_string_literal: true; -*- rbs_inline: enabled -*-
|
3
2
|
|
3
|
+
require_relative "acrobat/version"
|
4
|
+
require_relative "acrobat/app"
|
4
5
|
|
5
6
|
module Acrobat
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
if $0 == __FILE__
|
11
|
-
require 'pry'
|
12
|
-
|
13
|
-
app = Acrobat::App.run do |app|
|
14
|
-
|
15
|
-
data = Pathname(__dir__).parent + 'data'
|
16
|
-
antenna_form = data + 'faa.6030.17.antenna.pdf'
|
17
|
-
|
18
|
-
|
19
|
-
doc1 = app.open(antenna_form)
|
20
|
-
doc1.show
|
21
|
-
|
22
|
-
fields = {'city' => 'OGD', 'state' => 'Utah',
|
23
|
-
'lid' => 'OGD',
|
24
|
-
'fac' => 'RTR',
|
25
|
-
}
|
26
|
-
doc1.fill_form(fields)
|
27
|
-
|
28
|
-
|
29
|
-
doc1.save_as(name: 'ogd.rtr.pdf', dir: 'tmp')
|
30
|
-
binding.pry
|
31
|
-
jso = doc1.jso
|
32
|
-
jso.show_console
|
33
|
-
puts "field count: #{jso.field_count}"
|
34
|
-
puts "field names: \n#{jso.field_names}"
|
35
|
-
binding.pry
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
doc2 = app.open(data + 'faa.6030.17.cm300.uhf.tx.pdf')
|
40
|
-
doc2.show
|
41
|
-
doc2.fill_form(fields)
|
42
|
-
|
43
|
-
doc1.merge(doc2)
|
44
|
-
doc1.save_as(name: 'ogd.merged_antenna_tx.pdf', dir: 'tmp')
|
45
|
-
|
46
|
-
end
|
47
|
-
|
7
|
+
class Error < StandardError; end
|
8
|
+
# Your code goes here...
|
48
9
|
end
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- type: git
|
4
|
+
name: ruby/gem_rbs_collection
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
6
|
+
revision: main
|
7
|
+
repo_dir: gems
|
8
|
+
|
9
|
+
# You can specify local directories as sources also.
|
10
|
+
# - type: local
|
11
|
+
# path: path/to/your/local/repository
|
12
|
+
|
13
|
+
# A directory to install the downloaded RBSs
|
14
|
+
path: .gem_rbs_collection
|
15
|
+
|
16
|
+
# gems:
|
17
|
+
# # If you want to avoid installing rbs files for gems, you can specify them here.
|
18
|
+
# - name: GEM_NAME
|
19
|
+
# ignore: true
|
@@ -0,0 +1,40 @@
|
|
1
|
+
Private Function ApplyBackgroundToPDF(BasePDF As String, BackgroundPDF As String)
|
2
|
+
Dim pdDoc As Acrobat.CAcroPDDoc
|
3
|
+
Dim pdTemplate As Acrobat.CAcroPDDoc
|
4
|
+
Dim template As Variant
|
5
|
+
Dim lngPage As Long
|
6
|
+
|
7
|
+
'Open base document
|
8
|
+
Set pdDoc = CreateObject("AcroExch.PDDoc")
|
9
|
+
pdDoc.Open BasePDF
|
10
|
+
DoEvents
|
11
|
+
|
12
|
+
'Open background document
|
13
|
+
Set pdTemplate = CreateObject("AcroExch.PDDoc")
|
14
|
+
pdTemplate.Open BackgroundPDF
|
15
|
+
DoEvents
|
16
|
+
|
17
|
+
'Add background document to base document
|
18
|
+
pdDoc.InsertPages pdDoc.GetNumPages - 1, pdTemplate, 0, 1, 0
|
19
|
+
|
20
|
+
'Create a template from the inserted background document
|
21
|
+
Set template = pdDoc.GetJSObject.CreateTemplate("background", pdDoc.GetNumPages - 1)
|
22
|
+
|
23
|
+
'Place the template as a background to all pages
|
24
|
+
For lngPage = 0 To pdDoc.GetNumPages - 2
|
25
|
+
template.Spawn lngPage, True, True
|
26
|
+
Next
|
27
|
+
|
28
|
+
'Delete last page (used for template creation purposes only)
|
29
|
+
pdDoc.DeletePages pdDoc.GetNumPages - 1, pdDoc.GetNumPages - 1
|
30
|
+
|
31
|
+
'Save
|
32
|
+
pdDoc.Save 1, BasePDF
|
33
|
+
|
34
|
+
'Close & Destroy Objects
|
35
|
+
pdDoc.Close
|
36
|
+
Set pdDoc = Nothing
|
37
|
+
|
38
|
+
pdTemplate.Close
|
39
|
+
Set pdTemplate = Nothing
|
40
|
+
End Function
|