jasper-command-line 0.2.2 → 0.2.3

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/Gemfile CHANGED
@@ -4,4 +4,5 @@ gemspec
4
4
 
5
5
  gem 'activesupport', '>= 3.2.0'
6
6
  gem 'rjb', '>= 1.4.0'
7
- gem 'builder', '>= 3.0.3'
7
+ gem 'builder', '>= 3.0.3'
8
+ gem 'pdf-merger', '>= 0.3.1'
data/README.md CHANGED
@@ -15,6 +15,7 @@ It also embeds the .jar files needed to digitally sign the PDF, if necessary. Th
15
15
  * [rjb](http://rjb.rubyforge.org/) >= 1.4.0
16
16
  * [builder](https://rubygems.org/gems/builder) >= 3.0.3
17
17
  * [activesupport](https://rubygems.org/gems/activesupport) >= 3.2.0
18
+ * [pdf-merger](https://github.com/paulschreiber/pdf-merger) >= 0.3.1
18
19
 
19
20
  ## Install
20
21
 
@@ -40,6 +41,7 @@ Options:
40
41
  compiled from the .jrxml file with the same name and
41
42
  on the same location)
42
43
  --data-file /path/to/file The .xml file to load the data from
44
+ --copies number The number of copies to generate
43
45
  --param key=value Adds the parameter with name key with the value value
44
46
  (can be defined multiple times)
45
47
 
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency('rjb', '>= 1.4.0')
17
17
  s.add_dependency('builder', '>= 3.0.3')
18
18
  s.add_dependency('activesupport', '>= 3.2.0')
19
+ s.add_dependency('pdf-merger', '>= 0.3.1')
19
20
  s.add_development_dependency("rspec", "~> 2.7")
20
21
  s.add_development_dependency("rake", "~> 0.9.2")
21
22
 
@@ -15,6 +15,7 @@ module JasperCommandLine
15
15
  puts " compiled from the .jrxml file with the same name and"
16
16
  puts " on the same location)"
17
17
  puts "--data-file /path/to/file The .xml file to load the data from"
18
+ puts "--copies number The number of copies to generate"
18
19
  puts "--param key=value Adds the parameter with name key with the value value"
19
20
  puts " (can be defined multiple times)"
20
21
  puts ""
@@ -81,12 +82,17 @@ module JasperCommandLine
81
82
  end
82
83
 
83
84
  when 'jasper'
84
- # Or a file
85
85
  i = get_option_data(arguments, i) do |argument_data|
86
86
  raise ArgumentError.new("File not found: #{argument_data}") unless File.exists?(argument_data) || File.exists?(argument_data.gsub(/\.jasper$/, '.jrxml'))
87
87
  data[:jasper_file] = argument_data
88
88
  end
89
89
 
90
+ when 'copies'
91
+ i = get_option_data(arguments, i) do |argument_data|
92
+ raise ArgumentError.new("Invalid number of copies: #{argument_data}") unless argument_data =~ /^[1-9][0-9]*$/
93
+ data[:copies] = argument_data.to_i
94
+ end
95
+
90
96
  when 'sign-key-file'
91
97
  # Sign document with file
92
98
  i = get_option_data(arguments, i) do |argument_data|
@@ -81,21 +81,43 @@ module JasperCommandLine
81
81
  end
82
82
 
83
83
  jasper_params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, data_document)
84
- jasper_print = JasperFillManager.fillReport(jasper_file, jasper_params)
85
84
 
86
- # Export it!
85
+ temp_file = Tempfile.new(['pdf-', '.pdf'])
86
+ file = temp_file.path
87
+ temp_file.close!
87
88
 
89
+ created_files = [file]
90
+
91
+ pdf = PDF::Merger.new
92
+
93
+ # Export n copies and merge them into one file
94
+ options[:copies] ||= 1
95
+
96
+ (1..options[:copies]).each do |copy|
97
+ copy_temp_file = Tempfile.new(["pdf-#{copy}-", '.pdf'])
98
+ copy_file = copy_temp_file.path
99
+ copy_temp_file.close!
100
+
101
+ jasper_params.put JavaString.new('copy_number'), JavaString.new(copy.to_s)
102
+ jasper_print = JasperFillManager.fillReport(jasper_file, jasper_params)
103
+
104
+ File.open(copy_file, 'wb') { |f| f.write JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print) }
105
+
106
+ pdf.add_file copy_file
107
+
108
+ created_files << copy_file
109
+ end
110
+
111
+ pdf.save_as file
112
+
113
+ # Digitally sign the file, if necessary
88
114
  if sign_options
89
- temp_file = Tempfile.new(['pdf-', '.pdf'])
90
115
  temp_signed_file = Tempfile.new(['signed-pdf-', '.pdf'])
91
- file = temp_file.path
92
116
  signed_file = temp_signed_file.path
93
117
 
94
118
  temp_file.close!
95
119
  temp_signed_file.close!
96
120
 
97
- File.open(file, 'wb') { |f| f.write JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print) }
98
-
99
121
  call_options = [
100
122
  '-n',
101
123
  '-t', file,
@@ -108,16 +130,20 @@ module JasperCommandLine
108
130
 
109
131
  `java -jar #{File.dirname(__FILE__)}/java/PortableSigner/PortableSigner.jar #{call_options.join(' ')}`
110
132
 
133
+
134
+ created_files << signed_file
135
+ else
136
+ signed_file = file
137
+ end
138
+
139
+ begin
140
+ return File.read(signed_file)
141
+ ensure
111
142
  begin
112
- return File.read(signed_file)
113
- ensure
114
- begin
115
- File.unlink file, signed_file
116
- rescue
117
- end
143
+ File.unlink *created_files
144
+ rescue => e
145
+ puts e.message
118
146
  end
119
- else
120
- JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print)
121
147
  end
122
148
 
123
149
  rescue Exception=>e
@@ -1,3 +1,3 @@
1
1
  module JasperCommandLine
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -7,6 +7,7 @@ require 'tempfile'
7
7
  require 'jasper-command-line/version'
8
8
  require 'jasper-command-line/command_line'
9
9
  require 'jasper-command-line/jasper'
10
+ require 'pdf/merger'
10
11
 
11
12
  module JasperCommandLine
12
13
  def self.logger=(log)
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.2.2
4
+ version: 0.2.3
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-04 00:00:00.000000000 Z
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rjb
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.2.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: pdf-merger
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.3.1
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.3.1
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: rspec
64
80
  requirement: !ruby/object:Gem::Requirement