Skip to content

Instantly share code, notes, and snippets.

@zachy
Created February 14, 2012 11:42
Show Gist options
  • Save zachy/1826167 to your computer and use it in GitHub Desktop.
Save zachy/1826167 to your computer and use it in GitHub Desktop.
require 'mini_magick'
class InvalidInputFileError < Exception; end
class Converter
def initialize(input, output = nil)
raise InvalidInputFileError unless html_file?(input)
@input = input
if @output
@ouput = output
else
@output = output_filename_from @input
end
end
def convert_file
system(Dir.pwd+"/wkhtmltopdf-amd64",@input, "temporary.pdf")
image = MiniMagick::Image.open("temporary.pdf")
image.format "png"
image.write Dir.pwd+"/"+@output + ".png"
File.delete("temporary.pdf")
end
protected
def html_file?(filename)
filename.match(/\.html$/)
end
def output_filename_from(filename)
File.basename(filename, File.extname(filename))
end
end
conv = Converter.new("faktura.html")
conv.convert_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment