Reputation: 6367
I am creating a PDF file using Wicked:
pdf = WickedPdf.new.pdf_from_string('<h1>Hello There!</h1>')
I assume that this creates a temporary file somewhere. How can I get the path to this temp file?
Upvotes: 1
Views: 2706
Reputation: 3677
Please refer to example of https://github.com/mileszs/wicked_pdf#super-advanced-usage.
The official example use File
pdf = render_to_string pdf: "some_file_name", template: "templates/pdf", encoding: "UTF-8"
# then save to a file
save_path = Rails.root.join('pdfs','filename.pdf')
File.open(save_path, 'wb') do |file|
file << pdf
end
You may use tempfile
to do it as
pdf_string = WickedPdf.new.pdf_from_string(...)
overlay = Tempfile.new('overlay')
overlay.binmode
overlay.write(pdf_string)
overlay.close
overlay.path # to get path
Upvotes: 1
Reputation: 246
you can do this when you are creating the pdf only u can pass in the option of your desired temp path
pdf = WickedPdf.new.pdf_from_string('<h1>Hello There!</h1>', {temp_path: "your path here")
Upvotes: 1
Reputation: 5763
Checking the source of WickedPDF it has a TempFile
The temporary file should be created in the temporary directory as defined in options
, or in Dir.tmpdir
.
Upvotes: 0