module H2P

Constants

VERSION

Public Class Methods

convert(html) click to toggle source
# File lib/h2p.rb, line 16
def self.convert(html)
  html_path = tmp_path(:html)
  pdf_path = tmp_path(:pdf)
  File.open(html_path, 'w+') { |f| f << html }
  system('wkhtmltopdf', '-q', html_path, pdf_path)
  IO.read(pdf_path)
ensure
  FileUtils.rm(html_path) rescue nil
  FileUtils.rm(pdf_path) rescue nil
end
tmp_path(ext) click to toggle source
# File lib/h2p.rb, line 10
def self.tmp_path(ext)
  stamp = Time.now.to_f
  @counter ||= 0
  File.join(Dir.tmpdir, "h2p-#{stamp}-#{@counter += 1}.#{ext}")
end