Module: OVNI

Defined in:
lib/ovni.rb,
lib/ovni/config.rb,
lib/ovni/version.rb

Defined Under Namespace

Classes: Config

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.html_to_pdf(html, pdf_file, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ovni.rb', line 9

def self.html_to_pdf(html, pdf_file, options = {})
  options = Config.options.merge(options)

  class_path = [File.join(File.expand_path(File.dirname(__FILE__)), "ovni/Xhtml2Pdf"), options[:class_path]].join(options[:classpath_separator])

  Tempfile.open("ovni") do |file|
    file << html
    file.flush

    command = "#{options[:java_bin]} -Xmx#{options[:max_memory_mb]}m -Djava.awt.headless=true -cp #{class_path} Xhtml2Pdf #{file.path} #{File.expand_path(pdf_file)}"

    system(command)

    return $? == 0
  end
end