Skip to content

Instantly share code, notes, and snippets.

@cs3b
Created March 31, 2010 08:35
Show Gist options
  • Save cs3b/350094 to your computer and use it in GitHub Desktop.
Save cs3b/350094 to your computer and use it in GitHub Desktop.
# model invoice
def store_pdf
# this should be constant
temp_invoice_file_path = Rails.root.join("html2pdf/invoice.html")
File.open(temp_invoice_file_path, 'w') {|f| f.write(markup) }
if ENV['OS'] and ENV['OS'].include?("Windows")
`xhtml2pdf html2pdf/invoice.html #{filepath}`
else
`python pisa.py #{temp_invoice_file_path} #{filepath}`
end
# File.delete(temp_invoice_file_path)
filepath
end
def filepath(extension='pdf')
Rails.root.join "html2pdf/invoice_cache/#{filename}.#{extension}"
end
# controller mail
def create
params[:mailing][:filepaths] = [[ @invoice.store_pdf, @invoice.filename+".pdf"]]
if Mailing.create(params[:mailing])
@invoice.update_attribute(:emailed_at, Time.now)
end
respond_to do |format|
format.html {redirect_to invoicing_invoice_path(@invoice)}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment