पर सिस्टम सिस्टम जेनरेटेड पीडीएफ को हल करें, नीचे संपादित करें देखें।एस 3
मेरी 3.1 रेल में मैं इस तरह एक PDF पैदा कर रहा हूँ एप्लिकेशन:
def show
@contributor = Contributor.find(params[:id])
respond_to do |format|
format.pdf {
html = render_to_string(:action => "show.html.erb")
kit = PDFKit.new(html)
kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css"
thepdf = send_data kit.to_pdf, :filename => "blah.pdf", :type => 'application/pdf'
redirect_to :action => save_to_s3
}
end
तो मैं दुकान है कि पेपरक्लिप साथ अपलोड करके S3 पर पीडीएफ उत्पन्न करने के लिए कोशिश कर रहा हूँ:
def save_to_s3
html = render_to_string(:action => "show.html.erb")
kit = PDFKit.new(html)
kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css"
roy = Royarchive.new(:client_id => @contributor.client_id)
f = File.open("blah.pdf", 'w+')
f.write kit.to_pdf
roy.pdf = f
roy.save!
end
लेकिन यह मुझे "\x9C" from ASCII-8BIT to UTF-8
मैं जेनरेट करने के लिए पेपरक्लिप का उपयोग कैसे कर सकता हूं एसडी के लिए पीडीएफ? मैं हेरोकू का उपयोग कर रहा हूं इसलिए मैं सर्वर पर एक अस्थायी फ़ाइल सहेज नहीं सकता हूं और फिर इसे अपलोड कर सकता हूं।
//// हल
ओह, मेरा बुरा है, तो आप कर सकते हैं store files for the duration of the session at root।
तो यह काम करता है:
def show
@contributors = Contributor.where(:client_id => current_user.client_id).paginate(:page => params[:page])
@contributor = Contributor.where(:client_id => current_user.client_id).find(params[:id])
respond_to do |format|
format.html
format.pdf {
html = render_to_string(:action => "show.html.erb")
kit = PDFKit.new(html)
kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css"
send_data kit.to_pdf, :filename => "name.pdf", :type => 'application/pdf'
@thepdf = kit.to_file("#{Rails.root}/tmp/name.pdf")
roy = Royarchive.new(:client_id => @contributor.client_id)
roy.pdf = @thepdf
roy.save!
}
end
end
मैं लूंगा - आप और अधिक प्रतिनिधि से मैं भी इसे लिखने के 8 घंटे के भीतर जवाब देने के लिए, अकेले स्वीकार करते हैं, अपनी खुद की क्यू है की जरूरत है। – snowangel