Class: Acrobat::App
- Inherits:
-
Object
- Object
- Acrobat::App
- Defined in:
- lib/acrobat/app.rb
Instance Attribute Summary collapse
-
#ole_obj ⇒ Object
readonly
Returns the value of attribute ole_obj.
-
#pdoc ⇒ Object
readonly
Returns the value of attribute pdoc.
Class Method Summary collapse
-
.run ⇒ Object
Runs the adobe app and quits at the end Acrobat::App.run do |app| doc = app.open(‘doc.pdf’) doc.fill_form( city: ‘City’, state: ‘ST’) doc.save_as(‘filled.pdf’) end.
Instance Method Summary collapse
- #docs ⇒ Object
-
#find_pdfs_in_dir(dir) ⇒ Array
Finds the pdfs in a dir.
- #form ⇒ Object
-
#hide ⇒ Object
hide the Adobe Acrobat application.
-
#initialize ⇒ App
constructor
A new instance of App.
- #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
31 32 33 34 35 36 37 |
# File 'lib/acrobat/app.rb', line 31 def initialize() @ole_obj = WIN32OLE.new('AcroExch.App') load_constants(@ole_obj) @ole_obj @docs = [] self end |
Instance Attribute Details
#ole_obj ⇒ Object (readonly)
Returns the value of attribute ole_obj.
29 30 31 |
# File 'lib/acrobat/app.rb', line 29 def ole_obj @ole_obj end |
#pdoc ⇒ Object (readonly)
Returns the value of attribute pdoc.
29 30 31 |
# File 'lib/acrobat/app.rb', line 29 def pdoc @pdoc end |
Class Method Details
.run ⇒ Object
Runs the adobe app and quits at the end Acrobat::App.run do |app|
doc = app.open('doc.pdf')
doc.fill_form( city: 'City', state: 'ST')
doc.save_as('filled.pdf')
end
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/acrobat/app.rb', line 49 def self.run begin the_app = new yield the_app ensure the_app.quit unless the_app.nil? the_app = nil GC.start nil end end |
Instance Method Details
#docs ⇒ Object
117 118 119 |
# File 'lib/acrobat/app.rb', line 117 def docs @docs end |
#find_pdfs_in_dir(dir) ⇒ Array
Finds the pdfs in a dir
74 75 76 |
# File 'lib/acrobat/app.rb', line 74 def find_pdfs_in_dir(dir) Pathname.glob( dir + '*.pdf') end |
#form ⇒ Object
141 142 143 |
# File 'lib/acrobat/app.rb', line 141 def form Form.new(self,WIN32OLE.new("AFormAut.App")) end |
#hide ⇒ Object
hide the Adobe Acrobat application
67 68 69 |
# File 'lib/acrobat/app.rb', line 67 def hide ole_obj.Hide end |
#merge_pdfs(*pdfs) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/acrobat/app.rb', line 78 def merge_pdfs(*pdfs) pdf_array = Array(pdfs) raise 'Not enough pdfs to merge' if pdfs.size < 2 first, *rest = pdf_array doc = 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
96 97 98 99 100 101 102 |
# File 'lib/acrobat/app.rb', line 96 def merge_pdfs_in_dir(dir, name: nil , output_dir: nil) name = lname || "merged.pdf" dir = output_dir || dir pdfs = Pathname.glob( dir + '*.pdf') doc = merge_pdfs(pdfs) doc end |
#open(file) ⇒ PDoc
open the file.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/acrobat/app.rb', line 124 def open(file) filepath = Pathname(file). raise FileNotFound 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 doc = nil end end |
#quit ⇒ Object
quit the Adobe App.
closes the open adobe documents and quits the program
107 108 109 110 111 112 113 114 115 |
# File 'lib/acrobat/app.rb', line 107 def quit begin docs.each{ |d| d.close} ole_obj.Exit rescue return nil end nil end |
#show ⇒ Object
show the Adobe Acrobat application
62 63 64 |
# File 'lib/acrobat/app.rb', line 62 def show ole_obj.Show end |