pdf-forms 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pdf_forms/pdf.rb +1 -0
- data/lib/pdf_forms/pdftk_wrapper.rb +18 -4
- data/lib/pdf_forms/version.rb +1 -1
- metadata +2 -2
data/lib/pdf_forms/pdf.rb
CHANGED
@@ -8,7 +8,7 @@ module PdfForms
|
|
8
8
|
|
9
9
|
attr_reader :pdftk, :options
|
10
10
|
|
11
|
-
# PdftkWrapper.new('/usr/bin/pdftk', :encrypt => true, :encrypt_options => 'allow Printing')
|
11
|
+
# PdftkWrapper.new('/usr/bin/pdftk', :flatten => true, :encrypt => true, :encrypt_options => 'allow Printing')
|
12
12
|
def initialize(pdftk_path, options = {})
|
13
13
|
@pdftk = pdftk_path
|
14
14
|
@options = options
|
@@ -20,7 +20,7 @@ module PdfForms
|
|
20
20
|
tmp = Tempfile.new('pdf_forms-fdf')
|
21
21
|
tmp.close
|
22
22
|
fdf.save_to tmp.path
|
23
|
-
command = pdftk_command %Q("#{template}"), 'fill_form', tmp.path, 'output', destination,
|
23
|
+
command = pdftk_command %Q("#{template}"), 'fill_form', %Q("#{tmp.path}"), 'output', %Q("#{destination}"), add_options(tmp.path)
|
24
24
|
output = %x{#{command}}
|
25
25
|
unless File.readable?(destination) && File.size(destination) > 0
|
26
26
|
raise PdftkError.new("failed to fill form with command\n#{command}\ncommand output was:\n#{output}")
|
@@ -43,17 +43,31 @@ module PdfForms
|
|
43
43
|
%x{#{pdftk_command args}}
|
44
44
|
end
|
45
45
|
|
46
|
+
def cat(*files,output)
|
47
|
+
files = files[0] if files[0].class == Array
|
48
|
+
input = files.map{|f| %Q("#{f}")}
|
49
|
+
call_pdftk(*input,'output',output)
|
50
|
+
end
|
51
|
+
|
46
52
|
protected
|
47
53
|
|
48
54
|
def pdftk_command(*args)
|
49
55
|
"#{pdftk} #{args.flatten.compact.join ' '} 2>&1"
|
50
56
|
end
|
51
57
|
|
52
|
-
def
|
58
|
+
def add_options(pwd)
|
59
|
+
return if options.empty?
|
60
|
+
opt_args = []
|
61
|
+
if options[:flatten]
|
62
|
+
opt_args << 'flatten'
|
63
|
+
end
|
53
64
|
if options[:encrypt]
|
54
|
-
['encrypt_128bit', 'owner_pw', pwd, options[:encrypt_options]]
|
65
|
+
opt_args.concat ['encrypt_128bit', 'owner_pw', pwd, options[:encrypt_options]]
|
55
66
|
end
|
67
|
+
opt_args
|
56
68
|
end
|
57
69
|
|
70
|
+
|
71
|
+
|
58
72
|
end
|
59
73
|
end
|
data/lib/pdf_forms/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pdf-forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.4.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Jens Kr\xC3\xA4mer"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-04
|
13
|
+
date: 2012-07-04 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Fill out PDF forms with pdftk (http://www.accesspdf.com/pdftk/).
|