Class: Acrobat::App
- Inherits:
-
Object
- Object
- Acrobat::App
- Defined in:
- lib/acrobat/app.rb
Instance Attribute Summary collapse
-
#docs ⇒ Object
readonly
Returns the value of attribute docs.
-
#ole_obj ⇒ Object
readonly
- WIN32_OLE
-
ole_obj.
-
#pdoc ⇒ Object
readonly
the wrapped [PDoc] PDoc object.
Class Method Summary collapse
-
.fill_form(form, output_name:, update_hash:) ⇒ Object
Fills the form with updates in a hash.
- .replace_pages(src, replacement, output_name:, **opts) ⇒ Object
-
.run ⇒ Object
Runs the adobe app and quits at the end.
Instance Method Summary collapse
-
#find_pdfs_in_dir(dir) ⇒ Array
Finds the pdfs in a dir.
- #form ⇒ Object
-
#hide ⇒ Object
hide the Adobe Acrobat application.
-
#initialize ⇒ App
constructor
Initialize the.
- #merge_pdfs(*pdfs) ⇒ Object
-
#merge_pdfs_in_dir(dir, name: nil, output_dir: nil) ⇒ Object
merges the pdfs in directory return [Boolean] if the merge was successful or not.
-
#open(file) ⇒ PDoc
open the file.
-
#quit ⇒ Object
quit the Adobe App.
-
#show ⇒ Object
show the Adobe Acrobat application.
Constructor Details
#initialize ⇒ App
Initialize the
37 38 39 40 41 |
# File 'lib/acrobat/app.rb', line 37 def initialize @ole_obj = WIN32OLE.new("AcroExch.App") load_constants(@ole_obj) @docs = [] end |
Instance Attribute Details
#docs ⇒ Object (readonly)
Returns the value of attribute docs.
141 142 143 |
# File 'lib/acrobat/app.rb', line 141 def docs @docs end |
#ole_obj ⇒ Object (readonly)
- WIN32_OLE
-
ole_obj
30 31 32 |
# File 'lib/acrobat/app.rb', line 30 def ole_obj @ole_obj end |
#pdoc ⇒ Object (readonly)
the wrapped [PDoc] PDoc object
33 34 35 |
# File 'lib/acrobat/app.rb', line 33 def pdoc @pdoc end |
Class Method Details
.fill_form(form, output_name:, update_hash:) ⇒ Object
Fills the form with updates in a hash
79 80 81 82 83 84 85 |
# File 'lib/acrobat/app.rb', line 79 def self.fill_form(form, output_name:, update_hash:) run do |app| doc = app.open(form) doc.fill_form(update_hash) doc.save_as(output_name) end end |
.replace_pages(src, replacement, output_name:, **opts) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/acrobat/app.rb', line 63 def self.replace_pages(src, replacement, output_name:, **opts) run do |app| app.open(src) do |doc| doc.replace_pages(replacement, **opts) doc.save_as(output_name) end end end |
.run ⇒ Object
Runs the adobe app and quits at the end
54 55 56 57 58 59 60 61 |
# File 'lib/acrobat/app.rb', line 54 def self.run the_app = new yield the_app ensure the_app&.quit GC.start nil end |
Instance Method Details
#find_pdfs_in_dir(dir) ⇒ Array
Finds the pdfs in a dir
100 101 102 |
# File 'lib/acrobat/app.rb', line 100 def find_pdfs_in_dir(dir) Pathname.glob(dir + "/*.pdf") end |
#form ⇒ Object
162 163 164 |
# File 'lib/acrobat/app.rb', line 162 def form Form.new(self, WIN32OLE.new("AFormAut.App")) end |
#hide ⇒ Object
hide the Adobe Acrobat application
93 94 95 |
# File 'lib/acrobat/app.rb', line 93 def hide ole_obj.Hide end |
#merge_pdfs(*pdfs) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/acrobat/app.rb', line 104 def merge_pdfs(*pdfs) pdf_array = Array(pdfs).flatten raise "Not enough pdfs to merge" if pdf_array.size < 2 first, *rest = pdf_array doc = self.open(first) rest.each do |path| doc.merge(path) end doc end |
#merge_pdfs_in_dir(dir, name: nil, output_dir: nil) ⇒ Object
merges the pdfs in directory return [Boolean] if the merge was successful or not
122 123 124 125 126 |
# File 'lib/acrobat/app.rb', line 122 def merge_pdfs_in_dir(dir, name: nil, output_dir: nil) name || "merged.pdf" dir = output_dir || dir merge_pdfs(find_pdfs_in_dir(dir)) end |
#open(file) ⇒ PDoc
open the file.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/acrobat/app.rb', line 146 def open(file) filepath = Pathname(file). raise FileNotFound.new(filepath) unless filepath.file? pdoc = WIN32OLE.new("AcroExch.PDDoc") is_opened = pdoc.open FileSystemObject.windows_path(filepath) doc = PDoc.new(self, pdoc, filepath) if is_opened docs << doc if is_opened return doc unless block_given? begin yield doc ensure doc.close nil end end |
#quit ⇒ Object
quit the Adobe App.
closes the open adobe documents and quits the program
131 132 133 134 135 136 137 138 139 |
# File 'lib/acrobat/app.rb', line 131 def quit begin docs.each { |d| d.close } ole_obj.Exit rescue return nil end nil end |
#show ⇒ Object
show the Adobe Acrobat application
88 89 90 |
# File 'lib/acrobat/app.rb', line 88 def show ole_obj.Show end |