acrobat 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +5 -0
- data/.autotest +25 -0
- data/.gitignore +32 -0
- data/Guardfile +30 -0
- data/History.adoc +6 -0
- data/LICENSE.adoc +22 -0
- data/Manifest.txt +13 -0
- data/README.adoc +115 -0
- data/Rakefile +47 -0
- data/bin/acrobat +3 -0
- data/lib/acrobat.rb +7 -0
- data/lib/acrobat/app.rb +414 -0
- data/test/acrobat_test.rb +33 -0
- data/test/test_helper.rb +9 -0
- metadata +239 -0
- metadata.gz.sig +1 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6cf8c70596499ece879fa4f9fc2479eae8f20d50
|
4
|
+
data.tar.gz: 248c69e02d4836795c2e812899f77b796431c276
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ce98e8d0fa74f6e2c8424ca8176f3812cb659ea668f4276a10c75d00166a91ee8e6d06ac0f08b9075078aafc4b036b793b6e5d48a775eb1f059652cdebc46d7
|
7
|
+
data.tar.gz: c491c89f2372e5256bb98aebc51d97cd0822c5dc349eb5b2c0f2ae2a8df19b009758c76ba5f9fddc15ba10a79a77a6477b2a2d1affbd318fbf62a7f6ba69b01e
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
data/.autotest
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require "autotest/restart"
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.testlib = "minitest/unit"
|
7
|
+
#
|
8
|
+
# at.extra_files << "../some/external/dependency.rb"
|
9
|
+
#
|
10
|
+
# at.libs << ":../some/external"
|
11
|
+
#
|
12
|
+
# at.add_exception "vendor"
|
13
|
+
#
|
14
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
15
|
+
# at.files_matching(/test_.*rb$/)
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# %w(TestA TestB).each do |klass|
|
19
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
|
23
|
+
# Autotest.add_hook :run_command do |at|
|
24
|
+
# system "rake build"
|
25
|
+
# end
|
data/.gitignore
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/pkg/
|
4
|
+
/spec/reports/
|
5
|
+
/spec/examples.txt
|
6
|
+
/test/tmp/
|
7
|
+
/test/version_tmp/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
# Used by dotenv library to load environment variables.
|
11
|
+
# .env
|
12
|
+
|
13
|
+
|
14
|
+
## Documentation cache and generated files:
|
15
|
+
/.yardoc/
|
16
|
+
/_yardoc/
|
17
|
+
/doc/
|
18
|
+
/rdoc/
|
19
|
+
|
20
|
+
## Environment normalization:
|
21
|
+
/.bundle/
|
22
|
+
/vendor/bundle
|
23
|
+
/lib/bundler/man/
|
24
|
+
|
25
|
+
# for a library or gem, you might want to ignore these files since the code is
|
26
|
+
# intended to run in multiple environments; otherwise, check them in:
|
27
|
+
Gemfile.lock
|
28
|
+
.ruby-version
|
29
|
+
.ruby-gemset
|
30
|
+
|
31
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
32
|
+
.rvmrc
|
data/Guardfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
guard :minitest do
|
19
|
+
# with Minitest::Unit
|
20
|
+
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
|
21
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
22
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
23
|
+
|
24
|
+
# with Minitest::Spec
|
25
|
+
# watch(%r{^spec/(.*)_spec\.rb$})
|
26
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
27
|
+
# watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
|
28
|
+
|
29
|
+
|
30
|
+
end
|
data/History.adoc
ADDED
data/LICENSE.adoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
.The MIT License
|
2
|
+
....
|
3
|
+
Copyright (C) 2012-2016 Dominic Sisneros and the Microstation-Ruby project.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
....
|
data/Manifest.txt
ADDED
data/README.adoc
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
= acrobat
|
2
|
+
Dominic Sisneros <https://github.com/dsisnero[@dsisnero]
|
3
|
+
//settings
|
4
|
+
:page-layout: base
|
5
|
+
:idprefix:
|
6
|
+
:idseparator: -
|
7
|
+
:source-language: ruby
|
8
|
+
:language: {source-language}
|
9
|
+
// Uris
|
10
|
+
:uri-org: https://github.com/dsisnero
|
11
|
+
:uri-repo: {uri-org}/acrobat
|
12
|
+
:uri-issues: {uri-repo}/issues
|
13
|
+
:uri-contributors: {uri-repo}/graphs/contributors
|
14
|
+
:uri-changelog: {uri-rel-file-base}CHANGELOG.adoc
|
15
|
+
:uri-rel-file-base: {uri-repo}/blob/master/
|
16
|
+
:uri-rel-tree-base: {uri-repo}/tree/master/
|
17
|
+
:uri-contribute: {uri-rel-file-base}CONTRIBUTING.adoc
|
18
|
+
:uri-license: {uri-rel-file-base}LICENSE.adoc
|
19
|
+
|
20
|
+
== DESCRIPTION:
|
21
|
+
|
22
|
+
== Requirements
|
23
|
+
|
24
|
+
* Windows Adobe Acrobat installed
|
25
|
+
|
26
|
+
== Install 0ptions
|
27
|
+
|
28
|
+
acrobat can be installed using (a) the `gem install` command, (b) Bundler
|
29
|
+
|
30
|
+
=== (a) gem install
|
31
|
+
|
32
|
+
Open a terminal and type
|
33
|
+
$ gem install acrobat
|
34
|
+
|
35
|
+
.Upgrading your installation
|
36
|
+
[TIP]
|
37
|
+
====
|
38
|
+
If you have an earlier version of acrobat installed you can update it using:
|
39
|
+
|
40
|
+
$ gem update acrobat
|
41
|
+
|
42
|
+
If you install a new version of the gem using `gem install` instead of
|
43
|
+
gem update, you'll have multiple versions installed. If that's the
|
44
|
+
case, use the following gem command to remove the old versions:
|
45
|
+
|
46
|
+
$ gem cleanup acrobat
|
47
|
+
====
|
48
|
+
=== (b) Bundler
|
49
|
+
|
50
|
+
. Create a Gemfile in the root folder of your project (or the current directory)
|
51
|
+
. Add the `asciidoctor` gem to your Gemfile as follows:
|
52
|
+
+
|
53
|
+
[source]
|
54
|
+
----
|
55
|
+
source 'https://rubygems.org'
|
56
|
+
gem 'acrobat'
|
57
|
+
# or specify the version explicitly
|
58
|
+
# gem 'acrobat', '0.0.5'
|
59
|
+
----
|
60
|
+
|
61
|
+
. Save the Gemfile
|
62
|
+
. Open a terminal and install the gem using:
|
63
|
+
|
64
|
+
$ bundle
|
65
|
+
|
66
|
+
To upgrade the gem, specify the new version in the Gemfile and run `bundle` again.
|
67
|
+
Using `bundle update` is *not* recommended as it will also update other gems, which may not be the desired result.
|
68
|
+
|
69
|
+
== Usage
|
70
|
+
|
71
|
+
[source,ruby]
|
72
|
+
====
|
73
|
+
|
74
|
+
require 'acrobat'
|
75
|
+
Adobe::Acrobat.run do |app|
|
76
|
+
fields = {city: 'City', state: 'State', zip: 'zip'}
|
77
|
+
doc = app.open('apd_document.pdf')
|
78
|
+
doc.fill_form(fields)
|
79
|
+
doc.show
|
80
|
+
doc2 = app.open('another_doc.pdf')
|
81
|
+
doc2.fill_form(fields)
|
82
|
+
doc1.merge_doc(doc2)
|
83
|
+
doc1.save_as(name: 'merged_doc.pdf', dir: 'tmp')
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
====
|
89
|
+
|
90
|
+
== Getting Help
|
91
|
+
|
92
|
+
|
93
|
+
We encourage you to ask questions and discuss any aspects of the project on the discussion list, Twitter or IRC.
|
94
|
+
|
95
|
+
Mailing list:: {uri-discuss}
|
96
|
+
|
97
|
+
|
98
|
+
ifdef::env-github[]
|
99
|
+
Further information and documentation about acrobat gem can be found on the project's website.
|
100
|
+
|
101
|
+
{uri-project}/[Home] | {uri-news}[News] | {uri-docs}[Docs]
|
102
|
+
endif::[]
|
103
|
+
|
104
|
+
The project's source code, issue tracker, and sub-projects are on github
|
105
|
+
|
106
|
+
Source repository (git):: {uri-repo}
|
107
|
+
Issue tracker:: {uri-issues}
|
108
|
+
acrobat organization on GitHub:: {uri-org}
|
109
|
+
|
110
|
+
== Copyright and Licensing
|
111
|
+
|
112
|
+
Copyright (C) 2012-2016 Dominic Sisneros and the acrobat-Ruby Project.
|
113
|
+
Free use of this software is granted under the terms of the MIT License.
|
114
|
+
|
115
|
+
See the {uri-license}[LICENSE] file for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "hoe"
|
5
|
+
|
6
|
+
class Hoe
|
7
|
+
|
8
|
+
def intuit_values
|
9
|
+
require 'asciidoctor'
|
10
|
+
doc = Asciidoctor.load_file readme_file
|
11
|
+
urls = { "home" => doc.attributes['uri-repo']}
|
12
|
+
desc = doc.blocks.find{|b| b.id =~ /description/i}.content
|
13
|
+
summ = desc.split(/\.\s+/).first(summary_sentences).join(". ")
|
14
|
+
self.urls ||= urls
|
15
|
+
self.description ||= desc
|
16
|
+
self.summary ||= summ
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
# Hoe.plugin :compiler
|
22
|
+
# Hoe.plugin :gem_prelude_sucks
|
23
|
+
# Hoe.plugin :inline
|
24
|
+
# Hoe.plugin :racc
|
25
|
+
# Hoe.plugin :rcov
|
26
|
+
# Hoe.plugin :rdoc
|
27
|
+
Hoe.plugin :bundler
|
28
|
+
Hoe.plugin :minitest
|
29
|
+
Hoe.plugin :yard
|
30
|
+
|
31
|
+
Hoe.spec "acrobat" do |s|
|
32
|
+
dependency("hoe-bundler", "> 0.0",:development)
|
33
|
+
dependency("hoe-yard", "> 0.0",:development)
|
34
|
+
dependency("pry", "> 0.0", :development)
|
35
|
+
dependency("pry-byebug", "> 0.0", :development)
|
36
|
+
dependency("yard", "> 0.0", :development)
|
37
|
+
dependency("guard", "> 0.0", :development)
|
38
|
+
dependency("wdm", "> 0.1.0", :development) if Gem.win_platform?
|
39
|
+
dependency("guard-minitest", "> 0.0", :development)
|
40
|
+
dependency("asciidoctor", ">0.0",:development)
|
41
|
+
developer("Dominic Sisneros","dsisnero@gmail.com")
|
42
|
+
clean_globs << "tmp"
|
43
|
+
license "MIT" # this should match the license in the README
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# vim: syntax=ruby
|
data/bin/acrobat
ADDED
data/lib/acrobat.rb
ADDED
data/lib/acrobat/app.rb
ADDED
@@ -0,0 +1,414 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'win32ole'
|
3
|
+
|
4
|
+
module FileSystemObject
|
5
|
+
|
6
|
+
@instance = nil
|
7
|
+
def FileSystemObject.instance
|
8
|
+
unless @instance
|
9
|
+
@instance = WIN32OLE.new('Scripting.FileSystemObject')
|
10
|
+
end
|
11
|
+
return @instance
|
12
|
+
end
|
13
|
+
|
14
|
+
def FileSystemObject.windows_path(path)
|
15
|
+
FileSystemObject.instance.GetAbsolutePathname(path.to_s)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
module ACRO; end
|
21
|
+
|
22
|
+
module Acrobat
|
23
|
+
|
24
|
+
class App
|
25
|
+
|
26
|
+
|
27
|
+
attr_reader :ole_obj, :pdoc
|
28
|
+
|
29
|
+
def initialize()
|
30
|
+
@ole_obj = WIN32OLE.new('AcroExch.App')
|
31
|
+
load_constants(@ole_obj)
|
32
|
+
@ole_obj
|
33
|
+
@docs = []
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
# Runs the adobe app and quits at the end
|
38
|
+
# @yield app [App]
|
39
|
+
#
|
40
|
+
# Acrobat::App.run do |app|
|
41
|
+
# doc = app.open('doc.pdf')
|
42
|
+
# doc.fill_form( city: 'City', state: 'ST')
|
43
|
+
# doc.save_as('filled.pdf')
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# @return nil
|
47
|
+
def self.run
|
48
|
+
begin
|
49
|
+
the_app = new
|
50
|
+
yield the_app
|
51
|
+
ensure
|
52
|
+
the_app.quit unless the_app.nil?
|
53
|
+
the_app = nil
|
54
|
+
GC.start
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# show the Adobe Acrobat application
|
60
|
+
def show
|
61
|
+
ole_obj.Show
|
62
|
+
end
|
63
|
+
|
64
|
+
# hide the Adobe Acrobat application
|
65
|
+
def hide
|
66
|
+
ole_obj.Hide
|
67
|
+
end
|
68
|
+
|
69
|
+
# Finds the pdfs in a dir
|
70
|
+
# @param dir [String] the directory to find pdfs in
|
71
|
+
# @return [Array] of pdf files
|
72
|
+
def find_pdfs_in_dir(dir)
|
73
|
+
Pathname.glob( dir + '*.pdf')
|
74
|
+
end
|
75
|
+
|
76
|
+
# merges the pdfs in directory
|
77
|
+
# @param dir [String] the path of the directory
|
78
|
+
# @param name [String,Nil] the name of the returned pdf file
|
79
|
+
# if the name is nil, the name is "merged.pdf"
|
80
|
+
# @param output_dir [String,Nil] the name of the output dir
|
81
|
+
# if the output_dir is nil, the output dir is the dir param
|
82
|
+
# return [Boolean] if the merge was successful or not
|
83
|
+
def merge_pdfs(dir, name: nil , output_dir: nil)
|
84
|
+
name = lname || "merged.pdf"
|
85
|
+
dir = output_dir || dir
|
86
|
+
pdfs = Pathname.glob( dir + '*.pdf')
|
87
|
+
raise 'Not enough pdfs to merge' if pdfs.size < 2
|
88
|
+
first, *rest = pdfs
|
89
|
+
open(first) do |pdf|
|
90
|
+
rest.each do |path|
|
91
|
+
open(path) do |pdfnext|
|
92
|
+
pdf.merge_doc(pdfnext)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
pdf.save_as(name: name, dir: dir)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# quit the Adobe App.
|
101
|
+
# closes the open adobe documents and quits the program
|
102
|
+
# @return nil
|
103
|
+
def quit
|
104
|
+
begin
|
105
|
+
docs.each{ |d| d.close}
|
106
|
+
ole_obj.Exit
|
107
|
+
rescue
|
108
|
+
return nil
|
109
|
+
end
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
|
113
|
+
def docs
|
114
|
+
@docs
|
115
|
+
end
|
116
|
+
|
117
|
+
# open the file.
|
118
|
+
# @param file [String #to_path]
|
119
|
+
# @return [PDoc] the open file as a Pdoc instance
|
120
|
+
def open(file)
|
121
|
+
filepath = Pathname(file).expand_path
|
122
|
+
raise FileNotFound unless filepath.file?
|
123
|
+
pdoc = WIN32OLE.new('AcroExch.PDDoc')
|
124
|
+
is_opened = pdoc.open FileSystemObject.windows_path(filepath)
|
125
|
+
doc = PDoc.new(self, pdoc, filepath) if is_opened
|
126
|
+
docs << doc if is_opened
|
127
|
+
return doc unless block_given?
|
128
|
+
begin
|
129
|
+
yield doc
|
130
|
+
ensure
|
131
|
+
doc.close unless doc.closed?
|
132
|
+
doc = nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
def form
|
138
|
+
Form.new(self,WIN32OLE.new("AFormAut.App"))
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def load_constants(ole_obj)
|
144
|
+
WIN32OLE.const_load(ole_obj, ACRO) unless ACRO.constants.size > 0
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
class PDoc
|
151
|
+
|
152
|
+
attr_reader :app, :ole_obj, :path
|
153
|
+
|
154
|
+
def initialize(app,ole,path=nil)
|
155
|
+
@app = app
|
156
|
+
@ole_obj = ole
|
157
|
+
@path = path
|
158
|
+
end
|
159
|
+
|
160
|
+
def show(name = nil)
|
161
|
+
name = name || ole_obj.GetFileName
|
162
|
+
ole_obj.OpenAVDoc(name)
|
163
|
+
end
|
164
|
+
|
165
|
+
# @return [Fixnum] the number of pages in the pdf
|
166
|
+
def page_count
|
167
|
+
ole_obj.GetNumPages()
|
168
|
+
end
|
169
|
+
|
170
|
+
# merges the doc to the
|
171
|
+
# @overload merge(doc)
|
172
|
+
# @param doc [String] the String path of a pdf file
|
173
|
+
# @overload merge(doc)
|
174
|
+
# @param doc [PDoc] an open PDoc to merge
|
175
|
+
# @return [Boolean] whether the doc was merged correctly
|
176
|
+
def merge(doc)
|
177
|
+
case doc
|
178
|
+
when PDoc
|
179
|
+
merge_pdoc(doc)
|
180
|
+
when String, Pathname
|
181
|
+
docpath = Pathname(doc)
|
182
|
+
raise 'File not found' unless docpath.file?
|
183
|
+
doc2 = app.open(docpath)
|
184
|
+
merge_pdoc(doc2)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def update_form(results)
|
189
|
+
form.update(results)
|
190
|
+
end
|
191
|
+
|
192
|
+
def update_and_save(results,name: nil, dir: nil)
|
193
|
+
update_form(results)
|
194
|
+
is_saved = save_as(name: name, dir: dir)
|
195
|
+
puts "saved file: %s" % [dir + name] if is_saved
|
196
|
+
end
|
197
|
+
|
198
|
+
def default_dir(d)
|
199
|
+
Pathname(dir || Pathname.getw)
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
def save_as(name:nil, dir:nil)
|
204
|
+
name = path.basename unless name
|
205
|
+
dir = Pathname(dir || Pathname.getwd)
|
206
|
+
dir.mkpath
|
207
|
+
windows_path = FileSystemObject.windows_path(dir + name )
|
208
|
+
ole_obj.save(ACRO::PDSaveFull | ACRO::PDSaveCopy,windows_path)
|
209
|
+
end
|
210
|
+
|
211
|
+
def name
|
212
|
+
ole_obj.GetFileName
|
213
|
+
end
|
214
|
+
|
215
|
+
def close
|
216
|
+
ole_obj.Close
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
def jso
|
221
|
+
@jso ||= Jso.new(ole_obj.GetJSObject)
|
222
|
+
end
|
223
|
+
|
224
|
+
def field_names
|
225
|
+
jso.field_names
|
226
|
+
end
|
227
|
+
|
228
|
+
def fill_form(results)
|
229
|
+
jso.fill_form(results)
|
230
|
+
end
|
231
|
+
|
232
|
+
protected
|
233
|
+
def merge_pdoc(doc)
|
234
|
+
ole_obj.InsertPages(page_count - 1, doc.ole_obj, 0, doc.page_count, true)
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
class Jso
|
240
|
+
|
241
|
+
attr_reader :ole_obj
|
242
|
+
|
243
|
+
def initialize(ole)
|
244
|
+
@ole_obj = ole
|
245
|
+
end
|
246
|
+
|
247
|
+
def find_field(name_or_number)
|
248
|
+
case name_or_number
|
249
|
+
when String,Symbol
|
250
|
+
ole_get_field(name_or_number.to_s)
|
251
|
+
when Number
|
252
|
+
ole_get_field(name_or_number)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def ole_get_field(field)
|
257
|
+
ole_obj.getField(field)
|
258
|
+
end
|
259
|
+
|
260
|
+
def console
|
261
|
+
@console ||= ole_obj.console
|
262
|
+
end
|
263
|
+
|
264
|
+
def field_names
|
265
|
+
result = []
|
266
|
+
0.upto(field_count -1) do |i|
|
267
|
+
result << ole_obj.getNthFieldName(i)
|
268
|
+
end
|
269
|
+
result
|
270
|
+
end
|
271
|
+
|
272
|
+
def set_field(name,value)
|
273
|
+
field = find_field(name)
|
274
|
+
field.Value = value if field
|
275
|
+
end
|
276
|
+
|
277
|
+
def get_field(name)
|
278
|
+
field = find_field(name)
|
279
|
+
field.Value if field
|
280
|
+
end
|
281
|
+
|
282
|
+
def field_count
|
283
|
+
ole_obj.numFields
|
284
|
+
end
|
285
|
+
|
286
|
+
def clear_form
|
287
|
+
ole_obj.resetForm
|
288
|
+
end
|
289
|
+
|
290
|
+
def fill_form(hash)
|
291
|
+
clear_form
|
292
|
+
hash.each do |k,v|
|
293
|
+
set_field(k,v)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
|
300
|
+
class Form
|
301
|
+
|
302
|
+
attr_reader :app, :ole_obj
|
303
|
+
|
304
|
+
def initialize(app, ole_obj)
|
305
|
+
@app = app
|
306
|
+
@ole_obj = ole_obj
|
307
|
+
end
|
308
|
+
|
309
|
+
def ole_fields
|
310
|
+
@ole_obj.fields
|
311
|
+
end
|
312
|
+
|
313
|
+
def [](name)
|
314
|
+
ole = get_name(name)
|
315
|
+
ole.value if ole
|
316
|
+
end
|
317
|
+
|
318
|
+
def get_name(name)
|
319
|
+
ole_obj.fields.Item(name.to_s) rescue nil
|
320
|
+
end
|
321
|
+
|
322
|
+
def []=(name,value)
|
323
|
+
ole = get_name(name.to_s)
|
324
|
+
ole.Value = value if ole
|
325
|
+
end
|
326
|
+
|
327
|
+
def update(hash)
|
328
|
+
hash.each do |k,v|
|
329
|
+
self[k.to_s] = v
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
|
334
|
+
def to_hash
|
335
|
+
result = {}
|
336
|
+
ole_obj.fields.each do |fld|
|
337
|
+
result[fld.Name] = fld.value
|
338
|
+
end
|
339
|
+
result
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
if $0 == __FILE__
|
348
|
+
require 'pry'
|
349
|
+
|
350
|
+
app = Acrobat::App.run do |app|
|
351
|
+
|
352
|
+
data = Pathname(__dir__).parent.parent + 'data'
|
353
|
+
antenna_form = data + 'faa.6030.17.antenna.pdf'
|
354
|
+
|
355
|
+
|
356
|
+
doc1 = app.open(antenna_form)
|
357
|
+
doc1.show
|
358
|
+
|
359
|
+
fields = {'city' => 'OGD', 'state' => 'Utah',
|
360
|
+
'lid' => 'OGD',
|
361
|
+
'fac' => 'RTR',
|
362
|
+
}
|
363
|
+
doc1.fill_form(fields)
|
364
|
+
|
365
|
+
|
366
|
+
doc1.save_as(name: 'ogd.rtr.pdf', dir: 'tmp')
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
doc2 = app.open(data + 'faa.6030.17.cm300.uhf.tx.pdf')
|
372
|
+
doc2.show
|
373
|
+
doc2.fill_form(fields)
|
374
|
+
|
375
|
+
doc1.merge(doc2)
|
376
|
+
doc1.save_as(name: 'ogd.merged_antenna_tx.pdf', dir: 'tmp')
|
377
|
+
|
378
|
+
end
|
379
|
+
|
380
|
+
end
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
# ublic Sub Main()
|
385
|
+
# Dim AcroApp As Acrobat.CAcroApp
|
386
|
+
# Dim AvDoc As Acrobat.CAcroAVDoc
|
387
|
+
# Dim fcount As Long
|
388
|
+
# Dim sFieldName As String
|
389
|
+
# Dim Field As AFORMAUTLib.Field
|
390
|
+
# Dim Fields As AFORMAUTLib.Fields
|
391
|
+
# Dim AcroForm As AFORMAUTLib.AFormApp
|
392
|
+
|
393
|
+
# Set AcroApp = CreateObject("AcroExch.App")
|
394
|
+
# Set AvDoc = CreateObject("AcroExch.AVDoc")
|
395
|
+
|
396
|
+
# If AvDoc.Open("C:\test\testform.pdf", "") Then
|
397
|
+
# AcroApp.Show
|
398
|
+
# Set AcroForm = CreateObject("AFormAut.App")
|
399
|
+
# Set Fields = AcroForm.Fields
|
400
|
+
# fcount = Fields.Count
|
401
|
+
# MsgBox fcount
|
402
|
+
# For Each Field In Fields
|
403
|
+
# sFieldName = Field.Name
|
404
|
+
# MsgBox sFieldName
|
405
|
+
# Next Field
|
406
|
+
# Else
|
407
|
+
# MsgBox "failure"
|
408
|
+
# End If
|
409
|
+
# AcroApp.Exit
|
410
|
+
# Set AcroApp = Nothing
|
411
|
+
# Set AvDoc = Nothing
|
412
|
+
# Set Field = Nothing
|
413
|
+
# Set Fields = Nothing
|
414
|
+
# Set AcroForm = Nothing
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
require "acrobat"
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
module Acrobat
|
9
|
+
|
10
|
+
describe App do
|
11
|
+
|
12
|
+
|
13
|
+
describe 'new' do
|
14
|
+
|
15
|
+
|
16
|
+
it 'can be created' do
|
17
|
+
|
18
|
+
app = App.new
|
19
|
+
app.must_be_instance_of App
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has an ole_obj' do
|
23
|
+
app = App.new
|
24
|
+
app.ole_obj.must_be_instance_of WIN32OLE
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
if RUBY_VERSION < '1.9.3'
|
4
|
+
::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
|
5
|
+
else
|
6
|
+
::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
|
7
|
+
end
|
8
|
+
|
9
|
+
|
metadata
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acrobat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dominic Sisneros
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkc2lz
|
14
|
+
bmVybzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
15
|
+
MB4XDTE3MDEzMTE2MDEyMVoXDTE4MDEzMTE2MDEyMVowPzERMA8GA1UEAwwIZHNp
|
16
|
+
c25lcm8xFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
17
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMEeU7rhCgCeSX2xM43x
|
18
|
+
WSfxn+McvtU5zL2Q15fibhe2UFSRM7+9kMElye9MpA2SvRvUdi1ffgifo5IbFskz
|
19
|
+
b872rX5NOTC5zdhc8/r7K2N5sNzuxtQS2neYwsDJYn+X4IXW+7vAC3tsEq60uotD
|
20
|
+
5ZCrGMzpe8+8QlOLhKBE8n8B1tGFqrJPLWGVT/4SLW6/AeegPXWzwaOUJioNnlP1
|
21
|
+
zoTq5xAqCFp+l5+gzj82hexnd3Mz6wTqfZn+z6KOeGYz2rHa1uaVWAJ4I03ofaso
|
22
|
+
4dj5N/R//djheKrZcRwvcHwglgNedKpKcDFvBmVh+/ueq1ZN4mxIOuWFfqH5EH1w
|
23
|
+
okECAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFDq6
|
24
|
+
Q3OD0phGy8SIVItmHiEfNUYNMB0GA1UdEQQWMBSBEmRzaXNuZXJvQGdtYWlsLmNv
|
25
|
+
bTAdBgNVHRIEFjAUgRJkc2lzbmVyb0BnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD
|
26
|
+
ggEBAGordyPD1ZBGMaJ0ZHsaw8gmmPX45r2LOjiuthmQfWTbxkXGcfxZmQMp4Rgq
|
27
|
+
i2SEkJ1bcxKNf2QcIEaSMo3tFz0JZikMMCCav1al2TB10JShlzkmK6akYrD2EMca
|
28
|
+
skUBzdiaODmVIxaePQKTofH3Tr+muDj2k2Jt0GADDi464TXjB7+WAfj9PNB6L0Bo
|
29
|
+
XLAuEbpybfRTbmgT1izvF41ZtekUEupzZkfe4Zjwdcfth9NX9YQml8RTrw5xPlgp
|
30
|
+
YeDmGZXEg4lVRuTrhlS3p+s9c5mdx2nJxSRQ8cJDPhwGiGFfBMMXo+HTfjvnVrDI
|
31
|
+
R2Hvov2PJU3aGJ/5gQuBTYYf3/0=
|
32
|
+
-----END CERTIFICATE-----
|
33
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
34
|
+
dependencies:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: minitest
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '5.10'
|
42
|
+
type: :development
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '5.10'
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: hoe-yard
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.1.2
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.1.2
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: hoe-bundler
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.0'
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: pry
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.0'
|
84
|
+
type: :development
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0.0'
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: pry-byebug
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.0'
|
98
|
+
type: :development
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0.0'
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: yard
|
107
|
+
requirement: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0.0'
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0.0'
|
119
|
+
- !ruby/object:Gem::Dependency
|
120
|
+
name: guard
|
121
|
+
requirement: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0.0'
|
126
|
+
type: :development
|
127
|
+
prerelease: false
|
128
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0.0'
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: wdm
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 0.1.0
|
140
|
+
type: :development
|
141
|
+
prerelease: false
|
142
|
+
version_requirements: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 0.1.0
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
name: guard-minitest
|
149
|
+
requirement: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0.0'
|
154
|
+
type: :development
|
155
|
+
prerelease: false
|
156
|
+
version_requirements: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0.0'
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
name: asciidoctor
|
163
|
+
requirement: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">"
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0.0'
|
168
|
+
type: :development
|
169
|
+
prerelease: false
|
170
|
+
version_requirements: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">"
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0.0'
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: hoe
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - "~>"
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '3.16'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - "~>"
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '3.16'
|
189
|
+
description: ''
|
190
|
+
email:
|
191
|
+
- dsisnero@gmail.com
|
192
|
+
executables:
|
193
|
+
- acrobat
|
194
|
+
extensions: []
|
195
|
+
extra_rdoc_files:
|
196
|
+
- Manifest.txt
|
197
|
+
- History.adoc
|
198
|
+
files:
|
199
|
+
- ".autotest"
|
200
|
+
- ".gitignore"
|
201
|
+
- Guardfile
|
202
|
+
- History.adoc
|
203
|
+
- LICENSE.adoc
|
204
|
+
- Manifest.txt
|
205
|
+
- README.adoc
|
206
|
+
- Rakefile
|
207
|
+
- bin/acrobat
|
208
|
+
- lib/acrobat.rb
|
209
|
+
- lib/acrobat/app.rb
|
210
|
+
- test/acrobat_test.rb
|
211
|
+
- test/test_helper.rb
|
212
|
+
homepage: https://github.com/dsisnero/acrobat
|
213
|
+
licenses:
|
214
|
+
- MIT
|
215
|
+
metadata: {}
|
216
|
+
post_install_message:
|
217
|
+
rdoc_options:
|
218
|
+
- "--title"
|
219
|
+
- TestAcrobat Documentation
|
220
|
+
- "--quiet"
|
221
|
+
require_paths:
|
222
|
+
- lib
|
223
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - ">="
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '0'
|
228
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
|
+
requirements:
|
230
|
+
- - ">="
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
version: '0'
|
233
|
+
requirements: []
|
234
|
+
rubyforge_project:
|
235
|
+
rubygems_version: 2.6.10
|
236
|
+
signing_key:
|
237
|
+
specification_version: 4
|
238
|
+
summary: ''
|
239
|
+
test_files: []
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1��7�^.��s��gD'=�Ԏ/��D[��NQL��K�LR�|O���8�ݜ�-�%���YS��ZWk٣��Y���'T�(��l/Ѕ���d���ك�9(bݙ�K|��xC��«���C��B��#}ԗ�G-zД؎��v�CLX�&;˸4l���C��:�&������/�H u�#�O-������FE��&a^���A�mO!ԇ��];,���V����k��>�jx D'qmޝ~�D�a�������G��&
|