acrobat 0.0.8 → 0.2.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/.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} +21 -22
- data/README.md +107 -0
- data/Rakefile +10 -48
- 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/lib/acrobat/app.rb +42 -57
- data/lib/acrobat/jso.rb +18 -25
- data/lib/acrobat/pdoc.rb +49 -42
- data/lib/acrobat/version.rb +5 -0
- data/lib/acrobat.rb +14 -17
- data/samples_other/background.js +40 -0
- data/samples_other/find_word.vb +440 -0
- data/samples_other/form.vb +393 -0
- data/vba/overlay.vba +40 -0
- metadata +34 -217
- checksums.yaml.gz.sig +0 -0
- data/.autotest +0 -25
- data/.gitignore +0 -32
- data/History.adoc +0 -6
- data/Manifest.txt +0 -15
- 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.tar.gz.sig +0 -1
- metadata.gz.sig +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0dbaa90ebab7df2e5eeb70d4bfff5a75448134d3efa100a45fe172080b85df8
|
4
|
+
data.tar.gz: f9b04d87101a45da0fdc675ea98a54c2eb73abd723e10844078d7d0474799947
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b306b051e57f3a9224d3cdb9b7f57df2b07d99533eac4d9dcf4d6bf59836d78a93dcafac356e8ea15ab76c9fe7fb847e67ff245d76239337e85b4224675571b7
|
7
|
+
data.tar.gz: 9811e4ca8066d17b88b3e010a162ade3b10cae13e3c322e3c9db7705702e9d7b5c324b5e6d45146c9531620d586ed2506e0a723d589a47e447e679c22731d40c
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/Guardfile
CHANGED
@@ -1,30 +1,28 @@
|
|
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/(.*)
|
21
|
-
watch(%r{^lib/(.*/)?([^/]+)\.rb$})
|
22
|
-
watch(%r{^test/test_helper\.rb$})
|
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
|
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
|
+
end
|
@@ -1,22 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Copyright (
|
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
|
-
....
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 dsisnero
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# DESCRIPTION:
|
2
|
+
|
3
|
+
The acrobat gem is a library that uses WIN32OLE to automate pdf
|
4
|
+
functions. Adobe Reader or Adobe Acrobat must be installed and then you
|
5
|
+
can fill forms and merge documents
|
6
|
+
|
7
|
+
# Requirements
|
8
|
+
|
9
|
+
- Windows Adobe Acrobat installed
|
10
|
+
|
11
|
+
# Install 0ptions
|
12
|
+
|
13
|
+
acrobat can be installed using (a) the `gem install` command, (b)
|
14
|
+
Bundler
|
15
|
+
|
16
|
+
## (a) gem install
|
17
|
+
|
18
|
+
Open a terminal and type \$ gem install acrobat
|
19
|
+
|
20
|
+
:::: tip
|
21
|
+
::: title
|
22
|
+
Upgrading your installation
|
23
|
+
:::
|
24
|
+
|
25
|
+
If you have an earlier version of acrobat installed you can update it
|
26
|
+
using:
|
27
|
+
|
28
|
+
\$ gem update acrobat
|
29
|
+
|
30
|
+
If you install a new version of the gem using `gem install` instead of
|
31
|
+
gem update, you'll have multiple versions installed. If that's the case,
|
32
|
+
use the following gem command to remove the old versions:
|
33
|
+
|
34
|
+
\$ gem cleanup acrobat
|
35
|
+
::::
|
36
|
+
|
37
|
+
## (b) Bundler
|
38
|
+
|
39
|
+
1. Create a Gemfile in the root folder of your project (or the current
|
40
|
+
directory)
|
41
|
+
|
42
|
+
2. Add the `asciidoctor` gem to your Gemfile as follows:
|
43
|
+
|
44
|
+
``` ruby
|
45
|
+
source 'https://rubygems.org'
|
46
|
+
gem 'acrobat'
|
47
|
+
# or specify the version explicitly
|
48
|
+
# gem 'acrobat', '0.0.5'
|
49
|
+
```
|
50
|
+
|
51
|
+
3. Save the Gemfile
|
52
|
+
|
53
|
+
4. Open a terminal and install the gem using:
|
54
|
+
|
55
|
+
$ bundle
|
56
|
+
|
57
|
+
To upgrade the gem, specify the new version in the Gemfile and run
|
58
|
+
`bundle` again. Using `bundle update` is **not** recommended as it will
|
59
|
+
also update other gems, which may not be the desired result.
|
60
|
+
|
61
|
+
# Usage
|
62
|
+
|
63
|
+
``` ruby
|
64
|
+
require 'acrobat'
|
65
|
+
Adobe::Acrobat.run do |app|
|
66
|
+
fields = {city: 'City', state: 'State', zip: 'zip'}
|
67
|
+
doc = app.open('apd_document.pdf')
|
68
|
+
doc.fill_form(fields)
|
69
|
+
doc.show
|
70
|
+
doc2 = app.open('another_doc.pdf')
|
71
|
+
doc2.fill_form(fields)
|
72
|
+
doc1.merge_doc(doc2)
|
73
|
+
doc1.save_as(name: 'merged_doc.pdf', dir: 'tmp')
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
# Getting Help
|
78
|
+
|
79
|
+
We encourage you to ask questions and discuss any aspects of the project
|
80
|
+
on the discussion list, Twitter or IRC.
|
81
|
+
|
82
|
+
Mailing list
|
83
|
+
|
84
|
+
: {uri-discuss}
|
85
|
+
|
86
|
+
The project's source code, issue tracker, and sub-projects are on github
|
87
|
+
|
88
|
+
Source repository (git)
|
89
|
+
|
90
|
+
: <https://github.com/dsisnero/acrobat>
|
91
|
+
|
92
|
+
Issue tracker
|
93
|
+
|
94
|
+
: <https://github.com/dsisnero/acrobat/issues>
|
95
|
+
|
96
|
+
acrobat organization on GitHub
|
97
|
+
|
98
|
+
: <https://github.com/dsisnero>
|
99
|
+
|
100
|
+
# Copyright and Licensing
|
101
|
+
|
102
|
+
Copyright © 2012-2016 Dominic Sisneros and the acrobat-Ruby Project.
|
103
|
+
Free use of this software is granted under the terms of the MIT License.
|
104
|
+
|
105
|
+
See the
|
106
|
+
[LICENSE](https://github.com/dsisnero/acrobat/blob/master/LICENSE.txt)
|
107
|
+
file for details.
|
data/Rakefile
CHANGED
@@ -1,48 +1,10 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require "
|
4
|
-
require "
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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", "~> 1.4",:development)
|
33
|
-
dependency("hoe-yard", "> 0.1",: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", :development) if Gem.win_platform?
|
39
|
-
dependency("guard-minitest", "> 0.0", :development)
|
40
|
-
dependency("asciidoctor", "> 0.0",:development)
|
41
|
-
# dependency("minitest-utils", "> 0.0", :development)
|
42
|
-
developer("Dominic Sisneros","dsisnero@gmail.com")
|
43
|
-
clean_globs << "tmp"
|
44
|
-
license "MIT" # this should match the license in the README
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
# vim: syntax=ruby
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "minitest/test_task"
|
5
|
+
|
6
|
+
Minitest::TestTask.create
|
7
|
+
|
8
|
+
require "standard/rake"
|
9
|
+
|
10
|
+
task default: %i[test standard]
|
Binary file
|
Binary file
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "acrobat"
|
2
|
+
require "pry"
|
3
|
+
|
4
|
+
Acrobat::App.new
|
5
|
+
# app.show
|
6
|
+
|
7
|
+
|
8
|
+
Acrobat::App.run do |app|
|
9
|
+
dir = Pathname(__dir__)
|
10
|
+
form_path = dir + "6030.17.antenna.pdf"
|
11
|
+
puts "Working on #{form_path}"
|
12
|
+
doc1 = app.open(form_path)
|
13
|
+
doc1.show
|
14
|
+
fields = {"city" => "Salt Lake City",
|
15
|
+
"state" => "Utah",
|
16
|
+
"lid" => "SLCB",
|
17
|
+
"fac" => "RTR",
|
18
|
+
:cost_center => "1234"}
|
19
|
+
doc1.fill_form(fields)
|
20
|
+
doc1.save_as(name: "slcb.example.pdf", dir: dir.parent + "tmp")
|
21
|
+
end
|
data/examples/merge.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "acrobat/app"
|
2
|
+
require "pry"
|
3
|
+
Acrobat::App.run do |app|
|
4
|
+
dir = Pathname(__dir__)
|
5
|
+
form_path = dir + "6030.17.antenna.pdf"
|
6
|
+
doc = app.open(form_path)
|
7
|
+
binding.pry
|
8
|
+
doc.merge(dir + "6030.17.cm300.tx.pdf")
|
9
|
+
doc.show
|
10
|
+
doc.save_as(name: "example.merged.pdf", dir: dir.parent + "tmp")
|
11
|
+
end
|
data/lib/acrobat/app.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require_relative
|
4
|
-
require_relative 'jso'
|
1
|
+
require "win32ole"
|
2
|
+
require_relative "pdoc"
|
3
|
+
require_relative "jso"
|
5
4
|
|
6
|
-
module
|
5
|
+
module Acrobat
|
6
|
+
class FileNotFound < StandardError
|
7
|
+
def initialize(path)
|
8
|
+
super("File not found: #{path}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
7
12
|
|
13
|
+
module FileSystemObject
|
8
14
|
@instance = nil
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
return @instance
|
15
|
+
def self.instance
|
16
|
+
@instance ||= WIN32OLE.new("Scripting.FileSystemObject")
|
17
|
+
@instance
|
14
18
|
end
|
15
19
|
|
16
|
-
def
|
20
|
+
def self.windows_path(path)
|
17
21
|
FileSystemObject.instance.GetAbsolutePathname(path.to_s)
|
18
22
|
end
|
19
|
-
|
20
23
|
end
|
21
24
|
|
22
25
|
module ACRO; end
|
23
26
|
|
24
27
|
module Acrobat
|
25
|
-
|
26
28
|
class App
|
27
|
-
|
28
29
|
# [WIN32_OLE] ole_obj
|
29
30
|
attr_reader :ole_obj
|
30
31
|
|
@@ -33,12 +34,10 @@ module Acrobat
|
|
33
34
|
|
34
35
|
# Initialize the
|
35
36
|
# @return [App] return an instance of App
|
36
|
-
def initialize
|
37
|
-
@ole_obj = WIN32OLE.new(
|
37
|
+
def initialize
|
38
|
+
@ole_obj = WIN32OLE.new("AcroExch.App")
|
38
39
|
load_constants(@ole_obj)
|
39
|
-
@ole_obj
|
40
40
|
@docs = []
|
41
|
-
self
|
42
41
|
end
|
43
42
|
|
44
43
|
# Runs the adobe app and quits at the end
|
@@ -53,21 +52,18 @@ module Acrobat
|
|
53
52
|
#
|
54
53
|
# @return nil
|
55
54
|
def self.run
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
GC.start
|
63
|
-
nil
|
64
|
-
end
|
55
|
+
the_app = new
|
56
|
+
yield the_app
|
57
|
+
ensure
|
58
|
+
the_app&.quit
|
59
|
+
GC.start
|
60
|
+
nil
|
65
61
|
end
|
66
62
|
|
67
|
-
def self.replace_pages(src, replacement, output_name
|
68
|
-
|
63
|
+
def self.replace_pages(src, replacement, output_name:, **opts)
|
64
|
+
run do |app|
|
69
65
|
app.open(src) do |doc|
|
70
|
-
doc.replace_pages(replacement, opts)
|
66
|
+
doc.replace_pages(replacement, **opts)
|
71
67
|
doc.save_as(output_name)
|
72
68
|
end
|
73
69
|
end
|
@@ -80,16 +76,14 @@ module Acrobat
|
|
80
76
|
# @param doc [String] the String path of a fillable pdf file
|
81
77
|
# @param output_name [String] the name of the saved filled pdf file
|
82
78
|
# @param update_hash [Hash] the hash with updates
|
83
|
-
def self.fill_form(form,output_name
|
84
|
-
|
79
|
+
def self.fill_form(form, output_name:, update_hash:)
|
80
|
+
run do |app|
|
85
81
|
doc = app.open(form)
|
86
82
|
doc.fill_form(update_hash)
|
87
83
|
doc.save_as(output_name)
|
88
84
|
end
|
89
85
|
end
|
90
86
|
|
91
|
-
|
92
|
-
|
93
87
|
# show the Adobe Acrobat application
|
94
88
|
def show
|
95
89
|
ole_obj.Show
|
@@ -104,22 +98,20 @@ module Acrobat
|
|
104
98
|
# @param dir [String] the directory to find pdfs in
|
105
99
|
# @return [Array] of pdf files
|
106
100
|
def find_pdfs_in_dir(dir)
|
107
|
-
Pathname.glob(
|
101
|
+
Pathname.glob(dir + "/*.pdf")
|
108
102
|
end
|
109
103
|
|
110
104
|
def merge_pdfs(*pdfs)
|
111
|
-
pdf_array = Array(pdfs)
|
112
|
-
raise
|
105
|
+
pdf_array = Array(pdfs).flatten
|
106
|
+
raise "Not enough pdfs to merge" if pdf_array.size < 2
|
113
107
|
first, *rest = pdf_array
|
114
|
-
doc = open(first)
|
108
|
+
doc = self.open(first)
|
115
109
|
rest.each do |path|
|
116
110
|
doc.merge(path)
|
117
111
|
end
|
118
112
|
doc
|
119
113
|
end
|
120
114
|
|
121
|
-
|
122
|
-
|
123
115
|
# merges the pdfs in directory
|
124
116
|
# @param dir [String] the path of the directory
|
125
117
|
# @param name [String,Nil] the name of the returned pdf file
|
@@ -127,12 +119,10 @@ module Acrobat
|
|
127
119
|
# @param output_dir [String,Nil] the name of the output dir
|
128
120
|
# if the output_dir is nil, the output dir is the dir param
|
129
121
|
# return [Boolean] if the merge was successful or not
|
130
|
-
def merge_pdfs_in_dir(dir, name: nil
|
131
|
-
name
|
122
|
+
def merge_pdfs_in_dir(dir, name: nil, output_dir: nil)
|
123
|
+
name || "merged.pdf"
|
132
124
|
dir = output_dir || dir
|
133
|
-
|
134
|
-
doc = merge_pdfs(pdfs)
|
135
|
-
doc
|
125
|
+
merge_pdfs(find_pdfs_in_dir(dir))
|
136
126
|
end
|
137
127
|
|
138
128
|
# quit the Adobe App.
|
@@ -140,7 +130,7 @@ module Acrobat
|
|
140
130
|
# @return nil
|
141
131
|
def quit
|
142
132
|
begin
|
143
|
-
docs.each{ |d| d.close}
|
133
|
+
docs.each { |d| d.close }
|
144
134
|
ole_obj.Exit
|
145
135
|
rescue
|
146
136
|
return nil
|
@@ -148,17 +138,15 @@ module Acrobat
|
|
148
138
|
nil
|
149
139
|
end
|
150
140
|
|
151
|
-
|
152
|
-
@docs
|
153
|
-
end
|
141
|
+
attr_reader :docs
|
154
142
|
|
155
143
|
# open the file.
|
156
144
|
# @param file [String #to_path]
|
157
145
|
# @return [PDoc] the open file as a Pdoc instance
|
158
146
|
def open(file)
|
159
147
|
filepath = Pathname(file).expand_path
|
160
|
-
raise FileNotFound unless filepath.file?
|
161
|
-
pdoc = WIN32OLE.new(
|
148
|
+
raise FileNotFound.new(filepath) unless filepath.file?
|
149
|
+
pdoc = WIN32OLE.new("AcroExch.PDDoc")
|
162
150
|
is_opened = pdoc.open FileSystemObject.windows_path(filepath)
|
163
151
|
doc = PDoc.new(self, pdoc, filepath) if is_opened
|
164
152
|
docs << doc if is_opened
|
@@ -167,21 +155,18 @@ module Acrobat
|
|
167
155
|
yield doc
|
168
156
|
ensure
|
169
157
|
doc.close
|
170
|
-
|
158
|
+
nil
|
171
159
|
end
|
172
160
|
end
|
173
161
|
|
174
|
-
|
175
162
|
def form
|
176
|
-
Form.new(self,WIN32OLE.new("AFormAut.App"))
|
163
|
+
Form.new(self, WIN32OLE.new("AFormAut.App"))
|
177
164
|
end
|
178
165
|
|
179
166
|
private
|
180
167
|
|
181
168
|
def load_constants(ole_obj)
|
182
|
-
|
169
|
+
WIN32OLE.const_load(ole_obj, ACRO) unless ACRO.constants.size > 0
|
183
170
|
end
|
184
|
-
|
185
171
|
end
|
186
|
-
|
187
172
|
end
|