acts_as_flying_saucer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +17 -15
- data/Rakefile +6 -0
- data/acts_as_flying_saucer.gemspec +1 -1
- data/lib/acts_as_flying_saucer/config.rb +25 -4
- data/lib/acts_as_flying_saucer/version.rb +1 -1
- data/lib/acts_as_flying_saucer/xhtml2pdf.rb +3 -2
- data/lib/acts_as_flying_saucer.rb +1 -0
- metadata +19 -6
data/README.markdown
CHANGED
@@ -99,7 +99,7 @@ Sinatra
|
|
99
99
|
html_content = erb :index
|
100
100
|
render_pdf(:template=>html_content,:pdf_file=>"test.pdf",
|
101
101
|
:send_file=> {:file_name=>"test.pdf",:stream=>false},:password=>"xxx")
|
102
|
-
|
102
|
+
end
|
103
103
|
Ruby
|
104
104
|
----
|
105
105
|
class Pdf
|
@@ -119,35 +119,37 @@ These are the default settings which can be overwritten in your enviroment confi
|
|
119
119
|
:classpath_separator => ':', # classpath separator. unixes system use ':' and windows ';'
|
120
120
|
:tmp_path => "/tmp", # path where temporary files will be stored
|
121
121
|
:max_memory_mb=>512,
|
122
|
-
:nailgun =>false
|
122
|
+
:nailgun =>false,
|
123
|
+
:nailgun_port => '2113',
|
124
|
+
:nailgun_host => 'localhost'
|
123
125
|
}
|
124
126
|
|
125
127
|
|
126
128
|
Advance Configuration (TODO: Manually)
|
127
129
|
-------------------
|
128
|
-
Now acts_as_flying_saucer call java each time on creating pdf this will speed down speed of
|
130
|
+
Now acts_as_flying_saucer call java each time on creating pdf this will speed down speed of generation of pdf.To overcome this start nailgun server that reads data from specific port and rendered pdf.so there is no need to launch the jvm every time a new pdf is generated.
|
131
|
+
Generate pdf with nailgun you have to overwrite Configuration make **nailgun option to true**
|
132
|
+
|
129
133
|
|
130
|
-
So to start nailgun with acts_as_flying_saucer
|
134
|
+
So to start nailgun with acts_as_flying_saucer gem:
|
131
135
|
|
132
136
|
<code>
|
133
|
-
|
137
|
+
sudo gem install nailgun
|
134
138
|
</code>
|
135
139
|
|
136
140
|
Start nailgun server.Before starting nailgun server make sure that your **classpath environment variable** set and point to jre/lib
|
137
141
|
|
142
|
+
On startup or manually write following line
|
143
|
+
You can write into config/initializers/
|
144
|
+
After setting nailgun host and port
|
138
145
|
<code>
|
139
|
-
|
140
|
-
</code>
|
141
|
-
<code>
|
142
|
-
rake nailgun
|
146
|
+
ActsAsFlyingSaucer::Config.setup_nailgun
|
143
147
|
</code>
|
144
|
-
Generate pdf with nailgun you have to overwrite Configuration make **nailgun option to true**
|
145
|
-
Now after making nailgun option true run
|
146
|
-
|
147
|
-
<code>rake acts_as_flying_saucer</code>
|
148
148
|
|
149
|
+
You can Manage nailgun using
|
149
150
|
<code>
|
150
|
-
|
151
|
+
nailgun
|
151
152
|
</code>
|
153
|
+
It will generate nailgun_config binary and set configuration parameter
|
154
|
+
and now you can start and stop nailgun server
|
152
155
|
|
153
|
-
Now you are ready with nailgun.
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "http://rubygems.org/gems/acts_as_flying_saucer"
|
12
12
|
s.summary = %q{XHTML to PDF using Flying Saucer java library}
|
13
13
|
s.description = %q{XHTML to PDF using Flying Saucer java library}
|
14
|
-
|
14
|
+
s.add_dependency "nailgun"
|
15
15
|
s.rubyforge_project = "acts_as_flying_saucer"
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split("\n")
|
@@ -4,17 +4,38 @@ module ActsAsFlyingSaucer
|
|
4
4
|
# default options
|
5
5
|
class << self
|
6
6
|
attr_accessor :options
|
7
|
+
|
7
8
|
end
|
8
9
|
ActsAsFlyingSaucer::Config.options = {
|
9
10
|
:java_bin => "java",
|
10
11
|
:classpath_separator => ':',
|
11
12
|
:tmp_path => "/tmp",
|
12
13
|
:run_mode => :once,
|
13
|
-
:max_memory_mb =>
|
14
|
-
:nailgun=> false
|
14
|
+
:max_memory_mb => 50,
|
15
|
+
:nailgun=> false,
|
16
|
+
:nailgun_port => '2113',
|
17
|
+
:nailgun_host => 'localhost',
|
15
18
|
}
|
16
|
-
|
17
|
-
|
19
|
+
def self.setup_nailgun
|
20
|
+
if ActsAsFlyingSaucer::Config.options[:nailgun]
|
21
|
+
Nailgun::NailgunConfig.options= {
|
22
|
+
:java_bin => ActsAsFlyingSaucer::Config.options[:java_bin],
|
23
|
+
:server_address => ActsAsFlyingSaucer::Config.options[:nailgun_host],
|
24
|
+
:port_no=>ActsAsFlyingSaucer::Config.options[:nailgun_port]
|
25
|
+
}
|
26
|
+
Nailgun::NailgunServer.new(["start"]).daemonize
|
27
|
+
count =0
|
28
|
+
while(!system("lsof -i -n -P|grep #{ActsAsFlyingSaucer::Config.options[:nailgun_port]}") && count<9)
|
29
|
+
sleep(1)
|
30
|
+
count+=1
|
31
|
+
end
|
32
|
+
acts_as_flying_saucer_jar_path = File.expand_path(File.join(File.dirname(__FILE__),'java','jar','acts_as_flying_saucer.jar'))
|
33
|
+
# ADD IN NAILGUN CLASS
|
34
|
+
Nailgun::NgCommand.ng_cp(acts_as_flying_saucer_jar_path)
|
35
|
+
Nailgun::NgCommand.ng_alias("Xhtml2Pdf","acts_as_flying_saucer.Xhtml2Pdf")
|
36
|
+
Nailgun::NgCommand.ng_alias("encryptPdf", "acts_as_flying_saucer.encryptPdf")
|
37
|
+
|
38
|
+
end
|
18
39
|
end
|
19
40
|
# cattr_accessor :options
|
20
41
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'nailgun'
|
1
2
|
module ActsAsFlyingSaucer
|
2
3
|
|
3
4
|
# Xhtml2Pdf
|
@@ -14,7 +15,7 @@ module ActsAsFlyingSaucer
|
|
14
15
|
class_path = "'.#{options[:classpath_separator]}#{java_dir}/jar/acts_as_flying_saucer.jar'"
|
15
16
|
|
16
17
|
if options[:nailgun]
|
17
|
-
command = "#{Nailgun::NgCommand::NGPATH} Xhtml2Pdf #{options[:input_file]} #{options[:output_file]}"
|
18
|
+
command = "#{Nailgun::NgCommand::NGPATH} --nailgun-server #{ActsAsFlyingSaucer::Config.options[:nailgun_host]} --nailgun-port #{ ActsAsFlyingSaucer::Config.options[:nailgun_port]} Xhtml2Pdf #{options[:input_file]} #{options[:output_file]}"
|
18
19
|
else
|
19
20
|
command = "#{options[:java_bin]} -Xmx512m -Djava.awt.headless=true -cp #{class_path} acts_as_flying_saucer.Xhtml2Pdf #{options[:input_file]} #{options[:output_file]}"
|
20
21
|
end
|
@@ -25,7 +26,7 @@ module ActsAsFlyingSaucer
|
|
25
26
|
java_dir = File.join(File.expand_path(File.dirname(__FILE__)), "java")
|
26
27
|
class_path = "'.#{options[:classpath_separator]}#{java_dir}/jar/acts_as_flying_saucer.jar'"
|
27
28
|
if options[:nailgun]
|
28
|
-
command = "#{Nailgun::NgCommand::NGPATH} encryptPdf #{options[:input_file]} #{options[:output_file]}"
|
29
|
+
command = "#{Nailgun::NgCommand::NGPATH} --nailgun-server #{ActsAsFlyingSaucer::Config.options[:nailgun_host]} --nailgun-port #{ ActsAsFlyingSaucer::Config.options[:nailgun_port]} encryptPdf #{options[:input_file]} #{options[:output_file]}"
|
29
30
|
else
|
30
31
|
command = "#{options[:java_bin]} -Xmx#{options[:max_memory_mb]}m -Djava.awt.headless=true -cp #{class_path} acts_as_flying_saucer.encryptPdf #{options[:output_file]} #{output_file_name} #{password}"
|
31
32
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'acts_as_flying_saucer/config'
|
2
2
|
require 'acts_as_flying_saucer/xhtml2pdf'
|
3
3
|
require 'acts_as_flying_saucer/acts_as_flying_saucer_controller'
|
4
|
+
require 'nailgun'
|
4
5
|
if defined?(Rails)
|
5
6
|
ActionController::Base.send(:include, ActsAsFlyingSaucer::Controller)
|
6
7
|
elsif defined?(Sinatra)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_flying_saucer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Amar Daxini
|
@@ -15,10 +15,23 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-25 00:00:00 +05:30
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: nailgun
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
22
35
|
description: XHTML to PDF using Flying Saucer java library
|
23
36
|
email:
|
24
37
|
- amardaxini@gmail.com
|