Class: Acrobat::PDoc

Inherits:
Object
  • Object
show all
Defined in:
lib/acrobat/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, ole, path = nil) ⇒ PDoc

Returns a new instance of PDoc.



154
155
156
157
158
# File 'lib/acrobat/app.rb', line 154

def initialize(app,ole,path=nil)
  @app = app
  @ole_obj = ole
  @path = path
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



152
153
154
# File 'lib/acrobat/app.rb', line 152

def app
  @app
end

#ole_objObject (readonly)

Returns the value of attribute ole_obj.



152
153
154
# File 'lib/acrobat/app.rb', line 152

def ole_obj
  @ole_obj
end

#pathObject (readonly)

Returns the value of attribute path.



152
153
154
# File 'lib/acrobat/app.rb', line 152

def path
  @path
end

Instance Method Details

#closeObject



215
216
217
# File 'lib/acrobat/app.rb', line 215

def close
  ole_obj.Close
end

#default_dir(d) ⇒ Object



198
199
200
# File 'lib/acrobat/app.rb', line 198

def default_dir(d)
  Pathname(dir || Pathname.getw)
end

#field_namesObject



224
225
226
# File 'lib/acrobat/app.rb', line 224

def field_names
  jso.field_names
end

#fill_form(results) ⇒ Object



228
229
230
# File 'lib/acrobat/app.rb', line 228

def fill_form(results)
  jso.fill_form(results)
end

#jsoObject



220
221
222
# File 'lib/acrobat/app.rb', line 220

def jso
  @jso ||= Jso.new(ole_obj.GetJSObject)
end

#merge(doc) ⇒ Boolean #merge(doc) ⇒ Boolean

merges the doc to the

Overloads:

  • #merge(doc) ⇒ Boolean

    Parameters:

    • doc (String)

      the String path of a pdf file

  • #merge(doc) ⇒ Boolean

    Parameters:

    • doc (PDoc)

      an open PDoc to merge

Returns:

  • (Boolean)

    whether the doc was merged correctly



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/acrobat/app.rb', line 176

def merge(doc)
  case doc
  when PDoc
    merge_pdoc(doc)
  when String, Pathname
    docpath = Pathname(doc)
    raise 'File not found' unless docpath.file?
    doc2 = app.open(docpath)
    merge_pdoc(doc2)
  end
end

#nameObject



211
212
213
# File 'lib/acrobat/app.rb', line 211

def name
  ole_obj.GetFileName
end

#page_countFixnum

Returns the number of pages in the pdf.

Returns:

  • (Fixnum)

    the number of pages in the pdf



166
167
168
# File 'lib/acrobat/app.rb', line 166

def page_count
  ole_obj.GetNumPages()
end

#save_as(name: nil, dir: nil) ⇒ Object



203
204
205
206
207
208
209
# File 'lib/acrobat/app.rb', line 203

def save_as(name:nil, dir:nil)
  name = path.basename unless name
  dir = Pathname(dir || Pathname.getwd)
  dir.mkpath
  windows_path = FileSystemObject.windows_path(dir + name )
  ole_obj.save(ACRO::PDSaveFull | ACRO::PDSaveCopy,windows_path)
end

#show(name = nil) ⇒ Object



160
161
162
163
# File 'lib/acrobat/app.rb', line 160

def show(name = nil)
  name = name ||  ole_obj.GetFileName
  ole_obj.OpenAVDoc(name)
end

#update_and_save(results, name: nil, dir: nil) ⇒ Object



192
193
194
195
196
# File 'lib/acrobat/app.rb', line 192

def update_and_save(results,name: nil, dir: nil)
  update_form(results)
  is_saved = save_as(name: name, dir: dir)
  puts "saved file: %s" % [dir + name] if is_saved
end

#update_form(results) ⇒ Object



188
189
190
# File 'lib/acrobat/app.rb', line 188

def update_form(results)
  form.update(results)
end