Sha256: e753c9a94435f84b7f9af33645b82a4fe7a90271b1e99a3935430a62d3db2e32
Contents?: true
Size: 603 Bytes
Versions: 1
Compression:
Stored size: 603 Bytes
Contents
# frozen_string_literal: true require 'modulation/gem' require 'tmpdir' require 'fileutils' export_default :H2P module H2P def self.tmp_path(ext) stamp = Time.now.to_f @counter ||= 0 File.join(Dir.tmpdir, "h2p-#{stamp}-#{@counter += 1}.#{ext}") end def self.convert(html) html_path = tmp_path(:html) pdf_path = tmp_path(:pdf) p [html_path, pdf_path] 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
h2p-0.1 | lib/h2p.rb |