Giter Site home page Giter Site logo

Comments (1)

neutrino avatar neutrino commented on May 3, 2024

Using PDFKit as a middleware allows you to render all pages as a pdf. But it can be done for a specific action by specifying the rendering format. For that you need to register mime type for version 0.3.3 and i think its fixed in the newer version. And here is a snippet.

format.pdf {
html_text = render_to_string(:layout => false, :action => "show.pdf.erb")
pdf_output = PDFKit.new(html_text, :print_media_type => true)
pdf_output.stylesheets << Rails.root + "public/stylesheets/print.css"
send_data(pdf_output.to_pdf, :filename => "filename.pdf", :type =>'application/pdf')
}

I have used show.pdf.erb as the view template which is similar to show.html.erb but without irrelevant elements and print_media_type is set to true to use different style-sheet and used Rails.root instead of RAILS_ROOT for rails 3.

hope it helps :)
Ranendra

from pdfkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.