Class: Wisepdf::Writer
- Inherits:
-
Object
- Object
- Wisepdf::Writer
- Defined in:
- lib/wisepdf/writer.rb
Instance Method Summary collapse
-
#initialize(path = nil) ⇒ Writer
constructor
A new instance of Writer.
- #to_pdf(string, options = {}) ⇒ Object
- #wkhtmltopdf ⇒ Object
- #wkhtmltopdf=(value) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ Writer
Returns a new instance of Writer.
6 7 8 |
# File 'lib/wisepdf/writer.rb', line 6 def initialize(path=nil) self.wkhtmltopdf = path unless path.nil? end |
Instance Method Details
#to_pdf(string, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wisepdf/writer.rb', line 10 def to_pdf(string, ={}) command = "\"#{self.wkhtmltopdf}\" #{()} #{'-q ' unless Wisepdf::Configuration.windows?}- - " # -q for no errors on stdout print_command(command) if Wisepdf::Configuration.development? result = IO.popen(command, "wb+") do |pdf| pdf.puts(string) pdf.close_write pdf.gets(nil) end raise Wisepdf::WriteError if result && result.rstrip.length == 0 return result end |
#wkhtmltopdf ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/wisepdf/writer.rb', line 26 def wkhtmltopdf return @wkhtmltopdf if @wkhtmltopdf.present? @wkhtmltopdf = Wisepdf::Configuration.wkhtmltopdf raise Wisepdf::NoExecutableError.new(@wkhtmltopdf) if @wkhtmltopdf.nil? || !File.exists?(@wkhtmltopdf) return @wkhtmltopdf end |
#wkhtmltopdf=(value) ⇒ Object
35 36 37 38 |
# File 'lib/wisepdf/writer.rb', line 35 def wkhtmltopdf=(value) @wkhtmltopdf = value raise Wisepdf::NoExecutableError.new(@wkhtmltopdf) if @wkhtmltopdf.nil? || !File.exists?(@wkhtmltopdf) end |