jasper-command-line 0.1.4 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -0
- data/lib/jasper-command-line.rb +1 -1
- data/lib/jasper-command-line/command_line.rb +49 -1
- data/lib/jasper-command-line/jasper.rb +31 -1
- data/lib/jasper-command-line/java/PortableSigner/PortableSigner.jar +0 -0
- data/lib/jasper-command-line/java/PortableSigner/lib/bcprov-ext-jdk15-143.jar +0 -0
- data/lib/jasper-command-line/java/PortableSigner/lib/commons-cli-1.2.jar +0 -0
- data/lib/jasper-command-line/java/PortableSigner/lib/iText-2.1.7.jar +0 -0
- data/lib/jasper-command-line/java/PortableSigner/lib/quaqua.jar +0 -0
- data/lib/jasper-command-line/java/PortableSigner/lib/swing-layout-1.0.3.jar +0 -0
- data/lib/jasper-command-line/version.rb +1 -1
- metadata +8 -2
data/README.md
CHANGED
@@ -7,6 +7,8 @@ Print a jasper document via the command line
|
|
7
7
|
|
8
8
|
This gem embeds the .jar files provided by [jasper-rails](https://github.com/fortesinformatica/jasper-rails), so you don't need to include the gem ([jasper-rails](https://github.com/fortesinformatica/jasper-rails) requires the whole Ruby on Rails framework, which isn't necessary in this case).
|
9
9
|
|
10
|
+
It also embeds the .jar files needed to digitally sign the PDF, if necessary. The PDF files are signed using [PortableSigner](http://portablesigner.sourceforge.net) by [Peter Pfläging](peter.pflaeging@wien.gv.at). All credit for the digital signature code goes to him.
|
11
|
+
|
10
12
|
## Dependencies
|
11
13
|
|
12
14
|
* You need a Java Virtual Machine installed and set up in order to use this gem.
|
@@ -40,6 +42,13 @@ Options:
|
|
40
42
|
--data-file /path/to/file The .xml file to load the data from
|
41
43
|
--param key=value Adds the parameter with name key with the value value
|
42
44
|
(can be defined multiple times)
|
45
|
+
|
46
|
+
Digital signature options:
|
47
|
+
--sign-key-file /path/to/file The location of the PKCS12 file to
|
48
|
+
digitally sign the PDF with
|
49
|
+
--sign-password password The password for the PKCS12 file
|
50
|
+
--sign-location location The location of the signature
|
51
|
+
--sign-reason reason The reason for signing the PDF
|
43
52
|
```
|
44
53
|
## LICENSE
|
45
54
|
|
data/lib/jasper-command-line.rb
CHANGED
@@ -17,9 +17,26 @@ module JasperCommandLine
|
|
17
17
|
puts "--data-file /path/to/file The .xml file to load the data from"
|
18
18
|
puts "--param key=value Adds the parameter with name key with the value value"
|
19
19
|
puts " (can be defined multiple times)"
|
20
|
+
puts ""
|
21
|
+
puts "Digital signature options:"
|
22
|
+
puts "--sign-key-file /path/to/file The location of the PKCS12 file to"
|
23
|
+
puts " digitally sign the PDF with"
|
24
|
+
puts "--sign-password password The password for the PKCS12 file"
|
25
|
+
puts "--sign-location location The location of the signature"
|
26
|
+
puts "--sign-reason reason The reason for signing the PDF"
|
20
27
|
else
|
21
28
|
if options[:jasper_file]
|
22
|
-
|
29
|
+
jasper_file = options.delete :jasper_file
|
30
|
+
data = options.delete :data
|
31
|
+
params = options.delete :params
|
32
|
+
|
33
|
+
if options[:signature]
|
34
|
+
if options[:signature][:key_file] && !options[:signature][:password]
|
35
|
+
raise ArgumentError.new("Password not supplied for certificate")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
puts JasperCommandLine::Jasper::render_pdf(jasper_file, data, params, options)
|
23
40
|
end
|
24
41
|
end
|
25
42
|
rescue ArgumentError => e
|
@@ -70,6 +87,37 @@ module JasperCommandLine
|
|
70
87
|
data[:jasper_file] = argument_data
|
71
88
|
end
|
72
89
|
|
90
|
+
when 'sign-key-file'
|
91
|
+
# Sign document with file
|
92
|
+
i = get_option_data(arguments, i) do |argument_data|
|
93
|
+
raise ArgumentError.new("Signature key file not found: #{argument_data}") unless File.exists?(argument_data)
|
94
|
+
data[:signature] ||= {}
|
95
|
+
data[:signature][:key_file] = argument_data
|
96
|
+
end
|
97
|
+
|
98
|
+
when 'sign-location'
|
99
|
+
# Location to set on the signature
|
100
|
+
i = get_option_data(arguments, i) do |argument_data|
|
101
|
+
data[:signature] ||= {}
|
102
|
+
data[:signature][:location] = argument_data
|
103
|
+
end
|
104
|
+
|
105
|
+
when 'sign-password'
|
106
|
+
# Password to open the signature key file
|
107
|
+
i = get_option_data(arguments, i) do |argument_data|
|
108
|
+
data[:signature] ||= {}
|
109
|
+
data[:signature][:password] = argument_data
|
110
|
+
end
|
111
|
+
|
112
|
+
when 'sign-reason'
|
113
|
+
# Reason to set on the signature
|
114
|
+
i = get_option_data(arguments, i) do |argument_data|
|
115
|
+
data[:signature] ||= {}
|
116
|
+
data[:signature][:reason] = argument_data
|
117
|
+
end
|
118
|
+
|
119
|
+
else
|
120
|
+
i += 1
|
73
121
|
end
|
74
122
|
end
|
75
123
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
#
|
2
3
|
# Copyright (C) 2012 Marlus Saraiva, Rodrigo Maia
|
3
4
|
#
|
@@ -54,6 +55,8 @@ module JasperCommandLine
|
|
54
55
|
parameters ||= {}
|
55
56
|
jrxml_file = jasper_file.sub(/\.jasper$/, ".jrxml")
|
56
57
|
|
58
|
+
sign_options = options.delete(:signature)
|
59
|
+
|
57
60
|
begin
|
58
61
|
# Convert the ruby parameters' hash to a java HashMap.
|
59
62
|
# Pay attention that, for now, all parameters are converted to string!
|
@@ -81,7 +84,34 @@ module JasperCommandLine
|
|
81
84
|
jasper_print = JasperFillManager.fillReport(jasper_file, jasper_params)
|
82
85
|
|
83
86
|
# Export it!
|
84
|
-
|
87
|
+
|
88
|
+
if sign_options
|
89
|
+
file = Tempfile.new(['pdf-', '.pdf'])
|
90
|
+
signed_file = Tempfile.new(['signed-pdf-', '.pdf'])
|
91
|
+
begin
|
92
|
+
file.write JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print)
|
93
|
+
|
94
|
+
call_options = [
|
95
|
+
'-n',
|
96
|
+
'-t', file.path,
|
97
|
+
'-s', sign_options[:key_file],
|
98
|
+
'-p', %Q["#{sign_options[:password]}"],
|
99
|
+
'-o', signed_file.path
|
100
|
+
]
|
101
|
+
call_options.push '-l', %Q["#{sign_options[:location]}"] if sign_options[:location]
|
102
|
+
call_options.push '-r', %Q["#{sign_options[:reason]}"] if sign_options[:reason]
|
103
|
+
|
104
|
+
`java -jar #{File.dirname(__FILE__)}/java/PortableSigner/PortableSigner.jar #{call_options.join(' ')}`
|
105
|
+
|
106
|
+
return File.read(signed_file.path)
|
107
|
+
ensure
|
108
|
+
file.close!
|
109
|
+
signed_file.close!
|
110
|
+
end
|
111
|
+
else
|
112
|
+
JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print)
|
113
|
+
end
|
114
|
+
|
85
115
|
rescue Exception=>e
|
86
116
|
if e.respond_to? 'printStackTrace'
|
87
117
|
JasperCommandLine.logger.error e.message
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jasper-command-line
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rjb
|
@@ -109,6 +109,12 @@ files:
|
|
109
109
|
- lib/jasper-command-line.rb
|
110
110
|
- lib/jasper-command-line/command_line.rb
|
111
111
|
- lib/jasper-command-line/jasper.rb
|
112
|
+
- lib/jasper-command-line/java/PortableSigner/PortableSigner.jar
|
113
|
+
- lib/jasper-command-line/java/PortableSigner/lib/bcprov-ext-jdk15-143.jar
|
114
|
+
- lib/jasper-command-line/java/PortableSigner/lib/commons-cli-1.2.jar
|
115
|
+
- lib/jasper-command-line/java/PortableSigner/lib/iText-2.1.7.jar
|
116
|
+
- lib/jasper-command-line/java/PortableSigner/lib/quaqua.jar
|
117
|
+
- lib/jasper-command-line/java/PortableSigner/lib/swing-layout-1.0.3.jar
|
112
118
|
- lib/jasper-command-line/java/commons-beanutils-1.8.2.jar
|
113
119
|
- lib/jasper-command-line/java/commons-collections-3.2.1.jar
|
114
120
|
- lib/jasper-command-line/java/commons-digester-2.1.jar
|