#Rails pdfkit pdf
Testing the possibility that the pdf is generating before the ajax call, I tried making a config/initializers/pdfkit.rb with this in it: nfigure do |config|Ĭonfig. I know that wkhtmltopdf can handle d3 because I've made many PDFs from d3-heavy sites before using it from the command line.Īny help or advice that anyone can lend is greatly appreciated :) thank you NOTE: the generated PDF picks up the pdfkit.css style sheet just fine When I change the color of the h2 tags in that stylesheet, the generated PDF reflects those changes. I have tried changing the render_to_string gives me an error. "reporting/" which gave me the exact same result.
#Rails pdfkit how to
I have tried changing the render_to_string to PDFKit with Rails creates malformatted text using rendertostring Using Ruby CSV creates Rails Records where string fields aren't queryable how to render a partial using linkto with rails 4.2. Viewed 4k times 0 I have managed installing PDFKit and wkhtmltopdf on. On the website, clicking Download PDF still gives me a near-empty Ask Question Asked 4 years, 2 months ago.
#Rails pdfkit code
I have tried moving all the code (all the d3 code, and all the jsonĭata) into the view and while it still works fine That is my problem.ĭoes anyone know why this is? Or what I can do? Here are a few things I've tried: The PDF has a couple of H2 tags that say "Charts by Category" and "Charts by Subcategory" and thats it, so it is not picking up the d3 whatsoever. The b圜ategory() and bySubcategory() functions are defined in b圜ategory.js and bySubcategory.js respectively and are 100% d3 code which selects the #b圜ategory and #bySubcategory divs and appends a bunch of SVG bar charts using the data from when I click my Download PDF button, wkhtmltopdf fires up, generates the pdf, my browser downloads it, and the PDF is just the bare-bones page with no d3 charts!. (from reporting/) =link_to 'Download PDF', by Category Register PDF as a mime-type in environment.rb: Mime::Type.register 'application/pdf', :pdf. Disable the PDFKit middleware so that your controller handles the generation of the PDF. The d3 code then selects those divs and makes a bunch of beautiful charts inside them with this code: How to cache the PDF using Rails page caching and PDFKit. The view, (reporting/) is a relatively empty view with just a couple H2 tags and empty divs. (If we were doing this with a Rails 2 app this would go in the environment configuration file.) We’ll modify the file so that the application uses the PDFKit middleware. Kit = "test.pdf", :type=>"application/pdf", :disposition=>"attachment" In a Rails 3 application this is done in the /config/application.rb file. Here is my controller method in the Reporting controller: def = render_to_string("reporting/charts", :layout => false) I am using D3 to create a bunch of fancy charts and I want the user to be able to download a PDF of it. I have a javascript-heavy view-in particular D3.js. I am using PDFKit as a way for users to Download a PDF of the page they are looking at, no middleware involved whatsoever, no viewing PDF within the browser. NOTE: I am NOT using the PDFKit Middleware.