class Dauphin::Pdf

Attributes

executable[RW]
log_file[RW]
logger[RW]
stylesheets[RW]

Public Class Methods

new(opt={}) click to toggle source
# File lib/dauphin/pdf.rb, line 5
def initialize(opt={})
  options = {
      :path => nil,
      :executable => Dauphin.runtime,
      :log_file => nil,
      :logger => nil
  }.merge(opt)

  @executable = options[:path] ? Dauphin::Runtime.new(options[:path]) : options[:executable]
  @stylesheets = ''
  @log_file = options[:log_file]
  @logger = options[:logger]
end

Public Instance Methods

add_style_sheet(*sheets) click to toggle source
# File lib/dauphin/pdf.rb, line 27
def add_style_sheet(*sheets)
  @stylesheets << sheets.map { |sheet| " -s #{sheet} " }.join(' ')
end
exe() click to toggle source
# File lib/dauphin/pdf.rb, line 31
def exe
  @executable.join(executable_options)
  puts "@executable: #{@executable.inspect}"
  @executable.join(executable_options)
end
executable_options() click to toggle source
# File lib/dauphin/pdf.rb, line 37
def executable_options
  options = []
  options << "--input=html"
  options << "--log=#{log_file}"
  options << @stylesheets
  options
end
mkpdf_file(string, output_file) click to toggle source
# File lib/dauphin/pdf.rb, line 56
def mkpdf_file(string, output_file)
  pdf = create_pdf string, output_file
  pdf.close
end
mkpdf_stream(string, output_file = '-') click to toggle source
# File lib/dauphin/pdf.rb, line 45
def mkpdf_stream(string, output_file = '-')
  pdf = create_pdf string, output_file, {:output_to_log_file => false}
  pdf.close_write

  result = pdf.gets
  pdf.close_read

  result.force_encoding(Encoding::BINARY) if RUBY_VERSION >= '1.9'
  result
end

Protected Instance Methods

create_pdf(string, output_file, opt={}) click to toggle source
# File lib/dauphin/pdf.rb, line 62
def create_pdf(string, output_file, opt={})
  options = {
      :log_command => true,
      :output_log => true
  }.merge(opt)

  path = exe

  path << " --silent - -o #{output_file}"
  path << " >> '#{log_file}' 2>> '#{log_file}'" if options[:output_to_log_file]
  puts "Path: #{path.inspect}"

  log path if options[:log_command]

  pdf = IO.popen(path, 'w+')
  pdf.puts string
  pdf
end
log(path) click to toggle source
# File lib/dauphin/pdf.rb, line 81
def log(path)
  logger.info "\n\nPRINCE PDF:"
  logger.info path
  logger.info ''
end