Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add :delete_temporary_files flag #1068

Merged
merged 5 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
)
}
)

Expand Down
6 changes: 5 additions & 1 deletion lib/wicked_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down