module Mn2pdf

Constants

MN2PDF_JAR_PATH
VERSION

Public Class Methods

convert(url_path, output_path, xsl_stylesheet, options = "") click to toggle source
# File lib/mn2pdf.rb, line 31
def self.convert(url_path, output_path, xsl_stylesheet, options = "")
  return if url_path.nil? || output_path.nil? || xsl_stylesheet.nil?

  cmd = ["java", "-Xss5m", "-Xmx2048m", *jvm_options,
         "-jar", MN2PDF_JAR_PATH, "--xml-file", url_path,
         "--xsl-file", xsl_stylesheet, "--pdf-file", output_path, options].join(" ")

  puts cmd
  stdout_str, error_str, status = Open3.capture3(cmd)

  raise prepare_error_msg(stdout_str, error_str) unless status.success?
end
help() click to toggle source
# File lib/mn2pdf.rb, line 18
def self.help
  cmd = ["java", *jvm_options, "-jar", MN2PDF_JAR_PATH].join(" ")
  # help message goes to STDERR (from mn2pdf v1.36)
  blank_message, help_message, = Open3.capture3(cmd)
  help_message
end
jvm_options() click to toggle source
# File lib/mn2pdf.rb, line 8
def self.jvm_options
  options = []

  if RbConfig::CONFIG["host_os"].match?(/darwin|mac os/)
    options << "-Dapple.awt.UIElement=true"
  end

  options
end
prepare_error_msg(stdout_str, error_str) click to toggle source
# File lib/mn2pdf.rb, line 44
def self.prepare_error_msg(stdout_str, error_str)
  # Strip default mn2pdf message
  stdout_str = stdout_str.gsub("Preparing...", "").strip
  ["[mn2pdf] Fatal:", stdout_str, error_str].join(" ").strip
end
version() click to toggle source
# File lib/mn2pdf.rb, line 25
def self.version
  cmd = ["java", *jvm_options, "-jar", MN2PDF_JAR_PATH, "-v"].join(" ")
  message, = Open3.capture3(cmd)
  message.strip
end