diff --git a/lib/princely/pdf.rb b/lib/princely/pdf.rb index 76b7b2a..fc03b0a 100644 --- a/lib/princely/pdf.rb +++ b/lib/princely/pdf.rb @@ -1,3 +1,4 @@ +require 'open3' require 'timeout' module Princely @@ -69,9 +70,8 @@ def executable_options def pdf_from_string(string, output_file = '-') with_timeout do pdf = initialize_pdf_from_string(string, output_file, {:output_to_log_file => false}) - pdf.close_write result = pdf.gets(nil) - pdf.close_read + pdf.close result.force_encoding('BINARY') if RUBY_VERSION >= "1.9" result @@ -107,9 +107,10 @@ def initialize_pdf_from_string(string, output_file, options = {}) log_command path if options[:log_command] # Actually call the prince command, and pass the entire data stream back. - pdf = IO.popen(path, "w+") - pdf.puts string - pdf + stdin, stdout = Open3.popen3(path) + stdin.puts string + stdin.close + stdout end def log_command(path)