Class: Acrobat::PDoc
- Inherits:
-
Object
- Object
- Acrobat::PDoc
- Defined in:
- lib/acrobat/pdoc.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#ole_obj ⇒ Object
readonly
Returns the value of attribute ole_obj.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
-
#default_dir(dir) ⇒ Object
returns [Pathname] of d @param dir [String, Nil] the String path.
-
#field_names ⇒ Object
return the field_names of the pdf form.
- #fill_and_save(results, name: nil, dir: nil) ⇒ Object
- #fill_form(results) ⇒ Object
-
#initialize(app, ole, path = nil) ⇒ PDoc
constructor
A new instance of PDoc.
- #insert_pages(src:, insert_after: nil, src_page_start: nil, src_page_end: nil) ⇒ Object
-
#jso ⇒ Jso
return the instance of JSO object.
- #last_page ⇒ Object
-
#merge(doc) ⇒ Boolean
merges the doc to the.
- #name ⇒ Object
-
#open_pdoc(doc) ⇒ Object
opens and/or returns PDoc.
-
#page_count ⇒ Fixnum
The number of pages in the pdf.
- #prepend_pages(src_path:, src_page_start: 1, src_page_end: nil) ⇒ Object
- #replace_pages(doc, start: 0, replace_start: 0, num_of_pages: 1, merge_annotations: true) ⇒ Object
- #save_as(name, dir: nil) ⇒ Object
- #show(name = nil) ⇒ Object
Constructor Details
#initialize(app, ole, path = nil) ⇒ PDoc
Returns a new instance of PDoc.
5 6 7 8 9 |
# File 'lib/acrobat/pdoc.rb', line 5 def initialize(app, ole, path = nil) @app = app @ole_obj = ole @path = path end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
3 4 5 |
# File 'lib/acrobat/pdoc.rb', line 3 def app @app end |
#ole_obj ⇒ Object (readonly)
Returns the value of attribute ole_obj.
3 4 5 |
# File 'lib/acrobat/pdoc.rb', line 3 def ole_obj @ole_obj end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/acrobat/pdoc.rb', line 3 def path @path end |
Instance Method Details
#close ⇒ Object
91 92 93 94 95 |
# File 'lib/acrobat/pdoc.rb', line 91 def close ole_obj.Close rescue nil end |
#default_dir(dir) ⇒ Object
returns [Pathname] of d
@param dir [String, Nil] the String path
75 76 77 |
# File 'lib/acrobat/pdoc.rb', line 75 def default_dir(dir) Pathname(dir || Pathname.getw) end |
#field_names ⇒ Object
return the field_names of the pdf form
110 111 112 |
# File 'lib/acrobat/pdoc.rb', line 110 def field_names jso.field_names end |
#fill_and_save(results, name: nil, dir: nil) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/acrobat/pdoc.rb', line 54 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) ⇒ Object
114 115 116 |
# File 'lib/acrobat/pdoc.rb', line 114 def fill_form(results) jso.fill_form(results) end |
#insert_pages(src:, insert_after: nil, src_page_start: nil, src_page_end: nil) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/acrobat/pdoc.rb', line 61 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 ⇒ Jso
return the instance of JSO object
105 106 107 |
# File 'lib/acrobat/pdoc.rb', line 105 def jso @jso ||= Jso.new(self, ole_obj.GetJSObject) end |
#last_page ⇒ Object
21 22 23 |
# File 'lib/acrobat/pdoc.rb', line 21 def last_page page_count(-1) end |
#merge(doc) ⇒ Boolean #merge(doc) ⇒ Boolean
merges the doc to the
31 32 33 34 |
# File 'lib/acrobat/pdoc.rb', line 31 def merge(doc) src = open_pdoc(doc) merge_pdoc(src) end |
#name ⇒ Object
87 88 89 |
# File 'lib/acrobat/pdoc.rb', line 87 def name ole_obj.GetFileName end |
#open(doc) ⇒ Object #open(PDoc]) ⇒ Object
opens and/or returns PDoc
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/acrobat/pdoc.rb', line 42 def open_pdoc(doc) case doc when PDoc doc when String, Pathname docpath = Pathname(doc) raise "File not found" unless docpath.file? app.open(docpath) end end |
#page_count ⇒ Fixnum
Returns the number of pages in the pdf.
17 18 19 |
# File 'lib/acrobat/pdoc.rb', line 17 def page_count ole_obj.GetNumPages() end |
#prepend_pages(src_path:, src_page_start: 1, src_page_end: nil) ⇒ Object
68 69 70 |
# File 'lib/acrobat/pdoc.rb', line 68 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) ⇒ Object
97 98 99 100 101 |
# File 'lib/acrobat/pdoc.rb', line 97 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) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/acrobat/pdoc.rb', line 79 def save_as(name, dir: nil) name ||= path.basename 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
11 12 13 14 |
# File 'lib/acrobat/pdoc.rb', line 11 def show(name = nil) name ||= ole_obj.GetFileName ole_obj.OpenAVDoc(name) end |