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 6994511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:54:07+00:00 2026-05-27T19:54:07+00:00

I am creating a pdf file in the latest version of the Prawn library

  • 0

I am creating a pdf file in the latest version of the Prawn library (v1.0.1rc) in Rails (3.1.1) and when I run my code it generates the PDF into the root of the application.

I don’t want this. I want it to render the output into user’s browser window, without saving it locally to the server.

Please tell me how I can achieve this. Here are my files:

views/foo/show.pdf.erb:

<%=

require 'prawn'

pdf = Prawn::Document.new(:page_size => 'LETTER', :page_layout => :landscape, :margin => 50, :top_margin => 20, :bottom_margin => 50)

.....

render_file("foo.pdf")

%>

controllers/foo_controller:

class AuditsController < ApplicationController
  before_filter :authenticate_user!
  layout 'application'
  can_edit_on_the_spot
  respond_to :html, :xml, :js, :pdf

  def index
    @audits = Audit.all
    respond_with @audits
  end

  def show
    @audit = Audit.find(params[:id])
    respond_with @audit do |format|
      format.pdf { render :layour => false }
    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-27T19:54:08+00:00Added an answer on May 27, 2026 at 7:54 pm

    Gemfile

    gem 'prawn'
    

    /config/initializers/mime_types.rb

    Mime::Type.register "application/pdf", :pdf
    

    AuditsController

    def show
      @audit = Audit.find(params[:id])
      respond_to do |format|
        format.html
        format.pdf do
          pdf = Prawn::Document.new
          pdf.text "This is an audit."
          # Use whatever prawn methods you need on the pdf object to generate the PDF file right here.
    
          send_data pdf.render, type: "application/pdf", disposition: "inline"
          # send_data renders the pdf on the client side rather than saving it on the server filesystem.
          # Inline disposition renders it in the browser rather than making it a file download.
        end
      end
    end
    

    I used to use the prawnto gem before Rails 3.1, but it doesn’t work without a bit of hacking anymore. This is a much cleaner way to instantiate and display the PDF object in 3.1 by accessing Prawn directly.

    I got this technique straight from one of Ryan Bates’ Railscasts. Been using it ever since. You can view that specific episode here. He goes into much more detail about subclassing Prawn and moving the PDF generating code out of the controller. Also shows a lot of useful Prawn methods to get you started. Highly recommended.

    A lot of the episodes are free, but that revised Prawn episode is one of those that are only available with a paid subscription. At $9/month though, a subscription quickly pays for itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating generator of pdf documents in Ruby on Rails with Prawn gem and
I am using PHP code for creating .pdf file and I am filing forms
I tried creating a pdf file into my device out of a file in
I am creating a file pdf in iphone application and it is saved in
Language : ASP.NET/VB.NET I am creating pdf file using itextsharp library. On my development
I am creating a PDF File in my application, and then I print it
In my application, I am taking selected user data and creating a PDF file.
I'm creating a pdf file using BIRT reporting library. Later I need to digitally
I need a PDF library for manipulating a PDF documents, (creating PDF, image convertinng
I'm creating a PDF with iText version 2.1.0. I have to create a detail

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.