class Acrobat::PDoc
Attributes
app[R]
ole_obj[R]
path[R]
Public Class Methods
new(app,ole,path=nil)
click to toggle source
# File lib/acrobat/pdoc.rb, line 7 def initialize(app,ole,path=nil) @app = app @ole_obj = ole @path = path end
Public Instance Methods
close()
click to toggle source
# File lib/acrobat/pdoc.rb, line 94 def close ole_obj.Close rescue nil end
default_dir(dir)
click to toggle source
returns [Pathname] of d
@param dir [String, Nil] the String path
@return dir [Pathname] Pathname of dir or of working directory
# File lib/acrobat/pdoc.rb, line 78 def default_dir(dir) Pathname(dir || Pathname.getw) end
field_names()
click to toggle source
return the field_names
of the pdf form
# File lib/acrobat/pdoc.rb, line 111 def field_names jso.field_names end
fill_and_save(results,name: nil, dir: nil)
click to toggle source
# File lib/acrobat/pdoc.rb, line 57 def fill_and_save(results,name: nil, dir: nil) fill_form(results) is_saved = save_as(name: name, dir: dir) puts "saved file: %s" % [dir + name] if is_saved true end
fill_form(results)
click to toggle source
# File lib/acrobat/pdoc.rb, line 115 def fill_form(results) jso.fill_form(results) end
insert_pages(src: , insert_after: nil, src_page_start: nil, src_page_end: nil)
click to toggle source
# File lib/acrobat/pdoc.rb, line 64 def insert_pages(src: , insert_after: nil, src_page_start: nil, src_page_end: nil) insert_hash = { 'nPage' => insert_after -1 } insert_hash['nStart'] = src_page_start + 1 if src_page_start insert_hash['nEnd'] = src_page_end + 1 if src_page_end ole_obj.InsertPages(**insert_hash) end
jso()
click to toggle source
return the instance of JSO object @return [Jso] a WIN32OLE wrapped Jso
object 'javascript object'
# File lib/acrobat/pdoc.rb, line 106 def jso @jso ||= Jso.new(self,ole_obj.GetJSObject) end
last_page()
click to toggle source
# File lib/acrobat/pdoc.rb, line 23 def last_page page_count -1 end
merge(doc)
click to toggle source
merges the doc to the @overload merge(doc)
@param doc [String] the String path of a pdf file
@overload merge(doc)
@param doc [PDoc] an open PDoc to merge
@return [Boolean] whether the doc was merged correctly
# File lib/acrobat/pdoc.rb, line 33 def merge(doc) src = open_pdoc(doc) merge_pdoc(src) end
name()
click to toggle source
# File lib/acrobat/pdoc.rb, line 90 def name ole_obj.GetFileName end
open_pdoc(doc)
click to toggle source
opens and/or returns PDoc
@overload open(doc)
@param doc [String] the String path of a pdf file
@overload open(PDoc] and open PDoc
file
@param doc [PDoc] an already open PDoc file
@return doc [PDOC] the opened PDoc
# File lib/acrobat/pdoc.rb, line 44 def open_pdoc(doc) src = case doc when PDoc doc when String, Pathname docpath = Pathname(doc) raise 'File not found' unless docpath.file? doc2 = app.open(docpath) doc2 end src end
page_count()
click to toggle source
@return [Fixnum] the number of pages in the pdf
# File lib/acrobat/pdoc.rb, line 19 def page_count ole_obj.GetNumPages() end
prepend_pages(src_path: , src_page_start: 1, src_page_end: nil)
click to toggle source
# File lib/acrobat/pdoc.rb, line 71 def prepend_pages(src_path: , src_page_start: 1, src_page_end: nil) insert_pages( insert_after: 0, src_path: src_path, src_page_start: src_page_start, src_page_end: src_page_end) end
replace_pages(doc, start: 0, replace_start: 0, num_of_pages: 1,merge_annotations: true)
click to toggle source
# File lib/acrobat/pdoc.rb, line 98 def replace_pages(doc, start: 0, replace_start: 0, num_of_pages: 1,merge_annotations: true) src = open_pdoc(doc) ole_obj.ReplacePages(start,src.ole_obj,replace_start,num_of_pages,merge_annotations) end
save_as(name,dir:nil)
click to toggle source
# File lib/acrobat/pdoc.rb, line 82 def save_as(name,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)
click to toggle source
# File lib/acrobat/pdoc.rb, line 13 def show(name = nil) name = name || ole_obj.GetFileName ole_obj.OpenAVDoc(name) end
Protected Instance Methods
merge_pdoc(doc, **options)
click to toggle source
# File lib/acrobat/pdoc.rb, line 120 def merge_pdoc(doc, **options) begin unless options merged = ole_obj.InsertPages(page_count - 1, doc.ole_obj, 0, doc.page_count, true) return merged else start = options[:start] start_page pages = options[:pages] ole_obj.InsertPages(start, doc.ole_obj, 0, doc.page_count, true) end rescue return false end end