Class: Grandfather::Wkhtmltopdf
- Inherits:
-
Object
- Object
- Grandfather::Wkhtmltopdf
- Defined in:
- lib/grandfather/wkhtmltopdf.rb
Instance Method Summary collapse
- #bin ⇒ Object
- #command(filename) ⇒ Object
-
#initialize(parameters = nil) ⇒ Wkhtmltopdf
constructor
A new instance of Wkhtmltopdf.
- #output_pdf(html, filename) ⇒ Object
Constructor Details
#initialize(parameters = nil) ⇒ Wkhtmltopdf
Returns a new instance of Wkhtmltopdf.
4 5 6 |
# File 'lib/grandfather/wkhtmltopdf.rb', line 4 def initialize(parameters = nil) @parameters = parameters end |
Instance Method Details
#bin ⇒ Object
23 24 25 |
# File 'lib/grandfather/wkhtmltopdf.rb', line 23 def bin @bin ||= "\"#{(`which wkhtmltopdf`).chomp}\"" end |
#command(filename) ⇒ Object
19 20 21 |
# File 'lib/grandfather/wkhtmltopdf.rb', line 19 def command(filename) [bin, @parameters, '--quiet', '-', "\"#{filename}\""].compact end |
#output_pdf(html, filename) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/grandfather/wkhtmltopdf.rb', line 8 def output_pdf(html, filename) args = command(filename) invoke = args.join(' ') IO.popen(invoke, "wb+") do |pdf| pdf.puts(html) pdf.close_write pdf.gets(nil) end end |