lib/wicked_pdf.rb in wicked_pdf-0.8.0 vs lib/wicked_pdf.rb in wicked_pdf-0.9.0
- old
+ new
@@ -27,20 +27,23 @@
raise "Bad #{EXE_NAME}'s path" unless File.exists?(@exe_path)
raise "#{EXE_NAME} is not executable" unless File.executable?(@exe_path)
end
def pdf_from_string(string, options={})
- command = "\"#{@exe_path}\" #{'-q ' unless on_windows?}#{parse_options(options)} - - " # -q for no errors on stdout
+ string_file = WickedPdfTempfile.new("wicked_pdf.html")
+ string_file.write(string)
+ string_file.close
+
+ generated_pdf_file = WickedPdfTempfile.new("wicked_pdf_generated_file.pdf")
+ command = "\"#{@exe_path}\" #{'-q ' unless on_windows?}#{parse_options(options)} \"file://#{string_file.path}\" \"#{generated_pdf_file.path}\" " # -q for no errors on stdout
print_command(command) if in_development_mode?
- pdf, err = Open3.popen3(command) do |stdin, stdout, stderr|
- stdin.binmode
- stdout.binmode
- stderr.binmode
- stdin.write(string)
- stdin.close
- [stdout.read, stderr.read]
+ err = Open3.popen3(command) do |stdin, stdout, stderr|
+ stderr.read
end
+ generated_pdf_file.rewind
+ generated_pdf_file.binmode
+ pdf = generated_pdf_file.read
raise "PDF could not be generated!" if pdf and pdf.rstrip.length == 0
pdf
rescue Exception => e
raise "Failed to execute:\n#{command}\nError: #{e}"
end
@@ -116,10 +119,10 @@
@hf_tempfiles.push( tf=WickedPdfTempfile.new("wicked_#{hf}_pdf.html") )
tf.write options[hf][:content]
tf.flush
options[hf].delete(:content)
options[hf][:html] = {}
- options[hf][:html][:url] = "file://#{tf.path}"
+ options[hf][:html][:url] = "file:///#{tf.path}"
end
unless opt_hf[:html].blank?
r += make_option("#{hf.to_s}-html", opt_hf[:html][:url]) unless opt_hf[:html][:url].blank?
end
end