lib/wicked_pdf/document.rb in adzap-wicked_pdf-2.0.0.beta3 vs lib/wicked_pdf/document.rb in adzap-wicked_pdf-2.0.0.beta4
- old
+ new
@@ -10,37 +10,39 @@
def pdf_from_string(string, options = {})
options = options.dup
options.merge!(WickedPdf.config) { |_key, option, _config| option }
string_file = WickedPdf::Tempfile.new('wicked_pdf.html', options[:temp_path])
- string_file.binmode
- string_file.write(string)
- string_file.close
+ string_file.write_in_chunks(string)
pdf_from_html_file(string_file.path, options)
+ rescue Errno::EINVAL => e
+ Rails.logger.error '[wicked_pdf] The HTML file is too large! Try reducing the size or using the return_file option instead.'
+ raise e
ensure
string_file.close! if string_file
end
def pdf_from_url(url, options = {})
# merge in global config options
options.merge!(WickedPdf.config) { |_key, option, _config| option }
generated_pdf_file = WickedPdf::Tempfile.new('wicked_pdf_generated_file.pdf', options[:temp_path])
+ return_file = options.delete(:return_file)
- result = @command.execute(options, url, generated_pdf_file.path.to_s)
+ err = @command.execute(options, url, generated_pdf_file.path.to_s)
- if options[:return_file]
- return_file = options.delete(:return_file)
+ if return_file
return generated_pdf_file
end
- generated_pdf_file.rewind
- generated_pdf_file.binmode
- pdf = generated_pdf_file.read
+ pdf = generated_pdf_file.read_in_chunks
- raise "PDF could not be generated!\n Command Error: #{result}" if pdf && pdf.rstrip.empty?
+ raise "PDF could not be generated!\n Command Error: #{err}" if pdf && pdf.rstrip.empty?
pdf
+ rescue Errno::EINVAL => e
+ Rails.logger.error '[wicked_pdf] The PDF file is too large! Try reducing the size or using the return_file option instead.'
+ raise e
ensure
generated_pdf_file.close! if generated_pdf_file && !return_file
end
end
end