acrobat 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cf8c70596499ece879fa4f9fc2479eae8f20d50
4
- data.tar.gz: 248c69e02d4836795c2e812899f77b796431c276
3
+ metadata.gz: 6073a8a04f7af59dd0b8825ff3286975f0197d7d
4
+ data.tar.gz: 6004fca142d6c6856acf3bb83a2c918600ce3458
5
5
  SHA512:
6
- metadata.gz: 7ce98e8d0fa74f6e2c8424ca8176f3812cb659ea668f4276a10c75d00166a91ee8e6d06ac0f08b9075078aafc4b036b793b6e5d48a775eb1f059652cdebc46d7
7
- data.tar.gz: c491c89f2372e5256bb98aebc51d97cd0822c5dc349eb5b2c0f2ae2a8df19b009758c76ba5f9fddc15ba10a79a77a6477b2a2d1affbd318fbf62a7f6ba69b01e
6
+ metadata.gz: 8af177966f67905aba759fbced241768d2da6b5aa6128f531c505c6217d8b63d3893ec3092d88162c2d5d35ece6502f33d4db39d97640f6e3af3e3b4371a6ed8
7
+ data.tar.gz: 3e32a912018fcde36ee7ec584484e1f249313f356d29fa6535ee501052f8475d6248a03ffbe2334ce31a06166eefe3e3e75cdd39273deac5f7222cd5514ddc6c
Binary file
data.tar.gz.sig CHANGED
@@ -1,5 +1 @@
1
-
2
- �����w^���
3
- �Pd�y5�R�k���Ս�m� u�\�-�}�sb�P�TLV�ȶ �[8*F.�
4
- ����R�5�9d�ԧS��
5
- @Tp�\�+q'��J�=�"y}�ߑ����6�u`W)jOX0���
1
+ ��S����y�/��B���wq���Q��1]��XV�Y�L�VG88���9�hi߇ ���R_L,��q�V�>™��?.Eb�
@@ -9,5 +9,7 @@ Rakefile
9
9
  bin/acrobat
10
10
  lib/acrobat.rb
11
11
  lib/acrobat/app.rb
12
+ lib/acrobat/jso.rb
13
+ lib/acrobat/pdoc.rb
12
14
  test/acrobat_test.rb
13
15
  test/test_helper.rb
@@ -19,6 +19,8 @@ Dominic Sisneros <https://github.com/dsisnero[@dsisnero]
19
19
 
20
20
  == DESCRIPTION:
21
21
 
22
+ The acrobat gem is a library that uses WIN32OLE to automate pdf functions. Adobe Reader or Adobe Acrobat must be installed and then you can fill forms and merge documents
23
+
22
24
  == Requirements
23
25
 
24
26
  * Windows Adobe Acrobat installed
@@ -3,5 +3,46 @@ require 'acrobat/app'
3
3
 
4
4
 
5
5
  module Acrobat
6
- VERSION = "0.0.5"
6
+ VERSION = "0.0.7"
7
+ end
8
+
9
+
10
+ if $0 == __FILE__
11
+ require 'pry'
12
+
13
+ app = Acrobat::App.run do |app|
14
+
15
+ data = Pathname(__dir__).parent + 'data'
16
+ antenna_form = data + 'faa.6030.17.antenna.pdf'
17
+
18
+
19
+ doc1 = app.open(antenna_form)
20
+ doc1.show
21
+
22
+ fields = {'city' => 'OGD', 'state' => 'Utah',
23
+ 'lid' => 'OGD',
24
+ 'fac' => 'RTR',
25
+ }
26
+ doc1.fill_form(fields)
27
+
28
+
29
+ doc1.save_as(name: 'ogd.rtr.pdf', dir: 'tmp')
30
+ binding.pry
31
+ jso = doc1.jso
32
+ jso.show_console
33
+ puts "field count: #{jso.field_count}"
34
+ puts "field names: \n#{jso.field_names}"
35
+ binding.pry
36
+
37
+
38
+
39
+ doc2 = app.open(data + 'faa.6030.17.cm300.uhf.tx.pdf')
40
+ doc2.show
41
+ doc2.fill_form(fields)
42
+
43
+ doc1.merge(doc2)
44
+ doc1.save_as(name: 'ogd.merged_antenna_tx.pdf', dir: 'tmp')
45
+
46
+ end
47
+
7
48
  end
@@ -1,5 +1,7 @@
1
1
  require 'pry'
2
2
  require 'win32ole'
3
+ require_relative 'pdoc'
4
+ require_relative 'jso'
3
5
 
4
6
  module FileSystemObject
5
7
 
@@ -73,6 +75,17 @@ module Acrobat
73
75
  Pathname.glob( dir + '*.pdf')
74
76
  end
75
77
 
78
+ def merge_pdfs(*pdfs)
79
+ pdf_array = Array(pdfs)
80
+ raise 'Not enough pdfs to merge' if pdfs.size < 2
81
+ first, *rest = pdf_array
82
+ doc = open(first)
83
+ rest.each do |path|
84
+ doc.merge(path)
85
+ end
86
+ doc
87
+ end
88
+
76
89
  # merges the pdfs in directory
77
90
  # @param dir [String] the path of the directory
78
91
  # @param name [String,Nil] the name of the returned pdf file
@@ -80,21 +93,12 @@ module Acrobat
80
93
  # @param output_dir [String,Nil] the name of the output dir
81
94
  # if the output_dir is nil, the output dir is the dir param
82
95
  # return [Boolean] if the merge was successful or not
83
- def merge_pdfs(dir, name: nil , output_dir: nil)
96
+ def merge_pdfs_in_dir(dir, name: nil , output_dir: nil)
84
97
  name = lname || "merged.pdf"
85
98
  dir = output_dir || dir
86
99
  pdfs = Pathname.glob( dir + '*.pdf')
87
- raise 'Not enough pdfs to merge' if pdfs.size < 2
88
- first, *rest = pdfs
89
- open(first) do |pdf|
90
- rest.each do |path|
91
- open(path) do |pdfnext|
92
- pdf.merge_doc(pdfnext)
93
- end
94
- end
95
-
96
- pdf.save_as(name: name, dir: dir)
97
- end
100
+ doc = merge_pdfs(pdfs)
101
+ doc
98
102
  end
99
103
 
100
104
  # quit the Adobe App.
@@ -128,7 +132,7 @@ module Acrobat
128
132
  begin
129
133
  yield doc
130
134
  ensure
131
- doc.close unless doc.closed?
135
+ doc.close
132
136
  doc = nil
133
137
  end
134
138
  end
@@ -144,271 +148,6 @@ module Acrobat
144
148
  WIN32OLE.const_load(ole_obj, ACRO) unless ACRO.constants.size > 0
145
149
  end
146
150
 
147
-
148
- end
149
-
150
- class PDoc
151
-
152
- attr_reader :app, :ole_obj, :path
153
-
154
- def initialize(app,ole,path=nil)
155
- @app = app
156
- @ole_obj = ole
157
- @path = path
158
- end
159
-
160
- def show(name = nil)
161
- name = name || ole_obj.GetFileName
162
- ole_obj.OpenAVDoc(name)
163
- end
164
-
165
- # @return [Fixnum] the number of pages in the pdf
166
- def page_count
167
- ole_obj.GetNumPages()
168
- end
169
-
170
- # merges the doc to the
171
- # @overload merge(doc)
172
- # @param doc [String] the String path of a pdf file
173
- # @overload merge(doc)
174
- # @param doc [PDoc] an open PDoc to merge
175
- # @return [Boolean] whether the doc was merged correctly
176
- def merge(doc)
177
- case doc
178
- when PDoc
179
- merge_pdoc(doc)
180
- when String, Pathname
181
- docpath = Pathname(doc)
182
- raise 'File not found' unless docpath.file?
183
- doc2 = app.open(docpath)
184
- merge_pdoc(doc2)
185
- end
186
- end
187
-
188
- def update_form(results)
189
- form.update(results)
190
- end
191
-
192
- def update_and_save(results,name: nil, dir: nil)
193
- update_form(results)
194
- is_saved = save_as(name: name, dir: dir)
195
- puts "saved file: %s" % [dir + name] if is_saved
196
- end
197
-
198
- def default_dir(d)
199
- Pathname(dir || Pathname.getw)
200
- end
201
-
202
-
203
- def save_as(name:nil, dir:nil)
204
- name = path.basename unless name
205
- dir = Pathname(dir || Pathname.getwd)
206
- dir.mkpath
207
- windows_path = FileSystemObject.windows_path(dir + name )
208
- ole_obj.save(ACRO::PDSaveFull | ACRO::PDSaveCopy,windows_path)
209
- end
210
-
211
- def name
212
- ole_obj.GetFileName
213
- end
214
-
215
- def close
216
- ole_obj.Close
217
- end
218
-
219
-
220
- def jso
221
- @jso ||= Jso.new(ole_obj.GetJSObject)
222
- end
223
-
224
- def field_names
225
- jso.field_names
226
- end
227
-
228
- def fill_form(results)
229
- jso.fill_form(results)
230
- end
231
-
232
- protected
233
- def merge_pdoc(doc)
234
- ole_obj.InsertPages(page_count - 1, doc.ole_obj, 0, doc.page_count, true)
235
- end
236
-
237
- end
238
-
239
- class Jso
240
-
241
- attr_reader :ole_obj
242
-
243
- def initialize(ole)
244
- @ole_obj = ole
245
- end
246
-
247
- def find_field(name_or_number)
248
- case name_or_number
249
- when String,Symbol
250
- ole_get_field(name_or_number.to_s)
251
- when Number
252
- ole_get_field(name_or_number)
253
- end
254
- end
255
-
256
- def ole_get_field(field)
257
- ole_obj.getField(field)
258
- end
259
-
260
- def console
261
- @console ||= ole_obj.console
262
- end
263
-
264
- def field_names
265
- result = []
266
- 0.upto(field_count -1) do |i|
267
- result << ole_obj.getNthFieldName(i)
268
- end
269
- result
270
- end
271
-
272
- def set_field(name,value)
273
- field = find_field(name)
274
- field.Value = value if field
275
- end
276
-
277
- def get_field(name)
278
- field = find_field(name)
279
- field.Value if field
280
- end
281
-
282
- def field_count
283
- ole_obj.numFields
284
- end
285
-
286
- def clear_form
287
- ole_obj.resetForm
288
- end
289
-
290
- def fill_form(hash)
291
- clear_form
292
- hash.each do |k,v|
293
- set_field(k,v)
294
- end
295
- end
296
-
297
- end
298
-
299
-
300
- class Form
301
-
302
- attr_reader :app, :ole_obj
303
-
304
- def initialize(app, ole_obj)
305
- @app = app
306
- @ole_obj = ole_obj
307
- end
308
-
309
- def ole_fields
310
- @ole_obj.fields
311
- end
312
-
313
- def [](name)
314
- ole = get_name(name)
315
- ole.value if ole
316
- end
317
-
318
- def get_name(name)
319
- ole_obj.fields.Item(name.to_s) rescue nil
320
- end
321
-
322
- def []=(name,value)
323
- ole = get_name(name.to_s)
324
- ole.Value = value if ole
325
- end
326
-
327
- def update(hash)
328
- hash.each do |k,v|
329
- self[k.to_s] = v
330
- end
331
-
332
- end
333
-
334
- def to_hash
335
- result = {}
336
- ole_obj.fields.each do |fld|
337
- result[fld.Name] = fld.value
338
- end
339
- result
340
- end
341
- end
342
-
343
-
344
-
345
- end
346
-
347
- if $0 == __FILE__
348
- require 'pry'
349
-
350
- app = Acrobat::App.run do |app|
351
-
352
- data = Pathname(__dir__).parent.parent + 'data'
353
- antenna_form = data + 'faa.6030.17.antenna.pdf'
354
-
355
-
356
- doc1 = app.open(antenna_form)
357
- doc1.show
358
-
359
- fields = {'city' => 'OGD', 'state' => 'Utah',
360
- 'lid' => 'OGD',
361
- 'fac' => 'RTR',
362
- }
363
- doc1.fill_form(fields)
364
-
365
-
366
- doc1.save_as(name: 'ogd.rtr.pdf', dir: 'tmp')
367
-
368
-
369
-
370
-
371
- doc2 = app.open(data + 'faa.6030.17.cm300.uhf.tx.pdf')
372
- doc2.show
373
- doc2.fill_form(fields)
374
-
375
- doc1.merge(doc2)
376
- doc1.save_as(name: 'ogd.merged_antenna_tx.pdf', dir: 'tmp')
377
-
378
151
  end
379
152
 
380
153
  end
381
-
382
-
383
-
384
- # ublic Sub Main()
385
- # Dim AcroApp As Acrobat.CAcroApp
386
- # Dim AvDoc As Acrobat.CAcroAVDoc
387
- # Dim fcount As Long
388
- # Dim sFieldName As String
389
- # Dim Field As AFORMAUTLib.Field
390
- # Dim Fields As AFORMAUTLib.Fields
391
- # Dim AcroForm As AFORMAUTLib.AFormApp
392
-
393
- # Set AcroApp = CreateObject("AcroExch.App")
394
- # Set AvDoc = CreateObject("AcroExch.AVDoc")
395
-
396
- # If AvDoc.Open("C:\test\testform.pdf", "") Then
397
- # AcroApp.Show
398
- # Set AcroForm = CreateObject("AFormAut.App")
399
- # Set Fields = AcroForm.Fields
400
- # fcount = Fields.Count
401
- # MsgBox fcount
402
- # For Each Field In Fields
403
- # sFieldName = Field.Name
404
- # MsgBox sFieldName
405
- # Next Field
406
- # Else
407
- # MsgBox "failure"
408
- # End If
409
- # AcroApp.Exit
410
- # Set AcroApp = Nothing
411
- # Set AvDoc = Nothing
412
- # Set Field = Nothing
413
- # Set Fields = Nothing
414
- # Set AcroForm = Nothing
@@ -0,0 +1,94 @@
1
+ module Acrobat
2
+
3
+ class Jso
4
+
5
+ attr_reader :doc, :ole_obj
6
+
7
+ def initialize(doc,ole)
8
+ @doc = doc
9
+ @ole_obj = ole
10
+ end
11
+
12
+ def find_field(name_or_number)
13
+ case name_or_number
14
+ when String,Symbol
15
+ ole_get_field(name_or_number.to_s)
16
+ when Number
17
+ ole_get_field(name_or_number)
18
+ end
19
+ end
20
+
21
+ def ole_get_field(field)
22
+ ole_obj.getField(field)
23
+ end
24
+
25
+ def console
26
+ @console ||= ole_obj.console
27
+ end
28
+
29
+ def show_console
30
+ console.show
31
+ end
32
+
33
+ def field_names
34
+ result = []
35
+ count = field_count
36
+ 0.upto(count-1) do |i|
37
+ result << ole_obj.getNthFieldName(i)
38
+ end
39
+ result
40
+ end
41
+
42
+ def export_as_fdf(name)
43
+ end
44
+
45
+ def import_fdf(path)
46
+ end
47
+
48
+
49
+ def fields_hash
50
+ result = {}
51
+ field_names.each_with_object( result ) do |name, h|
52
+ h[name] = get_field(name)
53
+ end
54
+ end
55
+
56
+
57
+ # // Enumerate through all of the fields in the document.
58
+ # for (var i = 0; i < this.numFields; i++)
59
+ # console.println("Field[" + i + "] = " + this.getNthFieldName(i));
60
+
61
+ def set_field(name,value)
62
+ begin
63
+ field = find_field(name)
64
+ field.Value = value.to_s if field
65
+ rescue
66
+ require 'pry'
67
+ binding.pry
68
+ nil
69
+ end
70
+ end
71
+
72
+ def get_field(name)
73
+ field = find_field(name)
74
+ field.Value if field
75
+ end
76
+
77
+ def field_count
78
+ ole_obj.numFields().to_int
79
+ end
80
+
81
+ def clear_form
82
+ ole_obj.resetForm
83
+ end
84
+
85
+ def fill_form(hash)
86
+ clear_form
87
+ hash.each do |k,v|
88
+ set_field(k,v)
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ end
@@ -0,0 +1,92 @@
1
+ module Acrobat
2
+
3
+ class PDoc
4
+
5
+ attr_reader :app, :ole_obj, :path
6
+
7
+ def initialize(app,ole,path=nil)
8
+ @app = app
9
+ @ole_obj = ole
10
+ @path = path
11
+ end
12
+
13
+ def show(name = nil)
14
+ name = name || ole_obj.GetFileName
15
+ ole_obj.OpenAVDoc(name)
16
+ end
17
+
18
+ # @return [Fixnum] the number of pages in the pdf
19
+ def page_count
20
+ ole_obj.GetNumPages()
21
+ end
22
+
23
+ # merges the doc to the
24
+ # @overload merge(doc)
25
+ # @param doc [String] the String path of a pdf file
26
+ # @overload merge(doc)
27
+ # @param doc [PDoc] an open PDoc to merge
28
+ # @return [Boolean] whether the doc was merged correctly
29
+ def merge(doc)
30
+ case doc
31
+ when PDoc
32
+ merge_pdoc(doc)
33
+ when String, Pathname
34
+ docpath = Pathname(doc)
35
+ raise 'File not found' unless docpath.file?
36
+ doc2 = app.open(docpath)
37
+ merge_pdoc(doc2)
38
+ end
39
+ end
40
+
41
+ def fill_and_save(results,name: nil, dir: nil)
42
+ fill_form(results)
43
+ is_saved = save_as(name: name, dir: dir)
44
+ puts "saved file: %s" % [dir + name] if is_saved
45
+ true
46
+ end
47
+
48
+ def default_dir(d)
49
+ Pathname(dir || Pathname.getw)
50
+ end
51
+
52
+ def save_as(name:nil, dir:nil)
53
+ name = path.basename unless name
54
+ dir = Pathname(dir || Pathname.getwd)
55
+ dir.mkpath
56
+ windows_path = FileSystemObject.windows_path(dir + name )
57
+ ole_obj.save(ACRO::PDSaveFull | ACRO::PDSaveCopy,windows_path)
58
+ end
59
+
60
+ def name
61
+ ole_obj.GetFileName
62
+ end
63
+
64
+ def close
65
+ ole_obj.Close rescue nil
66
+ end
67
+
68
+
69
+ def jso
70
+ @jso ||= Jso.new(self,ole_obj.GetJSObject)
71
+ end
72
+
73
+ def field_names
74
+ jso.field_names
75
+ end
76
+
77
+ def fill_form(results)
78
+ jso.fill_form(results)
79
+ end
80
+
81
+ protected
82
+ def merge_pdoc(doc)
83
+ begin
84
+ merged = ole_obj.InsertPages(page_count - 1, doc.ole_obj, 0, doc.page_count, true)
85
+ return merged
86
+ rescue
87
+ return false
88
+ end
89
+ end
90
+ end
91
+
92
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acrobat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Sisneros
@@ -186,7 +186,10 @@ dependencies:
186
186
  - - "~>"
187
187
  - !ruby/object:Gem::Version
188
188
  version: '3.16'
189
- description: ''
189
+ description: |-
190
+ <div class="paragraph">
191
+ <p>The acrobat gem is a library that uses WIN32OLE to automate pdf functions. Adobe Reader or Adobe Acrobat must be installed and then you can fill forms and merge documents</p>
192
+ </div>
190
193
  email:
191
194
  - dsisnero@gmail.com
192
195
  executables:
@@ -207,6 +210,8 @@ files:
207
210
  - bin/acrobat
208
211
  - lib/acrobat.rb
209
212
  - lib/acrobat/app.rb
213
+ - lib/acrobat/jso.rb
214
+ - lib/acrobat/pdoc.rb
210
215
  - test/acrobat_test.rb
211
216
  - test/test_helper.rb
212
217
  homepage: https://github.com/dsisnero/acrobat
@@ -235,5 +240,6 @@ rubyforge_project:
235
240
  rubygems_version: 2.6.10
236
241
  signing_key:
237
242
  specification_version: 4
238
- summary: ''
243
+ summary: <div class="paragraph"> <p>The acrobat gem is a library that uses WIN32OLE
244
+ to automate pdf functions
239
245
  test_files: []
metadata.gz.sig CHANGED
Binary file