diff --git a/README.md b/README.md index b2e794db..bed73f9b 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,8 @@ class ThingsController < ApplicationController disable_toc_links: true, disable_back_links:true, xsl_style_sheet: 'file.xsl'}, # optional XSLT stylesheet to use for styling table of contents - progress: proc { |output| puts output } # proc called when console output changes + progress: proc { |output| puts output }, # proc called when console output changes + delete_temporary_files: true # explicitly delete temporary files, default false end end end @@ -294,14 +295,14 @@ pdf = WickedPdf.new.pdf_from_html_file('/your/absolute/path/here') # create a pdf from a URL pdf = WickedPdf.new.pdf_from_url('https://github.com/mileszs/wicked_pdf') -# create a pdf from string using templates, layouts and content option for header or footer +# create a pdf from string using templates, layouts, and content option for header or footer pdf = WickedPdf.new.pdf_from_string( render_to_string('templates/pdf', layout: 'pdfs/layout_pdf.html'), footer: { content: render_to_string( - 'templates/footer', - layout: 'pdfs/layout_pdf.html' - ) + 'templates/footer', + layout: 'pdfs/layout_pdf.html' + ) } ) diff --git a/lib/wicked_pdf.rb b/lib/wicked_pdf.rb index fc7a3811..15503275 100644 --- a/lib/wicked_pdf.rb +++ b/lib/wicked_pdf.rb @@ -43,7 +43,11 @@ def pdf_from_string(string, options = {}) string_file.write_in_chunks(string) pdf_from_html_file(string_file.path, options) ensure - string_file.close if string_file + if options[:delete_temporary_files] && string_file + string_file.close! + elsif string_file + string_file.close + end end def pdf_from_url(url, options = {}) # rubocop:disable Metrics/CyclomaticComplexity