Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6388489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:17:05+00:00 2026-05-25T03:17:05+00:00

Solved, see edit at bottom. In my 3.1 rails app I’m generating a pdf

  • 0

Solved, see edit at bottom.


In my 3.1 rails app I’m generating a pdf like this:

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

Then I’m trying to store that generated PDF on S3 by uploading with Paperclip:

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 

But that’s giving me "\x9C" from ASCII-8BIT to UTF-8

How can I use Paperclip to upload this generated pdf to S3? I’m using Heroku so I can’t save a temp file on the server then upload it.

////solved

Oh, my bad, you can store files for the duration of the session at root.

So this works:

   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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:17:06+00:00Added an answer on May 25, 2026 at 3:17 am

    Oh, my bad, you can store files for the duration of the session at root.

    So this works:

    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" 
      thepdf = kit.to_file("#{Rails.root}/tmp/name.pdf")
    
         roy = Royarchive.new(:client_id => @contributor.client_id) 
         roy.pdf = thepdf
         roy.save!
         redirect_to :action => index
    end 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: I have solved this by myself. See my answer below I have set
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
This problem has been solved thanks to your suggestions. See the bottom for details.
This is something that I solved using reflection, but would like to see how
[EDIT: Problem solved. Please see my answer below.] In my app I call the
edit: this is now solved, see my answer below The situation: User clicks on
(Problem solved now, see answers below) Hello, in my app I am trying to
EDIT 3: Solved. See below. EDIT 2: I think Chadwick's on the right track
SOLVED see Edit 2 Hello, I've been writing a Perl program to handle automatic
EDIT: Problem solved. This was (yet another) situation where the problem wasn't really where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.